Repository navigation
fix(shim): move npm global links to the reinstalled Node.js version - #3283
Merged
fengmk2 merged 5 commits intoNov 20, 2026
Merged
Conversation
When the active Node.js version changes, `npm install -g <pkg>` installs a new copy into the new Node.js npm prefix. The `~/.vite-plus/bin` link kept the old target because Vite+ replaced a link only when a different package owned it. The command then kept running the old version. Replace the link also when the same package owns it but the link does not point to the binary in the current npm bin dir, record the new Node.js version, and tell the user that the link moved. Fixes voidzero-dev#3279 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fengmk2
reviewed
Oct 30, 2026
A dry run changes no files in the npm prefix, but the post-install hook still saw an existing binary in that prefix and could move the link to it. With the same package in two prefixes, `npm install -g --dry-run` into the older prefix moved the command back to the older version. Skip the post-install link step when npm's effective `dry-run` setting is on. A CLI flag wins; otherwise `npm config get dry-run` reports the value from the environment and npmrc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fengmk2
reviewed
Nov 1, 2026
fengmk2
reviewed
Nov 1, 2026
The dry-run probe ran `npm config get dry-run` without the install's arguments, and Vite+ parsed the dry-run flags itself. Both could disagree with npm: - Without `-g`, the probe failed with ENOWORKSPACES in a workspace child, and read a project .npmrc that `install -g` ignores. - An explicit `--userconfig` file was not read. - `--dry-run false`, `--no-dry-run false`, and the `--dry` abbreviation were parsed differently from npm. Pass the install's arguments to the probe so npm applies the same global mode, config files, and flag parsing. The extra positionals become extra keys, so read the `dry-run=` line. When npm cannot report the setting, leave the links unchanged and tell the user, instead of assuming a real install. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
liangmiQwQ
reviewed
Nov 17, 2026
liangmiQwQ
left a comment
Collaborator
There was a problem hiding this comment.
Found one remaining boolean-conversion edge case in the dry-run probe; details inline.
🤖 Generated by Codex.
npm converts an `undefined` value from the environment or an npmrc file to no value, so `npm_config_dry_run=undefined` gives a real install. `npm config get` prints the value before that conversion, and the probe read it as true, so Vite+ did not create or move the link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Fixes #3279.
When the active Node.js version changes,
npm install -g <pkg>installs a new copy into the new Node.js npm prefix. The~/.vite-plus/bin/<bin>link kept pointing to the old copy, because Vite+ replaced an existing npm link only when a different package owned it. npm reported success and Vite+ printed nothing, so the command kept running the old version.Now Vite+ also replaces the link when the same package owns it but the link does not point to the binary in the current npm bin dir. It records the new Node.js version in the BinConfig and prints a note:
A repeat install under the same Node.js version leaves the link and BinConfig unchanged and prints nothing new.
On Unix, the check compares the symlink target. On Windows, it checks the source path in the
.cmdwrapper thatcreate_bin_linkwrites.Dry runs
A dry run changes no files in the npm prefix, so the post-install link step now does nothing when npm's effective
dry-runsetting is on. This also covers the existing different-owner and missing-link paths. Without this, a dry run into an older prefix that still has the package could move the link back to the older copy.To get the effective value, Vite+ runs
npm config get dry-runwith the install's own arguments. npm then applies the same global mode, config files (--userconfig, no project.npmrcunder-g), and flag parsing (--dry-run false,--no-dry-run false, abbreviations) as it did for the install. The subcommand and package specs become extra keys, so Vite+ reads thedry-run=line. If npm cannot report the setting, Vite+ leaves the links unchanged and prints a note instead of assuming a real install.This adds one short
npm config getprocess after each successfulnpm install -g.Tests
test_npm_reinstall_under_new_node_version_moves_link: two npm prefixes, one per Node.js version. It fails with the old condition and passes with this change. It also checks that a repeat install changes nothing.dry-run=line and for npm's boolean values (npm config getprints environment values such as1unparsed).npm_global_install_node_version_relink(global flavor, Unix only, like the other npm link cases):VP_NODE_VERSION=26.12.1(the link moves).--dry-run,npm_config_dry_run=true,--no-dry-run false,--userconfig <file>, and an npm workspace child..npmrcsetsdry-run=true(ignored byinstall -g), and with--dry-run false.NPM_CONFIG_PREFIXper Node.js version instead of writing into the runtime folder.npm_global*snapshot cases pass locally.cargo fmt --checkandclippy -p vp_global_cli --all-targets --deny warningspass. I could not compile thecfg(windows)branch locally.🤖 Generated with Claude Code