Skip to main content
Version: 10.x

pnpm -r, --recursive

别名:mmultirecursive<command> -r

🌐 Aliases: m, multi, recursive, <command> -r

与以下命令一起使用时,在工作区的每个项目中运行命令:

🌐 Runs a command in every project of a workspace, when used with the following commands:

  • install
  • list
  • outdated
  • publish
  • pack
  • rebuild
  • remove
  • unlink
  • update
  • why

在工作区的每个项目中运行命令,排除根项目,当与以下命令一起使用时:

🌐 Runs a command in every project of a workspace, excluding the root project, when used with the following commands:

  • exec
  • run
  • test
  • add

如果你希望在运行脚本时也包含根项目,请将 includeWorkspaceRoot 设置为 true

🌐 If you want the root project be included even when running scripts, set the includeWorkspaceRoot setting to true.

使用示例:

🌐 Usage example:

pnpm -r publish

选项

🌐 Options

  • 默认:
  • 类型:真,假,深

将本地可用的软件包链接到 monorepo 的工作区中的 node_modules,而不是从注册表重新下载它们。这模拟了类似于 yarn workspaces 的功能。

🌐 Link locally available packages in workspaces of a monorepo into node_modules instead of re-downloading them from the registry. This emulates functionality similar to yarn workspaces.

当设置为 deep 时,本地包也可以链接到子依赖。

🌐 When this is set to deep, local packages can also be linked to subdependencies.

请注意,建议使用 pnpm-workspace.yaml 来设置此项,以便在所有环境中强制保持相同的行为。此选项的存在仅是为了在必要时允许你覆盖该设置。

🌐 Be advised that it is encouraged instead to use pnpm-workspace.yaml for this setting, to enforce the same behaviour in all environments. This option exists solely so you may override that if necessary.

--workspace-concurrency

  • 默认:4
  • 类型:数字

设置同时运行的任务最大数量。要实现无限并发,请使用 Infinity

🌐 Set the maximum number of tasks to run simultaneously. For unlimited concurrency use Infinity.

你可以将 workspace-concurrency 设置为 <= 0,它将使用主机的核心数量作为:max(1, (number of cores) - abs(workspace-concurrency))

🌐 You can set the workspace-concurrency as <= 0 and it will use amount of cores of the host as: max(1, (number of cores) - abs(workspace-concurrency))

--[no-]bail

  • 默认:
  • 类型:布尔

如果为 true,则在任务引发错误时停止。

🌐 If true, stops when a task throws an error.

此配置不会影响退出代码。即使使用 --no-bail,所有任务都会完成,但如果任何任务失败,命令将以非零代码退出。

🌐 This config does not affect the exit code. Even if --no-bail is used, all tasks will finish but if any of the tasks fail, the command will exit with a non-zero code.

示例(在每个包中运行测试,如果其中一个包中的测试失败则继续):

🌐 Example (run tests in every package, continue if tests fail in one of them):

pnpm -r --no-bail test

--[no-]sort

  • 默认:
  • 类型:布尔

true 时,软件包会按拓扑顺序排序(依赖在依赖它的项之前)。传入 --no-sort 可禁用此功能。

🌐 When true, packages are sorted topologically (dependencies before dependents). Pass --no-sort to disable.

示例:

🌐 Example:

pnpm -r --no-sort test

--reverse

  • 默认:
  • 类型:布尔

true 时,包的顺序被颠倒。

🌐 When true, the order of packages is reversed.

pnpm -r --reverse run clean

--filter <package_selector>

了解更多关于筛选的信息。