pnpm exec
在项目范围内执行 shell 命令。
¥Execute a shell command in scope of a project.
node_modules/.bin
被添加到 PATH
中,因此 pnpm exec
允许执行依赖的命令。
¥node_modules/.bin
is added to the PATH
, so pnpm exec
allows executing commands of dependencies.
示例
¥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
¥Read about this option in the run command docs