pnpm -r, --recursive

别名:m、multi、recursive、<command> -r

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

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

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

  • exec
  • run
  • test
  • add

如果你希望在运行脚本时也包含根项目,请将 [include-workspace-root] 设置设为 true。

用法示例:

pnpm -r publish

By default, recursive run, exec, and test execute projects in topological order: dependencies run before their dependents. Use --no-sort to disable graph ordering, or --parallel to start tasks without waiting for dependencies.

配置项#

  • 默认值: false
  • 类型:true,false,deep

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

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

请注意,我们鼓励使用 pnpm-workspace.yaml 代替来进行此设置,去强制所有环境中都有同样的表现。此选项单独存在,以便你可以在必要时覆盖它。

--workspace-concurrency#

  • Default: the smaller of 4 and the number of available CPU cores
  • 类型:Number

设置同时运行的最大任务数。对于无限并发使用 Infinity。

In a container with a CPU quota, such as a Kubernetes CPU limit, the quota is the number of available CPU cores when it is smaller than the number of CPUs the container may run on. A fractional quota is rounded down, to at least 1.

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

--[no-]bail#

  • 默认值:true
  • 类型:Boolean

如果为 true,则在任务抛出错误时停止。

With --no-bail, tasks that depend on a failed task are skipped and independent tasks keep running. This config does not affect the exit code: if any task fails, the command exits with a non-zero code. See --no-bail.

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

pnpm -r --no-bail test

--[no-]sort#

  • 默认值:true
  • 类型:Boolean

When true, commands follow the workspace dependency graph. Recursive run also applies relationships from the tasks setting. Pass --no-sort to remove graph ordering. This also makes tasks, --reverse, and --resume-from inapplicable.

示例:

pnpm -r --no-sort test

--reverse#

  • 默认值: false
  • 类型:Boolean

When true, dependency edges are reversed. For recursive run, this reverses the resolved task graph, including relationships declared with dependsOn.

pnpm -r --reverse run clean

--filter <package_selector>#

阅读更多有关过滤的内容。