Skip to main content
Version: 11.x

pnpm exec

在项目范围内执行 shell 命令。

🌐 Execute a shell command in scope of a project.

node_modules/.bin被添加到PATH中,因此pnpm exec允许执行依赖的命令。

示例

🌐 Examples

如果你的项目依赖于 Jest,就无需全局安装 Jest,只需用 pnpm exec 运行即可:

🌐 If you have Jest as a dependency of your project, there is no need to install Jest globally, just run it with pnpm exec:

pnpm exec jest

当命令与内置 pnpm 命令不冲突时,exec 部分实际上是可选的,所以你也可以直接运行:

🌐 The exec part is actually optional when the command is not in conflict with a builtin pnpm command, so you may also just run:

pnpm jest

选项

🌐 Options

exec 命令的任何选项都应在 exec 关键字之前列出。 在 exec 关键字之后列出的选项将传递给执行的命令。

🌐 Any options for the exec command should be listed before the exec keyword. Options listed after the exec keyword are passed to the executed command.

好的。pnpm 将会递归运行:

🌐 Good. pnpm will run recursively:

pnpm -r exec jest

不行,pnpm 不会递归运行,但 jest 将会以 -r 选项执行:

🌐 Bad, pnpm will not run recursively but jest will be executed with the -r option:

pnpm exec jest -r

--recursive, -r

在工作区的每个项目中执行 shell 命令。

🌐 Execute the shell command in every project of the workspace.

当前软件包的名称可以通过环境变量 PNPM_PACKAGE_NAME 获取。

🌐 The name of the current package is available through the environment variable PNPM_PACKAGE_NAME.

示例

🌐 Examples

修剪所有包的 node_modules 安装:

🌐 Prune node_modules installations for all packages:

pnpm -r exec rm -rf node_modules

查看所有软件包的包信息。应与环境变量生效的 --shell-mode(或 -c)选项一起使用。

🌐 View package information for all packages. This should be used with the --shell-mode (or -c) option for the environment variable to work.

pnpm -rc exec pnpm view \$PNPM_PACKAGE_NAME

--no-reporter-hide-prefix

并行运行命令时不隐藏前缀。

🌐 Do not hide prefix when running commands in parallel.

--resume-from <package_name>

从特定项目恢复执行。如果你在处理一个大型工作区,并且希望在特定项目上重新开始构建,而无需运行构建顺序中位于它之前的所有项目,这会很有用。

🌐 Resume execution from a particular project. This can be useful if you are working with a large workspace and you want to restart a build at a particular project without running through all of the projects that precede it in the build order.

--parallel

完全忽略并发和拓扑排序,在所有匹配的包中立即运行给定的脚本。对于跨多个包的长时间运行的进程,例如耗时的构建过程,这是首选的参数。

🌐 Completely disregard concurrency and topological sorting, running a given script immediately in all matching packages. This is the preferred flag for long-running processes over many packages, for instance, a lengthy build process.

--shell-mode, -c

在 shell 中运行命令。在 UNIX 上使用 /bin/sh,在 Windows 上使用 \cmd.exe

🌐 Runs the command inside of a shell. Uses /bin/sh on UNIX and \cmd.exe on Windows.

--report-summary

在运行命令文档中阅读有关此选项的信息

--filter <package_selector>

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