fix(exec): don't inherit global config when installing to the npx cache - #9894
Open
lazerg wants to merge 2 commits into
Open
fix(exec): don't inherit global config when installing to the npx cache#9894lazerg wants to merge 2 commits into
lazerg wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What / Why
An
npxspawned from a lifecycle script duringnpm install -ginheritsnpm_config_global=truefrom the script environment, soexec()builds the npx cache Arborist withglobal: true. On reify the installed package counts as a global top-level install, andbin-linksputs the symlinks in<npxCache>/binrather than<installDir>/node_modules/.bin, which is the only pathexec()adds tobinPaths. A warm npx cache hides the problem because nothing is reified.On npm 10.x that surfaces the way the issue reports it, as
command not foundand a rollback of the whole global install. Since npm 11.2 the failure comes a step earlier: global mode also skips saving the ideal tree, so thePackageJson.load(installDir)after reify throwsCould not read package.json ... npxCache/<hash>/package.json. Same cause either way.The npx cache is never a global install, so its Arborist now sets
global: falseexplicitly.Testing
New case in
workspaces/libnpmexec/test/registry.jsthat runs exec withglobal: trueand checks the bins end up in the cache entry'snode_modules/.binand not at the cache root. It fails on the current code and passes with the fix.Also checked by hand with a cold cache:
npm_config_global=true node . exec --yes -- cowsay helloerrors onlatestand works after the change.References
Fixes #9890