From c9e3ab700ede011a8b994727c596482e93e27123 Mon Sep 17 00:00:00 2001 From: naokihaba <59875779+naokihaba@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:35:00 +0900 Subject: [PATCH 1/3] fix(cli): move the selected managed Node.js to the front of PATH `vp install` prepended the selected Node.js bin directory with `dedupe_anywhere: true`. When that directory was already on PATH after another Node.js, it kept its position, so pnpm, engine checks, and lifecycle scripts used the other Node.js. Keep the existing position only for a system Node.js selected in system-first mode. Move a managed runtime to the front. Fixes #3492 --- crates/vp_global_cli/src/commands/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/crates/vp_global_cli/src/commands/mod.rs b/crates/vp_global_cli/src/commands/mod.rs index c135f19bb4..224a174ce0 100644 --- a/crates/vp_global_cli/src/commands/mod.rs +++ b/crates/vp_global_cli/src/commands/mod.rs @@ -118,12 +118,14 @@ pub async fn prepend_js_runtime_to_path_env(project_path: &AbsolutePath) -> Resu let config = env::config::load_config().await?; let mut executor = JsExecutor::new(None); - let node_bin_prefix = if config.node_shim_mode == env::config::ShimMode::SystemFirst + let (node_bin_prefix, system_runtime) = if config.node_shim_mode + == env::config::ShimMode::SystemFirst && let Some(system_node) = crate::shim::dispatch::find_system_tool("node") && let Some(bin_dir) = system_node.parent() { - bin_dir.to_absolute_path_buf() + (bin_dir.to_absolute_path_buf(), true) } else { + // The else branch selects a managed runtime: a system-first system Node is handled above. // Use project runtime if package.json exists, otherwise use CLI runtime let package_json_path = project_path.join("package.json"); let runtime = if package_json_path.as_path().exists() { @@ -131,13 +133,16 @@ pub async fn prepend_js_runtime_to_path_env(project_path: &AbsolutePath) -> Resu } else { executor.ensure_cli_runtime().await? }; - runtime.get_bin_prefix() + (runtime.get_bin_prefix(), false) }; + // A later PATH entry for the selected runtime does not make it win the + // `node` lookup, so move it to the front. A system directory keeps its + // position because it can also contain unrelated tools. prepend_tools_to_path_env( &node_bin_prefix, &["node"], - PrependOptions { dedupe_anywhere: true }, + PrependOptions { dedupe_anywhere: system_runtime }, )?; if let Some(package_manager) = env::package_manager::resolve_current_spec(project_path).await? { if config.package_manager_shim_mode_for(package_manager.package_manager_type) From ffd83ba52c306ee580312d52f068c6ae079ef8c8 Mon Sep 17 00:00:00 2001 From: naokihaba <59875779+naokihaba@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:35:00 +0900 Subject: [PATCH 2/3] test(cli): cover a managed Node.js that follows another Node.js on PATH --- .../fixtures/system_first_path/snapshots.toml | 7 +++++++ .../managed_node_precedes_later_node_path.md | 7 +++++++ .../fixtures/system_first_path/verify.mjs | 20 +++++++++++++++++-- 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots/managed_node_precedes_later_node_path.md diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots.toml index 3f2ae082b8..471912632e 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots.toml @@ -5,6 +5,13 @@ skip-platforms = ["windows"] prewarm-package-managers = false steps = [["node", "verify.mjs", "system-pm"]] +[[case]] +name = "managed_node_precedes_later_node_path" +vp = "global" +skip-platforms = ["windows"] +prewarm-package-managers = false +steps = [["node", "verify.mjs", "managed-node-later"]] + [[case]] name = "managed_shim_preserves_system_node_path" vp = "global" diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots/managed_node_precedes_later_node_path.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots/managed_node_precedes_later_node_path.md new file mode 100644 index 0000000000..5af0173619 --- /dev/null +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots/managed_node_precedes_later_node_path.md @@ -0,0 +1,7 @@ +# managed_node_precedes_later_node_path + +## `node verify.mjs managed-node-later` + +``` +managed-node-later: selected Node and original PATH precedence preserved +``` diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs index a1598951c1..7a53e1e71d 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs @@ -1,6 +1,6 @@ import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; -import { chmodSync, mkdirSync, writeFileSync, symlinkSync } from 'node:fs'; +import { chmodSync, existsSync, mkdirSync, writeFileSync, symlinkSync } from 'node:fs'; import { delimiter, join } from 'node:path'; const scenario = process.argv[2]; @@ -51,7 +51,23 @@ function run(args) { } run(['env', 'off', 'node']); run(['env', 'off', 'pm']); -if (scenario === 'system-pm') { +if (scenario === 'managed-node-later') { + // The selected managed Node.js is already on PATH, but after another Node.js. + // The runner seeds `js_runtime` read-mostly, so reuse the runtime running this script. + const managedNode = join(process.env.VP_HOME, 'js_runtime/node', process.versions.node, 'bin'); + assert.ok(existsSync(join(managedNode, 'node')), `missing seeded runtime in ${managedNode}`); + const otherNode = join(root, 'other-node-bin'); + mkdirSync(otherNode); + executable(join(otherNode, 'node'), '#!/bin/sh\necho shadowed-by-other-node\nexit 1\n'); + writeFileSync('.nvmrc', `${process.versions.node}\n`); + run(['env', 'on', 'node']); + const result = spawnSync('vp', ['install'], { + env: { ...env, PATH: [otherNode, managedNode, env.PATH].join(delimiter) }, + encoding: 'utf8', + }); + assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`); + assert.match(result.stdout, /selected Node and original PATH precedence preserved/); +} else if (scenario === 'system-pm') { assert.match(run(['install']), /selected Node and original PATH precedence preserved/); run(['env', 'on', 'node']); assert.match(run(['install']), /selected Node and original PATH precedence preserved/); From ead2720a82961457d3b755bf5f21f7d794513af8 Mon Sep 17 00:00:00 2001 From: naokihaba <59875779+naokihaba@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:51:24 +0900 Subject: [PATCH 3/3] test(cli): resolve the managed Node.js directory through vp env current --- .../fixtures/system_first_path/verify.mjs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs index 7a53e1e71d..8b1bf973ca 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs @@ -1,7 +1,7 @@ import assert from 'node:assert/strict'; import { spawnSync } from 'node:child_process'; -import { chmodSync, existsSync, mkdirSync, writeFileSync, symlinkSync } from 'node:fs'; -import { delimiter, join } from 'node:path'; +import { chmodSync, mkdirSync, writeFileSync, symlinkSync } from 'node:fs'; +import { delimiter, dirname, join } from 'node:path'; const scenario = process.argv[2]; const root = process.cwd(); @@ -53,14 +53,16 @@ run(['env', 'off', 'node']); run(['env', 'off', 'pm']); if (scenario === 'managed-node-later') { // The selected managed Node.js is already on PATH, but after another Node.js. - // The runner seeds `js_runtime` read-mostly, so reuse the runtime running this script. - const managedNode = join(process.env.VP_HOME, 'js_runtime/node', process.versions.node, 'bin'); - assert.ok(existsSync(join(managedNode, 'node')), `missing seeded runtime in ${managedNode}`); + // Pin the seeded runtime that runs this script, and let Vite+ resolve its location. + writeFileSync('.nvmrc', `${process.versions.node}\n`); + run(['env', 'on', 'node']); + const { node } = JSON.parse(run(['env', 'current', '--json'])); + assert.equal(node.mode, 'managed'); + assert.ok(node.installed, `missing seeded runtime ${node.bin_path}`); + const managedNode = dirname(node.bin_path); const otherNode = join(root, 'other-node-bin'); mkdirSync(otherNode); executable(join(otherNode, 'node'), '#!/bin/sh\necho shadowed-by-other-node\nexit 1\n'); - writeFileSync('.nvmrc', `${process.versions.node}\n`); - run(['env', 'on', 'node']); const result = spawnSync('vp', ['install'], { env: { ...env, PATH: [otherNode, managedNode, env.PATH].join(delimiter) }, encoding: 'utf8',