pnpm run

별칭: run-script

패키지의 매니페스트 파일에 정의된 스크립트를 실행합니다. Without a script name, pnpm run lists the available scripts:

pnpm run

예시#

다음과 같이 package.json에 watch 스크립트가 설정되어 있다고 가정해 봅시다:

package.json
"scripts": {
    "watch": "webpack --watch"
}

Run it with pnpm run watch. pnpm watch is a shorthand for pnpm run watch. The shorthand works only for scripts whose name is not a pnpm command. A built-in command runs instead of a same-named script, except for the commands listed in pnpm pm, which run the script.

여러 스크립트 실행#

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

pnpm run "/<regex>/"

watch:로 시작하는 모든 스크립트 실행:

pnpm run "/^watch:/"

The selector must be written as a regular expression literal (that is, wrapped in slashes) and quoted, so the shell does not mangle it. 일반 문자열은 항상 리터럴 스크립트 이름으로 취급되며, 인수와 이름이 정확히 일치하는 스크립트가 정규식 매칭보다 우선합니다.

The pattern uses JavaScript regular expression syntax, including lookahead and lookbehind. Run every hello: script except hello:b:

pnpm run "/^hello:(?!b$).*$/"

매칭은 고정되지 않으므로 "/build:.*/"는 prebuild:web에도 일치합니다. 정확한 접두사가 필요한 경우 ^와 $로 패턴을 고정하세요.

매칭된 스크립트는 사전순으로 실행되므로, package.json에 스크립트가 나타나는 순서와 관계없이 선택이 결정적입니다. Since v12.2.0 they run concurrently, up to --workspace-concurrency, with each script's output prefixed by its name. 엄격하게 한 번에 하나씩 실행하려면 --sequential을 추가하세요.

With --no-bail, a failing script does not stop the others: every matched script is allowed to finish, and the command then exits with ERR_PNPM_RUN_FAILED, listing the ones that failed in selection order.

정규식 플래그는 지원되지 않습니다: pnpm run "/^build:.*/i"는 ERR_PNPM_UNSUPPORTED_SCRIPT_COMMAND_FORMAT 오류로 실패합니다.

세부 정보#

In addition to the shell's pre-existing PATH, pnpm run includes node_modules/.bin in the PATH provided to scripts. 즉, 패키지가 설치되어 있는 한 일반 명령어처럼 스크립트에서 사용할 수 있습니다. 예를 들어, eslint가 설치되어 있다면 다음과 같이 스크립트를 작성할 수 있습니다:

package.json
"lint": "eslint src --fix"

그러면 eslint가 셸에 전역으로 설치되어 있지 않아도 실행됩니다.

워크스페이스의 경우 <workspace root>/node_modules/.bin도 PATH에 추가되므로, 워크스페이스 루트에 설치된 도구는 모든 워크스페이스 패키지의 scripts에서 호출할 수 있습니다.

환경#

실행되는 스크립트를 위해 pnpm이 자동으로 생성하는 환경 변수가 몇 가지 있습니다. 이러한 환경 변수를 사용하여 실행 중인 프로세스에 대한 컨텍스트 정보를 얻을 수 있습니다.

다음은 pnpm이 생성하는 환경 변수입니다:

  • npm_command - 실행된 명령의 이름을 포함합니다. 실행된 명령이 pnpm run이면 이 변수의 값은 "run-script"가 됩니다.
  • npm_lifecycle_event - the name of the running script.
  • npm_lifecycle_script - the command of the running script.
  • npm_package_json - the path to the package's package.json.
  • npm_package_* - the name, version, config, engines, and bin fields of package.json, such as npm_package_name and npm_package_config_port.
  • npm_config_user_agent - the user agent of pnpm.
  • npm_execpath - the path to the pnpm executable.
  • npm_node_execpath and NODE - the path to the Node.js executable.
  • INIT_CWD - the directory pnpm was run from.
  • PNPM_SCRIPT_SRC_DIR - the directory of the package whose script runs.
  • FORCE_COLOR - set to 1 when pnpm prints the script's output itself and pnpm's own output is in color. pnpm prints the output itself with --stream or --parallel, or when several scripts run at once. A FORCE_COLOR that is already set is kept.

옵션#

run 명령의 옵션은 모두 스크립트 이름 앞에 나열해야 합니다. 스크립트의 이름 뒤에 나열된 옵션은 실행된 스크립트에 전달됩니다.

다음은 모두 --silent 옵션으로 pnpm CLI를 실행합니다:

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

명령어 이름 뒤에 전달된 모든 인수는 실행된 스크립트에 추가됩니다. 따라서 watch가 webpack --watch를 실행한다면, 다음 명령은:

pnpm run watch --no-color

이렇게 실행됩니다.

webpack --watch --no-color

--recursive, -r#

이것은 각 패키지의 "scripts"에서 임의의 명령어를 실행합니다. 패키지에 명령어가 없으면 건너뜁니다. 명령이 있는 패키지가 하나도 없으면, 실패합니다.

By default, recursive runs use a dependency-aware task graph. Configure relationships between scripts with the tasks setting. --no-sort, and --parallel which implies it, remove that ordering and ignore the tasks declarations along with it.

--if-present#

스크립트가 정의되지 않았을 때 오류 종료 코드로 종료되지 않도록 하려면 --if-present 플래그를 사용할 수 있습니다. 이렇게 하면 실행 체인을 끊지 않고 정의되지 않았을 수도 있는 스크립트를 실행할 수 있습니다.

--no-bail#

일치하는 스크립트 중 하나가 실패하더라도 나머지 스크립트를 계속 실행합니다. 실패한 스크립트가 하나라도 있으면 명령은 여전히 영이 아닌 종료 코드로 종료됩니다.

--parallel#

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

--sequential, -s#

선택한 스크립트를 하나씩 차례로 실행합니다. This forces --workspace-concurrency to 1, so scripts matched by a regex selector never overlap, neither across workspace packages nor within a single package.

pnpm run --sequential "/^build:.*/"

재귀 실행에서는 각 워크스페이스 프로젝트 내부뿐 아니라 프로젝트 간에도 스크립트를 직렬화합니다. --sequential은 --parallel보다 우선합니다: 이 옵션이 설정되면 두 플래그가 나타나는 순서와 관계없이 동시성이 1로 고정됩니다.

참고

pnpm run에서 -s는 --sequential의 축약형입니다. This includes the pnpm <script> shorthand, so pnpm -s watch means pnpm run --sequential watch. CLI의 다른 모든 곳에서 -s는 여전히 --reporter=silent의 축약형입니다. 긴 형식인 --silent는 모든 명령에서 영향을 받지 않습니다.

On GitHub Actions, recursive runs with --sequential or --workspace-concurrency=1 group each script's output. Silent runs omit the group markers.

--workspace-concurrency#

Set the maximum number of workspace tasks to run simultaneously. See pnpm recursive --workspace-concurrency for defaults and how zero and negative values are interpreted.

--stream#

원래의 패키지 디렉토리가 접두사로 붙은 자식 프로세스의 출력을 즉시 스트리밍합니다. 이를 통해 다른 패키지의 출력이 인터리브될 수 있습니다.

--aggregate-output#

병렬로 실행되는 자식 프로세스의 출력을 집계하고 자식 프로세스가 완료될 때만 결과를 출력합니다. 이를 통해 pnpm -r <command>을 --parallel 또는 --workspace-concurrency=<number>과 함께 실행한 후 대량의 로그를 훨씬 쉽게 읽을 수 있습니다(특히 CI에서). 오직 --reporter=append-only만 지원됩니다.

--resume-from <package_name>#

Resume at the named package's requested task. pnpm skips the tasks a matching record of the previous run says already passed; without such a record it omits the task's transitive dependencies instead, treating them as completed. Either way it still runs the task itself, its dependents, and unrelated tasks in the selected graph. See Workspace task orchestration.

--dry-run#

Resolve a recursive run's task graph without running scripts. The plain output is one stable topological ordering, not a prediction of the order in which independent tasks will be dispatched.

pnpm -r run --dry-run build

--dry-run is only supported for recursive runs.

--json#

With --dry-run, print the resolved tasks and their dependency edges as JSON. See Inspect the task graph for the schema and an example.

--report-summary#

스크립트 실행 결과를 pnpm-exec-summary.json 파일에 기록합니다.

pnpm-exec-summary.json 파일의 예시:

pnpm-exec-summary.json
{
  "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, skipped, and failure. A failed entry also has prefix and message fields. The key of a task other than the requested script is <dir>#<task>.

--reporter-hide-prefix#

병렬로 실행되는 자식 프로세스의 출력에서 워크스페이스 접두사를 숨기고, 원시 출력만 표시합니다. 이는 CI에서 실행 중이고 출력이 접두사 없이 특정 형식이어야 하는 경우에 유용할 수 있습니다(예: GitHub Actions annotations). 오직 --reporter=append-only만 지원됩니다.

--sort, --reverse, --bail#

See --[no-]sort, --reverse, and --[no-]bail.

--filter <package_selector>#

필터링에 대해 자세히 알아보세요.

pnpm-workspace.yaml 설정#

The tasks setting configures dependency relationships and per-task concurrency limits for recursive runs.

enablePrePostScripts#

  • 기본값: true
  • 유형: Boolean

true이면 pnpm은 모든 pre/post 스크립트를 자동으로 실행합니다. 따라서 pnpm foo를 실행하는 것은 pnpm prefoo && pnpm foo && pnpm postfoo를 실행하는 것과 같습니다.

scriptShell#

  • 기본값: null
  • 유형: path

pnpm run 명령으로 실행하는 스크립트에 사용할 셸입니다.

예를 들어, Windows에서 Git Bash를 사용하도록 강제하려면:

pnpm config set scriptShell "C:\Program Files\git\bin\bash.exe"

Since v12.4.0, a relative path in pnpm-workspace.yaml resolves from the workspace root, including for scripts that run in a nested package. A bare command name such as bash is still looked up on PATH.

shellEmulator#

  • 기본값: false
  • 유형: Boolean

When true, pnpm will use its built-in cross-platform, bash-like shell to execute scripts.

이 옵션은 플랫폼 간 스크립팅을 단순화합니다. 예를 들어, 기본적으로 다음 스크립트는 POSIX 규격이 아닌 시스템에서 실패합니다.

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

하지만 shellEmulator 설정을 true로 지정하면 모든 플랫폼에서 동작합니다.

Since v12.8.0, a configured non-empty scriptShell wins over shellEmulator for pnpm run and lifecycle scripts. The emulator runs only when scriptShell is unset or empty.

참고

Node.js 22 이상에서는 pnpm의 도움 없이 스크립트를 실행할 수 있습니다. 위 예시의 경우 test 스크립트를 node --run test로 실행할 수 있습니다. 하지만 shellEmulator 옵션은 이 경우에 아무런 영향을 주지 않습니다. POSIX 기능에 의존하는 스크립트를 POSIX 규격이 아닌 환경에서 동작시키려면 pnpm run으로 실행해야 하며, node --run으로는 실행할 수 없습니다.