# @abapify/adt-plugin 中文文档

规范地址：https://npmcn.com/package/%40abapify/adt-plugin/

版本：0\.4\.34
npm 元数据更新时间：2026-11-02T23:19:37.959Z
中文译文更新时间：2026-11-06T08:50:50.875Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40abapify/adt-plugin
原文对照：https://npmcn.com/package/%40abapify/adt-plugin/?lang=original
项目主页：https://github.com/abapify/adt-cli/tree/main/packages/adt-plugin#readme
源码仓库：https://github.com/abapify/adt-cli

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：43.5 kB，6 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：1 个
- 首次发布：2026-04-20T21:11:21.487Z
- 最新版本发布：2026-11-02T23:19:37.596Z
- 近 30 天下载量：3714（2026-10-05 至 2026-11-03，npm 官方下载统计）
- 已发布版本数：31（近 12 个月 31 个）

## 中文简介

ADT 插件接口和机床

## 安装

```sh
npm install @abapify/adt-plugin
```

也可以使用：`pnpm add @abapify/adt-plugin`、`yarn add @abapify/adt-plugin`、`bun add @abapify/adt-plugin`

## README

# @abapify/adt-plugin (中文(简体) )

[![version](https://img.shields.io/github/package-json/v/abapify/adt-cli?filename=packages/adt-plugin/package.json)](https://github.com/abapify/adt-cli/pkgs/npm/%40abapify%2Fadt-plugin)

ADT格式序列化的核心插件接口.

## 概览

此软件包定义 **插件合同** 用于将 ADK 对象序列化到各种格式(abapGit等)。 插件执行此接口以提供特定格式的序列化.

**关键原则:** 插件只处理序列化格式。 它们接收ADK对象并生成文件 - 没有ADT客户端逻辑.

## 安装

```bash
bun add @abapify/adt-plugin
```

## 使用量

### 创建插件

```typescript
import { createPlugin, type AdtPlugin } from '@abapify/adt-plugin';

export const myPlugin = createPlugin({
  name: 'myFormat',
  version: '1.0.0',
  description: 'My custom format plugin',

  // Registry service - what object types are supported
  registry: {
    isSupported: (type) => ['CLAS', 'INTF'].includes(type),
    getSupportedTypes: () => ['CLAS', 'INTF'],
  },

  // Format service - import/export operations
  format: {
    // Import: ADK object → file system
    import: async (object, targetPath, context) => {
      // Serialize object to files
      return {
        success: true,
        filesCreated: ['myclass.clas.xml'],
      };
    },

    // Export: file system → ADK object (optional)
    export: async (sourcePath, type, name) => {
      // Deserialize files to ADK object
      return {
        success: true,
        object: myAdkObject,
      };
    },
  },

  // Lifecycle hooks (optional)
  hooks: {
    afterImport: async (targetPath) => {
      // Generate metadata files, etc.
    },
  },
});
```

### 使用插件

```typescript
import { abapGitPlugin } from '@abapify/adt-plugin-abapgit';

// Check if type is supported
if (abapGitPlugin.registry.isSupported('CLAS')) {
  // Import object to file system
  const result = await abapGitPlugin.format.import(myClassObject, './output', {
    packagePath: ['ZROOT', 'ZSUB'],
  });

  if (result.success) {
    console.log('Files created:', result.filesCreated);
  }
}

// Get all supported types
const types = abapGitPlugin.registry.getSupportedTypes();
// → ['CLAS', 'INTF', 'DOMA', 'DEVC', 'DTEL']
```

## API 密码

### 纯树物质化

流体式消费者需要先计算寄存器的变化,然后才能触摸 文件系统。 A 类 `FormatPlugin` 暴露可选的纯物质化 能力。 获取一个通过 `requireFormatPlugin` (无) `createPlugin`,哪个 返回一个 `AdtPlugin`:

```typescript
import { requireFormatPlugin } from '@abapify/adt-plugin';

const formatPlugin = requireFormatPlugin('abapGit');
const result = await formatPlugin.materialize?.({
  object: adkObject,
  objectType: 'CLAS',
  packagePath: ['ZROOT', 'ZROOT_FEATURE'],
  sources: {
    main: historicalMainSource,
    definitions: historicalLocalDefinitions,
  },
  formatOptions: { folderLogic: 'prefix' },
});
```

何时 `sources` 它具有权威性。 处理器只发出这些 组件,不得通过 ADK 对象读取可变源。 结果 包含确定寄存器与文件 `source` 或者说 `metadata` 角色; 呼叫者拥有验证和文件系统调节.

### `createPlugin(definition)`

Factory 函数创建已验证的插件实例 .

### `AdtPlugin` 接口

```typescript
interface AdtPlugin {
  readonly name: string;
  readonly version: string;
  readonly description: string;

  readonly registry: {
    isSupported(type: AbapObjectType): boolean;
    getSupportedTypes(): AbapObjectType[];
  };

  readonly format: {
    import(object, targetPath, context): Promise<ImportResult>;
    export?(sourcePath, type, name): Promise<ExportResult>;
  };

  readonly hooks?: {
    afterImport?(targetPath: string): Promise<void>;
    beforeExport?(sourcePath: string): Promise<void>;
  };
}
```

## 术语

-   **导入** (到 Git): ADK 对象 ~ 序列文件 (SAP ~ 文件系统)
-   **导出** (取自 Git ): 序列文件 → ADK 对象( 文件系统 → SAP)

## 常见问题

### @abapify/adt-plugin 是什么？

ADT 插件接口和机床

### 如何安装 @abapify/adt-plugin？

在项目目录运行 npm install @abapify/adt-plugin，或使用 pnpm add / yarn add / bun add。

### @abapify/adt-plugin 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @abapify/adt-plugin 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @abapify/adt-plugin 可以商用吗？

@abapify/adt-plugin 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @abapify/adt-plugin 的下载量有多少？

根据 npm 官方下载统计，@abapify/adt-plugin 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,714 次，日均约 124 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @abapify/adt-plugin 还在维护吗？

最新版本 0\.4\.34 发布于 2026/11/03（4 天前）；至今共发布 31 个版本，其中过去 12 个月发布了 31 个；首次发布于 2026/04/21。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

