跳至主要內容
版本:6.x

pnpm exec

在專案的範圍中執行 Shell 命令。

node_modules/.bin 會被添加到 PATH,因此 pnpm exec 允許執行依賴關係的命令。

Examples

如果您的專案使用 Jest 作為依附套件,則無需全域安裝 Jest,只需使用 pnpm exec 執行它:

pnpm exec jest

當命令名稱與 pnpm 的內建命令不衝突時, exec 這部分實際上是可選的,因此您也可以只執行:

pnpm jest

Options

有關 exec 命令的選項需置於 exec 關鍵字前。 置於 exec 關鍵字後的選項將會提供給執行的命令。

正確範例, pnpm 將遞迴地執行:

pnpm -r exec jest

錯誤範例,pnpm 不會遞迴地執行,但 jest 會以 -r 選項執行:

pnpm exec jest -r

--recursive, -r

Added in: v2.9.0

Execute the shell command in every project of the workspace.

The name of the current package is available through the environment variable PNPM_PACKAGE_NAME (supported from pnpm v2.22.0 onwards).

Examples

Prune node_modules installations for all packages:

pnpm -r exec rm -rf node_modules

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

--parallel

Added in: v5.1.0

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

--shell-mode, -c

Added in: v6.31.0

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

--filter <package_selector>

Read more about filtering.