Repository navigation
fix(shim): move npm global links to the reinstalled Node.js version #3283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mondaychen
wants to merge
2
commits into
voidzero-dev:main
Choose a base branch
from
mondaychen:fix/npm-global-relink-node-version
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...apshots/tests/cli_snapshots/fixtures/npm_global_install_node_version_relink/.node-version
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 24.22.1 |
2 changes: 2 additions & 0 deletions
2
..._snapshots/tests/cli_snapshots/fixtures/npm_global_install_node_version_relink/pkg/cli.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| console.log('relink-cli works'); |
7 changes: 7 additions & 0 deletions
7
...hots/tests/cli_snapshots/fixtures/npm_global_install_node_version_relink/pkg/package.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "name": "npm-global-relink-pkg", | ||
| "version": "1.0.0", | ||
| "bin": { | ||
| "npm-global-relink-cli": "./cli.js" | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
...pshots/tests/cli_snapshots/fixtures/npm_global_install_node_version_relink/snapshots.toml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Each Vite+-managed Node.js version has its own npm global prefix. The runner | ||
| # seeds the runtime directory from a shared cache, so each step sets a | ||
| # case-local prefix per Node.js version instead. | ||
| [[case]] | ||
| name = "npm_global_install_node_version_relink" | ||
| vp = "global" | ||
| skip-platforms = ["windows"] | ||
| steps = [ | ||
| { tty = false, argv = ["npm", "install", "-g", "--ignore-scripts", "./pkg"], envs = [["NPM_CONFIG_PREFIX", "${workspace}/node-24"]], comment = "Install with Node.js 24 (creates the link)", continue-on-failure = true }, | ||
| { argv = ["vpt", "grep-file", "$VP_HOME/bins/npm-global-relink-cli.json", "\"nodeVersion\": \"24.22.1\""], comment = "BinConfig records Node.js 24", continue-on-failure = true }, | ||
| { tty = false, argv = ["npm", "install", "-g", "--ignore-scripts", "./pkg"], envs = [["VP_NODE_VERSION", "26.12.1"], ["NPM_CONFIG_PREFIX", "${workspace}/node-26"]], comment = "Install again with Node.js 26 (moves the link to the new prefix)", continue-on-failure = true }, | ||
| { argv = ["vpt", "grep-file", "$VP_HOME/bins/npm-global-relink-cli.json", "\"nodeVersion\": \"26.12.1\""], comment = "BinConfig records Node.js 26", continue-on-failure = true }, | ||
| { tty = false, argv = ["npm", "install", "-g", "--ignore-scripts", "--dry-run", "./pkg"], envs = [["NPM_CONFIG_PREFIX", "${workspace}/node-24"]], comment = "Dry run with Node.js 24, whose prefix still has the package (the link stays on Node.js 26)", continue-on-failure = true }, | ||
| { tty = false, argv = ["npm", "install", "-g", "--ignore-scripts", "./pkg"], envs = [["NPM_CONFIG_PREFIX", "${workspace}/node-24"], ["npm_config_dry_run", "true"]], comment = "Dry run from the npm environment config (the link stays on Node.js 26)", continue-on-failure = true }, | ||
| { argv = ["vpt", "grep-file", "$VP_HOME/bins/npm-global-relink-cli.json", "\"nodeVersion\": \"26.12.1\""], comment = "BinConfig still records Node.js 26", continue-on-failure = true }, | ||
| { argv = ["vpt", "rm", "-rf", "node-24"], comment = "Remove the Node.js 24 copy: the command must not depend on it", continue-on-failure = true }, | ||
| { argv = ["npm-global-relink-cli"], comment = "Should be callable via the moved link", continue-on-failure = true }, | ||
| { tty = false, argv = ["npm", "install", "-g", "--ignore-scripts", "./pkg"], envs = [["VP_NODE_VERSION", "26.12.1"], ["NPM_CONFIG_PREFIX", "${workspace}/node-26"]], comment = "Install again with Node.js 26 (the link is current, so no message)" }, | ||
| ] | ||
| after = [ | ||
| { tty = false, argv = ["npm", "uninstall", "-g", "--ignore-scripts", "npm-global-relink-pkg"], envs = [["VP_NODE_VERSION", "26.12.1"], ["NPM_CONFIG_PREFIX", "${workspace}/node-26"]], continue-on-failure = true }, | ||
| ] |
88 changes: 88 additions & 0 deletions
88
...install_node_version_relink/snapshots/npm_global_install_node_version_relink.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # npm_global_install_node_version_relink | ||
|
|
||
| ## `NPM_CONFIG_PREFIX=${workspace}/node-24 npm install -g --ignore-scripts ./pkg` | ||
|
|
||
| Install with Node.js 24 (creates the link) | ||
|
|
||
| ``` | ||
|
|
||
| added 1 package in <duration> | ||
| Linked 'npm-global-relink-cli' to <home>/.vite-plus/bin/npm-global-relink-cli | ||
| ``` | ||
|
|
||
| ## `vpt grep-file $VP_HOME/bins/npm-global-relink-cli.json '"nodeVersion": "24.22.1"'` | ||
|
|
||
| BinConfig records Node.js 24 | ||
|
|
||
| ``` | ||
| <home>/.vite-plus/bins/npm-global-relink-cli.json: found "\"nodeVersion\": \"24.22.1\"" | ||
| ``` | ||
|
|
||
| ## `VP_NODE_VERSION=26.12.1 NPM_CONFIG_PREFIX=${workspace}/node-26 npm install -g --ignore-scripts ./pkg` | ||
|
|
||
| Install again with Node.js 26 (moves the link to the new prefix) | ||
|
|
||
| ``` | ||
|
|
||
| added 1 package in <duration> | ||
| note: Moving 'npm-global-relink-cli' from Node.js <version> to 26.12.1 | ||
| Linked 'npm-global-relink-cli' to <home>/.vite-plus/bin/npm-global-relink-cli | ||
| ``` | ||
|
|
||
| ## `vpt grep-file $VP_HOME/bins/npm-global-relink-cli.json '"nodeVersion": "26.12.1"'` | ||
|
|
||
| BinConfig records Node.js 26 | ||
|
|
||
| ``` | ||
| <home>/.vite-plus/bins/npm-global-relink-cli.json: found "\"nodeVersion\": \"26.12.1\"" | ||
| ``` | ||
|
|
||
| ## `NPM_CONFIG_PREFIX=${workspace}/node-24 npm install -g --ignore-scripts --dry-run ./pkg` | ||
|
|
||
| Dry run with Node.js 24, whose prefix still has the package (the link stays on Node.js 26) | ||
|
|
||
| ``` | ||
|
|
||
| up to date in <duration> | ||
| ``` | ||
|
|
||
| ## `NPM_CONFIG_PREFIX=${workspace}/node-24 npm_config_dry_run=true npm install -g --ignore-scripts ./pkg` | ||
|
|
||
| Dry run from the npm environment config (the link stays on Node.js 26) | ||
|
|
||
| ``` | ||
|
|
||
| up to date in <duration> | ||
| ``` | ||
|
|
||
| ## `vpt grep-file $VP_HOME/bins/npm-global-relink-cli.json '"nodeVersion": "26.12.1"'` | ||
|
|
||
| BinConfig still records Node.js 26 | ||
|
|
||
| ``` | ||
| <home>/.vite-plus/bins/npm-global-relink-cli.json: found "\"nodeVersion\": \"26.12.1\"" | ||
| ``` | ||
|
|
||
| ## `vpt rm -rf node-24` | ||
|
|
||
| Remove the Node.js 24 copy: the command must not depend on it | ||
|
|
||
| ``` | ||
| ``` | ||
|
|
||
| ## `npm-global-relink-cli` | ||
|
|
||
| Should be callable via the moved link | ||
|
|
||
| ``` | ||
| relink-cli works | ||
| ``` | ||
|
|
||
| ## `VP_NODE_VERSION=26.12.1 NPM_CONFIG_PREFIX=${workspace}/node-26 npm install -g --ignore-scripts ./pkg` | ||
|
|
||
| Install again with Node.js 26 (the link is current, so no message) | ||
|
|
||
| ``` | ||
|
|
||
| up to date in <duration> | ||
| ``` |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] Preserve the existing npm link during a dry run
When the same package already exists in two npm prefixes, this condition can switch the active binary after
npm install -g --dry-run. For example, the Vite+ link points to version2.0.0in prefix B, while prefix A still contains1.0.0. Runningnpm install -g --prefix <A> <local-v2-package> --dry-runsucceeds without changing A's files, but the post-install hook sees A's existing binary and replaces the link to B with a link to A. I reproduced this on the PR head: the global command changed from2.0.0to1.0.0, while A's installed package remained unchanged. The previous same-owner guard skipped this mutation. Please preserve the link and itsBinConfigwhen npm's effective dry-run setting is enabled, including configuration from the environment or npmrc, and add a regression case with both prefixes already populated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed in ef2b9e7