스크립트
이 페이지에서는 pnpm이 package.json의 scripts 필드를 처리하는 방법을 설명합니다.
Hidden scripts#
이름이 .으로 시작하는 스크립트는 숨겨집니다. 이러한 스크립트는 pnpm run으로 직접 실행할 수 없으며 pnpm run 목록에서 생략됩니다. 숨겨진 스크립트는 다른 스크립트에서만 호출할 수 있습니다.
{
"scripts": {
".helper": "echo 'I am hidden'",
"build": "pnpm run .helper && tsc"
}
}
이 예시에서 pnpm run .helper는 실패하지만, .helper가 다른 스크립트에서 호출되므로 pnpm run build는 성공합니다.
환경 변수#
pnpm은 라이프사이클 스크립트 실행 중에 다음 환경 변수를 설정합니다:
npm_package_name: the package namenpm_package_version: the package versionnpm_package_config_*,npm_package_engines_*,npm_package_bin_*: theconfig,engines, andbinfields of the manifest, one variable per entry (for example,npm_package_config_port). A stringbinsetsnpm_package_bin.npm_package_json: the path to the package'spackage.jsonnpm_lifecycle_event: the name of the running script (e.g.,postinstall)npm_lifecycle_script: the command of the running scriptnpm_node_execpathandNODE: the path to the Node.js executablenpm_execpath: the path to the running pnpmnpm_config_user_agent: pnpm's user agent stringnpm_config_node_gyp: the path to the bundlednode-gyp, unless the environment already sets itINIT_CWD: the directory where pnpm was startedPNPM_SCRIPT_SRC_DIR: the directory of the package whose script runsTMPDIR:node_modules/.tmpin the package, unlessunsafePermistrue
참고
Apart from the variables above, pnpm does not set npm_config_* variables from
its configuration. Other npm_config_* variables in the environment reach the
script unchanged, except auth, scope-registry, and per-registry settings (names
starting with _, /, or @, or containing :_).
Processes a script leaves running#
A process that a script or a command run by pnpm exec or pnpm dlx starts
and leaves running, such as a daemon, an editor, or a browser opened by the
open package, keeps running after pnpm exits. It does so whether the script
succeeded or failed, and after Ctrl+C, just as it would if the script ran
without pnpm. Closing the terminal ends the processes attached to it, as the
operating system always does.
pnpm ends what it started in two cases only:
- When pnpm itself is killed or crashes while a script runs, for example when
a CI job is cancelled. On Windows this ends everything the script started,
except a process started with
CREATE_BREAKAWAY_FROM_JOB. On Unix it ends the scripts that run in a process group of their own, which is every script of a parallel run and every script started without a terminal. A process that leaves its process group, such as a daemon, keeps running. - When a script fails in a recursive or parallel run, pnpm stops the scripts
of the other packages that are still running, unless
--no-bailis set.
Built-in command and script name conflicts#
The following built-in commands prefer user scripts: clean (and its alias purge), setup, deploy, rebuild (and its alias rb), and tasks. package.json에 이러한 이름 중 하나로 스크립트가 정의되어 있으면, pnpm <name>은 내장 명령 대신 해당 스크립트를 실행합니다.
내장 명령을 강제로 실행하려면 pnpm pm <name>을 사용하세요.
Lifecycle scripts#
pnpm install runs these scripts of each project in the workspace, in order:
preinstall, install, postinstall, preprepare, prepare, and
postprepare. With --prod, or when it installs specific packages, it runs
only preinstall, install, and postinstall.
For pre and post scripts of other scripts run by pnpm run,
see enablePrePostScripts.
pnpm:devPreinstall#
Runs when pnpm install runs in the project itself, including in CI. It does not run when the package is installed as a dependency of another project.
의존성이 설치되기 전에 실행됩니다.
이 스크립트는 루트 프로젝트의 package.json에 설정된 경우에만 실행됩니다.