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

pnpm run

별칭: run-script

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

예시

다음과 같이 package.json에 구성된 watch 스크립트가 있다고 가정해 보겠습니다.

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

이제 pnpm run watch을 사용하여 해당 스크립트를 실행할 수 있습니다! 간단하지요? 키 입력과 시간을 절약하는 것을 좋아하는 사람들을 위해 주목해야 할 또 다른 사항은 모든 스크립트가 pnpm 명령으로 앨리어싱된다는 것입니다. 따라서 궁극적으로 pnpm watchpnpm run watch 의 축약형입니다 (이미 존재하는 pnpm 명령과 동일한 이름을 공유하지 않는 스크립트에만 해당함).

Running multiple scripts

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

pnpm run "/<regex>/"

다음과 같이 watch:로 시작하는 모든 스크립트를 실행할 수 있습니다.

pnpm run "/^watch:.*/"

Details

셸의 기존 PATH에 더하여, pnpm runscripts에 제공된 PATHnode_modules/.bin 을 포함합니다. 즉, 패키지가 설치되어 있는 한 일반 명령어처럼 스크립트에서 사용할 수 있습니다. 예를 들어, eslint 가 설치되어 있는 경우, 다음과 같이 스크립트 를 작성할 수 있습니다.

"lint": "eslint src --fix"

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

워크스페이스의 경우, <workspace root>/node_modules/.bin 도 에 PATH에 추가되었으므로, 도구가 워크스페이스의 루트에 설치되었다면 어떤 워크스페이스 패키지의 scripts에서도 호출될 수 있습니다.

npm run과의 차이점

기본적으로, pnpm은 사용자 정의 스크립트 (예를 들어 prestart) 에 대해 임의의 prepost 훅을 실행하지 않습니다. npm으로부터 상속된 이 행위는 스크립트를 명시적인 대신 암시적인 상태로 만들며, 실행 흐름을 난독화합니다. 또한 pnpm servepnpm preserve 를 동작시키는 놀라운 실행으로 이어졌습니다.

If for some reason you need the pre/post scripts behavior of npm, use the enable-pre-post-scripts option.

환경

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".

옵션

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

이 모든 것은 --silent 옵션과 함께 pnpm CLI를 실행합니다.

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

명령어 이름 뒤에 전달된 모든 인수는 실행된 스크립트에 추가됩니다. 따라서 watchwebpack --watch를 실행하면 이 명령어는 다음과 같습니다.

pnpm run watch --no-color

이렇게 실행됩니다.

webpack --watch --no-color

--recursive, -r

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

--if-present

스크립트가 정의되지 않은 경우 --if-present 플래그를 사용하여 non-zero 종료 코드 로 종료되는 것을 방지할 수 있습니다. 이렇게 하면 실행 체인을 끊지 않고 잠재적으로 정의되지 않은 스크립트 을 실행할 수 있습니다.

--parallel

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

--stream

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

--aggregate-output

병렬로 실행되는 자식 프로세스의 출력을 집계하고 자식 프로세스가 완료될 때만 결과를 출력합니다. pnpm -r <command> 명령어가 --parallel 또는 --workspace-concurrency=<number> 와 함께 실행한 후 대용량 로그를 읽기가 훨씬 쉬게 만들어 줍니다 (특히 CI에서). --reporter=append-only 만 지원됩니다.

--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.

--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

Added in: v8.8.0

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 <package_selector>

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

.npmrc settings

enable-pre-post-scripts

  • 기본값: false
  • 유형: Boolean

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

script-shell

  • 기본값: null
  • 유형: path

pnpm run 명령어를 실행할 셸입니다.

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

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

shell-emulator

  • 기본값: false
  • 유형: Boolean

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

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

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

그러나 shell-emulator 의 설정이 true 로 설정되어 있으면 모든 플랫폼에서 동작합니다.