fix(nodeenv): point npm_config_prefix at the env in activate.bat and Activate.ps1 - #420
Merged
Merged
Conversation
…Activate.ps1 npx exports npm_config_prefix, and npm.cmd asks npm-prefix.js for the global prefix: when an npm is installed under that prefix, npm.cmd runs it instead of the one next to it. The posix and fish activate scripts save and override the variable, the cmd and PowerShell ones only touched PATH and NODE_PATH, so an activated environment kept running the outer npm under cmd.exe and PowerShell. activate.bat and Activate.ps1 now save an inherited npm_config_prefix, set it to the Scripts directory (npm's prefix on Windows is the one holding node.exe) and deactivate restores or drops it. A second activation without a deactivate in between is treated as a re-activation, so the value set by the first one is not mistaken for an inherited one. Windows environment names are case-insensitive, so the lowercase spelling covers NPM_CONFIG_PREFIX too. Closes #309
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.
Closes #309
What happens
npx(andnpm exec) exportsnpm_config_prefixto the script it runs. npm'snpm.cmdasksnpm-prefix.jsfor the global prefix, and when an npm is installed under that prefix it runs that one instead of the npm next to it. The posixactivateandactivate.fishsave and override the variable, butactivate.batandActivate.ps1only touchedPATHandNODE_PATH. So under cmd.exe and PowerShell an activated environment kept running the outer npm, exactly what the issue reports. Still reproducible with npm 11:npm.cmdhas kept the prefix lookup.What changes
activate.batandActivate.ps1save an inheritednpm_config_prefix, set it toScripts(npm's prefix on Windows is the directory holdingnode.exe, the same value the git-bashactivatealready uses) anddeactivaterestores or drops it.deactivatein between is treated as a re-activation, so the value set by the first one is not saved as if it were inherited.NPM_CONFIG_PREFIXtoo.Tests
tests/test_install_activate.py: the generatedactivate.bat,deactivate.batandActivate.ps1carry the save, set and restore lines (runs everywhere throughfake_win).tests/test_activate_win.py: cmd.exe and PowerShell are run with a leakednpm_config_prefix; after activation it points atScripts, afterdeactivatethe leaked value is back, and activate-twice-then-deactivate leaves it unset. These need a Windows host and run on thewindows-latestmatrix.The tests were pushed on their own first: the two "points npm at Scripts" tests failed on all five Windows jobs against the unchanged templates, and the whole matrix is green with the fix.