From e6f443df7620bc0ed9e606bf47e6b19af20c2fa2 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Wed, 25 Nov 2026 10:22:23 +0100 Subject: [PATCH] fix(pm): ignore an inherited `npm_config_package` in npm commands `npx --package=vite-plus vp ...` exports `npm_config_package=vite-plus`. With npm as the package manager, `vp dlx ` then runs `npm exec --yes -- `, and npm reads the inherited package list: it installs `vite-plus` and runs `` as a command, failing with `sh: : command not found`. `vp migrate` hits this in its ESLint step, which runs `vp dlx @oxlint/migrate@`. Set `npm_config_package` to an empty value for npm and npx commands, which npm 7 to 11 treat as no packages. npm 6's npx ignores the variable. Refs #2970 --- .../fixtures/command_dlx_npm10/snapshots.toml | 1 + .../command_dlx_npm10/snapshots/command_dlx_npm10.md | 8 ++++++++ crates/vp_pm_cli/src/resolution/command.rs | 3 +++ crates/vp_pm_cli/src/resolution/commands/dlx.rs | 10 ++++++++++ 4 files changed, 22 insertions(+) diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots.toml b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots.toml index 3f5ae84dc6..b7545fedf2 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots.toml +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots.toml @@ -8,6 +8,7 @@ steps = [ { argv = ["vp", "dlx", "--help"], comment = "should show help message", continue-on-failure = true }, { argv = ["vp", "dlx", "-s", "vp-test-echo", "hello"], comment = "should run vp-test-echo with npm exec", continue-on-failure = true }, { argv = ["vp", "dlx", "-s", "vp-test-echo@1.0.0", "hello"], comment = "should run specific version", continue-on-failure = true }, + { argv = ["vp", "dlx", "-s", "vp-test-echo@1.0.0", "hello"], envs = [["npm_config_package", "vp-test-upper"]], comment = "should ignore `npm_config_package` from an outer `npx --package`", continue-on-failure = true }, { argv = ["vp", "dlx", "-s", "@vp-test/cli@npm:vp-test-echo@1.0.0", "hello"], comment = "npm selects the binary rather than using the scoped alias name" }, { argv = ["vp", "dlx", "-s", "-p", "vp-test-echo", "-p", "vp-test-upper", "vp-test-echo", "hello"], comment = "should run with multiple packages", continue-on-failure = true }, { argv = ["vp", "dlx", "-s", "-p", "vp-test-echo", "-p", "vp-test-upper", "-c", "echo hello-from-shell | vp-test-echo | vp-test-upper"], comment = "should run shell mode command (vp's own shell handles the pipe)", continue-on-failure = true }, diff --git a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots/command_dlx_npm10.md b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots/command_dlx_npm10.md index 33ec004772..7ab4c3abbe 100644 --- a/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots/command_dlx_npm10.md +++ b/crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/command_dlx_npm10/snapshots/command_dlx_npm10.md @@ -39,6 +39,14 @@ should run specific version hello ``` +## `npm_config_package=vp-test-upper vp dlx -s vp-test-echo@1.0.0 hello` + +should ignore `npm_config_package` from an outer `npx --package` + +``` +hello +``` + ## `vp dlx -s @vp-test/cli@npm:vp-test-echo@1.0.0 hello` npm selects the binary rather than using the scoped alias name diff --git a/crates/vp_pm_cli/src/resolution/command.rs b/crates/vp_pm_cli/src/resolution/command.rs index c81e8188f6..1e1c8aed89 100644 --- a/crates/vp_pm_cli/src/resolution/command.rs +++ b/crates/vp_pm_cli/src/resolution/command.rs @@ -22,6 +22,9 @@ impl ResolvedCommand { if matches!(program.as_str(), "npm" | "npx") { // Include npm/npx fallbacks: Vite+ manages their versions too. env.insert("npm_config_update_notifier".to_string(), "false".to_string()); + // `npx --package=vite-plus vp ...` exports `npm_config_package`. If inherited, + // `npm exec -- ` runs `` as a bin of that package instead. + env.insert("npm_config_package".to_string(), String::new()); } Self { program, args: Vec::new(), env, pre_run: Vec::new() } } diff --git a/crates/vp_pm_cli/src/resolution/commands/dlx.rs b/crates/vp_pm_cli/src/resolution/commands/dlx.rs index d7fc4d0df0..a933892a4b 100644 --- a/crates/vp_pm_cli/src/resolution/commands/dlx.rs +++ b/crates/vp_pm_cli/src/resolution/commands/dlx.rs @@ -392,6 +392,16 @@ mod tests { assert_eq!(command.args, vec!["exec", "--yes", "--", "@angular/cli", "--version"]); } + #[test] + fn test_npm_clears_inherited_package_config() { + for version in ["6.14.18", "11.0.0"] { + let command = + expect_run(resolve(&npm(version), dlx_args("vp-test-echo@1.0.0", &[])).outcome); + + assert_eq!(command.env.get("npm_config_package").map(String::as_str), Some("")); + } + } + #[test] fn test_yarn_v1_fallback_to_npx() { let resolution = resolve(&yarn("1.22.19"), dlx_args("create-vue", &["my-app"]));