pnpm deploy reruns the deployed project's preinstall/install/postinstall scripts #17742
Replies: 3 comments 3 replies
|
@TrevorBurnham, are you planning to open a pull request for this? If so, reply here and a maintainer will assign the issue to you, so nobody else starts on the same fix. |
|
As a workaround until this is decided: pnpm sets "scripts": {
"preinstall": "node -e \"process.exit(process.env.npm_command === 'deploy' ? 0 : 1)\" || rm -rf ./dist/*"
}On a POSIX shell, You don't need Limitations:
Written by an agent (Claude Code, claude-opus-5-5). |
|
Posted a workaround for you above. I don't personally care that match about this but it is a breaking change. Which we can do if users will ask for it. |
Uh oh!
There was an error while loading. Please reload this page.
Verify latest release
pnpm version
12.18.0
Which area(s) of pnpm are affected?
CLI (
pnpm deploy)Reproduction steps
Workspace layout:
native-depis any registry package whosepostinstallwrites a file (a native addon in practice; in my repro it writesbuilt.txt).Results:
native-depbuild output in deployapp'spreinstallruns in deploy dir--ignore-scriptsDescribe the Bug
pnpm deploycopies the project's files, already built, into the target directory, then runs that project's ownpreinstall,install, andpostinstallscripts again there. For a package with abinding.gyp, that includes the implicitnode-gyp rebuild.These reruns are slow at best and destructive at worst. One package I deploy has
"preinstall": "rm -rf ./dist/*", which empties the deployeddist. With--prod, the scripts can also fail because their devDependencies are not installed.--ignore-scriptsis the only way to avoid this, but it also stops pnpm from applying side-effects cache entries to dependencies. The deploy then ships native dependencies without their compiled.nodefiles, and the app fails at runtime.So there is no way to deploy an app that has native dependencies and its own install scripts. My workaround is to refuse to deploy any package that has these scripts or a
binding.gyp.#7282 reported the same problem for
prepare, and #15322 fixed it by skipping the deployed project'spreparescripts. The install stages have the same problem.Expected Behavior
pnpm deploydoes not run the deployed project's ownpreinstall,install, orpostinstallscripts, as it already skipsprepare. Dependencies' scripts and side-effects cache behave as they do today.If changing the default is too disruptive, an option to skip only the deployed project's lifecycle scripts would also work.
Which Node.js version are you using?
24.22.1
Which operating systems have you used?
Written by an agent (Claude Code, claude-opus-5-5).
All reactions