从 Nx 迁移到 Turbo

Activepieces monorepo 已全面迁移到 Turbo。本指南仅供**历史参考**,以及为仍使用基于 Nx 的构建系统的旧版 Fork 用户保留。

如果你有一个包含使用旧版基于 Nx 的构建系统构建的自定义 Piece 的现有 Fork,你需要将其迁移到新的基于 Turbo 的构建系统。本指南说明了变更内容并提供了迁移脚本。

变更内容

Activepieces monorepo 用 Turbo 替换了 Nx 作为其构建协调器。对于 Piece 来说,这意味着:

旧版(Nx)新版(Turbo)
构建配置每个 Piece 的 project.jsonpackage.json 脚本
构建命令nx build pieces-{name}turbo run build --filter=@activepieces/piece-{name}
输出目录dist/out-tsc(共享)./dist(每个 Piece 本地)
任务运行器Nx executor(@nx/js:tsc直接 tsc -p tsconfig.lib.json && cp package.json dist/
依赖管理由 Nx 图推断工作区协议(workspace:*)在 package.json

每个 Piece 受影响的文件

  • project.json — 删除(不再需要)
  • package.json — 添加 buildlint 脚本,添加 maintypes 字段,添加工作区依赖
  • tsconfig.lib.json — 更新 outDir,添加 rootDirbaseUrlpaths

自动迁移

运行迁移脚本以一次性更新所有自定义 Piece:

npx ts-node tools/scripts/migrate-custom-piece-to-turbo.ts

此脚本扫描 packages/pieces/custom/ 并应用所有必要的更改。

迁移特定的 Piece

你也可以传递路径来迁移单个 Piece:

npx ts-node tools/scripts/migrate-custom-piece-to-turbo.ts packages/pieces/custom/my-piece

脚本功能

对于每个 Piece,脚本会:

  1. 更新 package.json — 添加 buildlint 脚本,设置 maintypes 入口点,确保 @activepieces/pieces-framework@activepieces/sharedtslib 列为依赖
  2. 更新 tsconfig.lib.json — 设置 outDir./dist,添加 rootDirbaseUrlpathsdeclaration 设置
  3. 如果缺失则创建 tsconfig.json — 继承根 tsconfig.base.json
  4. 删除 project.json — 移除 Nx 配置

验证迁移

迁移后,构建你的 Piece 以验证一切正常:

npx turbo run build --filter=@activepieces/piece-your-piece --force

或者使用 CLI:

npm run build-piece your-piece

构建输出应出现在 packages/pieces/custom/your-piece/dist/ 中。