升级

升级到 2.0

¥Upgrading to 2.0

更新 turbo.json

¥Update turbo.json

运行以下命令开始从 1.x 升级到 2.0:

¥Get started upgrading from 1.x to 2.0 by running:

Terminal
pnpm dlx @turbo/codemod migrate

这将更新你的 turbo.json,使其涵盖从 1.x 到 2.0 的许多重大更改。

¥This will update your turbo.json(s) for many of the breaking changes from 1.x to 2.0.

此外,工作区中任何没有 name 字段的 package.json 都会添加一个 name 字段。

¥Additionally, a name field will be added to any package.json in the Workspace that doesn't have one.

Good to know: 

你也可以单独手动运行每个 codemod。访问 codemods 页面 了解更多信息。

¥You may also manually run each codemod individually. Visit the codemods page for more information.

packageManager 字段添加到根 package.json

¥Add a packageManager field to root package.json

packageManager 字段 是 Node.js 生态系统中的一个约定,它定义了预期在工作区中使用的包管理器。

¥The packageManager field is a convention from the Node.js ecosystem that defines which package manager is expected to be used in the Workspace.

Turborepo 2.0 要求你的工作区定义此字段,以提高代码库的稳定性和行为可预测性。如果你还没有锁文件,请将此字段添加到你的根 package.json 中:

¥Turborepo 2.0 requires that your Workspace define this field as a way to improve the stability and behavioral predictability of your codebase. If you do not have one already, add this field to your root package.json:

./package.json
{
+ "packageManager": "pnpm@9.2.0"
}

更新 eslint-config-turbo

¥Update eslint-config-turbo

eslint-config-turbo 帮助识别需要添加到 env 键以进行缓存的环境变量。如果你正在使用它,请确保将其更新以匹配你的主版本。

¥eslint-config-turbo helps identify environment variables that need to be added to the env key for caching. If you're using it, make sure you update it to match your major version.

更新 turbo run 命令

¥Update turbo run commands

Turborepo 2.0 改进了 turbo run 命令的行为和正确性。以下列出了变更摘要,这些变更可能会或可能不会对你的代码库产生影响:

¥Turborepo 2.0 includes behavioral and correctness improvements with behavior of turbo run commands. Listed below is the summary of changes, which may or may not have an affect on your codebase:

  • 环境变量的严格模式现已从松散模式 (PR) 改为默认模式

    ¥Strict Mode for environment variables is now the default, moving from Loose Mode (PR)

    • 如果你的任务中的脚本似乎缺少环境变量,你可以根据每个命令使用 --env-mode 选项 来选择退出此行为,以进行增量迁移。我们建议你在任务中更新 env,以考虑其所有环境变量,这样你就可以尽快删除 --env-mode 选项。

      ¥If it appears that the scripts in your tasks are missing environment variables, you can opt back out of this behavior using the --env-mode option on a per-command basis to incrementally migrate. We encourage you to update the env key in your task to account for all of its environment variables so you can drop the --env-mode option as soon as possible.

    • 如果你想将存储库的默认设置恢复为松散模式,你可以执行 使用 envMode 配置 操作。

      ¥If you'd like to set the default for the repository back to Loose Mode, you can do so using the envMode configuration.

  • 工作区根目录现在是所有包(PR)的隐式依赖

    ¥Workspace root directory is now an implicit dependency of all packages (PR)

    • 仓库的根目录中的代码应尽可能少,因为对根目录的更改会影响仓库中的所有任务。此外,如果你在工作区根目录中使用 内部软件包,更改这些依赖也会导致所有任务的缓存未命中。在这两种情况下,请考虑将代码移出根目录和 安装到包中 分支。

      ¥The repository should have as little code in the root as possible, since changes to the root can affect all tasks in your repository. Additionally, if you're using Internal Packages in the Workspace root, changes to those dependencies will also cause cache misses for all tasks. In both cases, consider moving the code out of the root and into a package.

  • 已删除 --ignore,支持 --filter,并在下方绘制正确性变更图(PR

    ¥--ignore removed in favor of --filter and graph correctness changes below (PR)

  • 删除了 --scope 标志(自 1.2 版起已弃用)(PR

    ¥Removed --scope flag (deprecated since 1.2) (PR)

  • 根目录 package.json 中的 engines 字段现在用于哈希计算 (PR)

    ¥engines field in root package.json is now used in hashing (PR)

  • --filter 不再推断包名的命名空间(PR

    ¥--filter no longer infers namespaces for package names (PR)

  • --filter 现在会在没有匹配的包名或目录时出错(PR

    ¥--filter now errors when no package names or directories are matched (PR)

  • --only 限制任务依赖,而不是包依赖(PR

    ¥--only restricts task dependencies instead of package dependencies (PR)