Skip to main content
Version: Next

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

  • 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

  • 默认:false

    ¥Default: false

  • 类型:true, false, deep

    ¥Type: true, false, deep

将 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

    ¥Default: 4

  • 类型:数字

    ¥Type: Number

设置同时运行的最大任务数。对于无限并发,请使用 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

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

如果为 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

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

true 时,包按拓扑排序(依赖位于依赖之前)。通过 --no-sort 禁用。

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

示例:

¥Example:

pnpm -r --no-sort test

--reverse

  • 默认:false

    ¥Default: false

  • 类型:boolean

    ¥Type: boolean

true 时,包的顺序相反。

¥When true, the order of packages is reversed.

pnpm -r --reverse run clean

--filter <package_selector>

了解有关过滤的更多信息。

¥Read more about filtering.