A configured scriptShell is spawned for pnpm run and lifecycle scripts even when shellEmulator is also enabled. The built-in emulator does not implement bash export or relative script paths the way Git Bash does, and the reported config sets both options, so the emulator was hiding the shell the user configured. shellEmulator still selects the built-in shell when scriptShell is unset. A blank scriptShell is unset on both runners, so the fallback shell and the extra-argument quoting match. The shell is still selected first, so a .bat or .cmd scriptShell is rejected before anything runs. Extra arguments are JSON-quoted only when cmd will parse the script (windowsVerbatimArguments). A non-cmd scriptShell, including a path such as C:\Program Files\Git\bin\bash.exe, gets POSIX quoting and is spawned without verbatim arguments, so the path stays one argument. PATH, bin lookup, and auth are not changed. Closes pnpm/pnpm#14719 --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Zoltan Kochan <z@kochan.io> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1.8 KiB
1.8 KiB
@pnpm/exec.npm-lifecycle
JavaScript package lifecycle hook runner
@pnpm/exec.npm-lifecycle is a library for executing packages' lifecycle
scripts. It is extracted from npm itself and intended to be fully compatible
with the way npm executes individual scripts.
Installation
pnpm add @pnpm/exec.npm-lifecycle
API
lifecycle(pkg, stage, wd, opts): Promise<void>
Runs the stage script of pkg in wd, followed by the .hooks/<stage>
hook of opts.dir when there is one.
opts.dir- thenode_modulesdirectory whose.hooksare run.opts.log- the logger the runner reports to.opts.stdio- the stdio passed to the child process.[0, 1, 2]by default.opts.runConcurrently- Boolean -falseby default. Iftrue, lifecycle scripts may run concurrently.opts.extraEnv- Record<string, string> - add some extra env vars to the exec environment of the lifecycle script.opts.extraBinPaths- string[] - directories added to thePATHof the lifecycle script.opts.onSpawn- Function - called with each spawned lifecycle child process.opts.scriptShell- the shell the script runs in.shby default,cmdon Windows.opts.shellEmulator- Boolean - whenscriptShellis unset, run the script in a JavaScript shell emulator instead of a system shell. A configuredscriptShellis used even when this is set.opts.scriptsPrependNodePath- Boolean | 'warn-only' - put the directory of the running Node.js binary on the script'sPATH.
makeEnv(pkg, opts): Record<string, string>
Builds the environment a lifecycle script of pkg runs with: the current
environment without private npm_config_* settings, plus the npm_package_*
variables derived from the manifest.