본문으로 건너뛰기
버전: 9.x

pnpm run

Aliases: run-script

패키지의 매니페스트 파일에 정의된 스크립트를 실행합니다.

예시

Let's say you have a watch script configured in your package.json, like so:

"scripts": {
"watch": "webpack --watch"
}

You can now run that script by using pnpm run watch! 간단하지요? Another thing to note for those that like to save keystrokes and time is that all scripts get aliased in as pnpm commands, so ultimately pnpm watch is just shorthand for pnpm run watch (ONLY for scripts that do not share the same name as already existing pnpm commands).

Running multiple scripts

스크립트의 이름 대신 정규식을 사용하여 동시에 여러 스크립트를 실행할 수 있습니다.

pnpm run "/<regex>/"

Run all scripts that start with watch::

pnpm run "/^watch:.*/"

Details

In addition to the shell’s pre-existing PATH, pnpm run includes node_modules/.bin in the PATH provided to scripts. 즉, 패키지가 설치되어 있는 한 일반 명령어처럼 스크립트에서 사용할 수 있습니다. For example, if you have eslint installed, you can write up a script like so:

"lint": "eslint src --fix"

And even though eslint is not installed globally in your shell, it will run.

For workspaces, <workspace root>/node_modules/.bin is also added to the PATH, so if a tool is installed in the workspace root, it may be called in any workspace package's scripts.

환경

There are some environment variables that pnpm automatically creates for the executed scripts. These environment variables may be used to get contextual information about the running process.

These are the environment variables created by pnpm:

  • npm_command - contains the name of the executed command. If the executed command is pnpm run, then the value of this variable will be "run-script".

옵션

Any options for the run command should be listed before the script's name. 스크립트의 이름 뒤에 나열된 옵션은 실행된 스크립트에 전달됩니다.

All these will run pnpm CLI with the --silent option:

pnpm run --silent watch
pnpm --silent run watch
pnpm --silent watch

명령어 이름 뒤에 전달된 모든 인수는 실행된 스크립트에 추가됩니다. So if watch runs webpack --watch, then this command:

pnpm run watch --no-color

이렇게 실행됩니다.

webpack --watch --no-color

--recursive, -r

This runs an arbitrary command from each package's "scripts" object. If a package doesn't have the command, it is skipped. If none of the packages have the command, the command fails.

--if-present

You can use the --if-present flag to avoid exiting with a non-zero exit code when the script is undefined. This lets you run potentially undefined scripts without breaking the execution chain.

--parallel

동시성 및 토폴로지 정렬을 완전히 무시하고, prefixed streaming output이 있는 모든 일치하는 패키지에서 즉시 지정된 스크립트를 실행합니다. 긴 빌드 프로세스와 같은 많은 패키지에 대한 장기 실행 프로세스에서 선호되는 플래그입니다.

--stream

Stream output from child processes immediately, prefixed with the originating package directory. This allows output from different packages to be interleaved.

--aggregate-output

Aggregate output from child processes that are run in parallel, and only print output when the child process is finished. It makes reading large logs after running pnpm -r <command> with --parallel or with --workspace-concurrency=<number> much easier (especially on CI). Only --reporter=append-only is supported.

--resume-from &lt;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.

--report-summary

Record the result of the scripts executions into a pnpm-exec-summary.json file.

An example of a pnpm-exec-summary.json file:

{
"executionStatus": {
"/Users/zoltan/src/pnpm/pnpm/cli/command": {
"status": "passed",
"duration": 1861.143042
},
"/Users/zoltan/src/pnpm/pnpm/cli/common-cli-options-help": {
"status": "passed",
"duration": 1865.914958
}
}

Possible values of status are: 'passed', 'queued', 'running'.

--reporter-hide-prefix

Hide workspace prefix from output from child processes that are run in parallel, and only print the raw output. This can be useful if you are running on CI and the output must be in a specific format without any prefixes (e.g. GitHub Actions annotations). Only --reporter=append-only is supported.

--filter &lt;package_selector>

Read more about filtering.

.npmrc settings

enable-pre-post-scripts

  • Default: true
  • Type: Boolean

When true, pnpm will run any pre/post scripts automatically. So running pnpm foo will be like running pnpm prefoo && pnpm foo && pnpm postfoo.

script-shell

  • Default: null
  • Type: path

The shell to use for scripts run with the pnpm run command.

For instance, to force usage of Git Bash on Windows:

pnpm config set script-shell "C:\\Program Files\\git\\bin\\bash.exe"

shell-emulator

  • Default: false
  • Type: Boolean

When true, pnpm will use a JavaScript implementation of a bash-like shell to execute scripts.

This option simplifies cross-platform scripting. For instance, by default, the next script will fail on non-POSIX-compliant systems:

"scripts": {
"test": "NODE_ENV=test node test.js"
}

But if the shell-emulator setting is set to true, it will work on all platforms.