Skip to content

Commit e4fc21d

Browse files
committed
fix(env): propagate explicit exec versions to package manager shims
1 parent 22798ab commit e4fc21d

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/shim_injected_tool_contracts/snapshots.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,12 @@ steps = [
160160
{ argv = ["vp", "env", "on", "npm"], snapshot = false },
161161
{ argv = ["vp", "env", "exec", "--node", "22.18.0", "node", "assert-unix-shim-path.cjs", "partial", "10.5.0"], comment = "A project npm pin still takes priority over bundled npm after a PATH reset" },
162162
]
163+
164+
[[case]]
165+
name = "explicit_npm_after_partial_path_reset"
166+
vp = "global"
167+
skip-platforms = ["windows"]
168+
env = { VP_NPM_VERSION = "10.9.4" }
169+
steps = [
170+
{ argv = ["vp", "env", "exec", "--node", "22.18.0", "--npm", "10.5.0", "node", "assert-unix-shim-path.cjs", "partial", "10.5.0"], comment = "An explicit npm version overrides the inherited version and survives a PATH reset" },
171+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# explicit_npm_after_partial_path_reset
2+
3+
## `vp env exec --node 22.18.0 --npm 10.5.0 node assert-unix-shim-path.cjs partial 10.5.0`
4+
5+
An explicit npm version overrides the inherited version and survives a PATH reset
6+
7+
```
8+
Node and its tools survive partial PATH
9+
```

crates/vp_global_cli/src/commands/env/exec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ async fn execute_with_version(
226226
let mut child = tokio::process::Command::new(cmd);
227227
child.args(args).envs(child_env.into_envs()).env(env_vars::VP_NODE_VERSION, &resolved_node);
228228
if let Some(package_manager) = resolved_package_manager {
229+
if explicit_package_manager {
230+
// Preserve explicit versions when a child removes the injected tool directory from PATH.
231+
let (kind, version, _) = parse_package_manager_spec_with_hash(&package_manager)?;
232+
child.env(package_manager_resolution::version_env_var(kind), version);
233+
}
229234
child.env(env_vars::VP_PACKAGE_MANAGER, package_manager);
230235
}
231236
// The child runs in the inherited cwd, which a leading `-C <dir>` changes

0 commit comments

Comments
 (0)