diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/package.json b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/package.json new file mode 100644 index 0000000000..a3554c0ab7 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/package.json @@ -0,0 +1,11 @@ +{ + "name": "shim-bun-runs-node-child", + "private": true, + "scripts": { + "node-child": "node -e \"if (process.version !== 'v22.12.0') process.exit(1)\"" + }, + "engines": { + "node": "22.12.0" + }, + "packageManager": "bun@1.3.11" +} diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots.toml b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots.toml new file mode 100644 index 0000000000..ece3ed0476 --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots.toml @@ -0,0 +1,7 @@ +[[case]] +name = "shim_bun_runs_node_child" +vp = "global" +steps = [ + { argv = ["vp", "install", "-g", "bun"], snapshot = false }, + { argv = ["bun", "run", "node-child"], comment = "Bun scripts can invoke the managed Node runtime" }, +] diff --git a/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots/shim_bun_runs_node_child.md b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots/shim_bun_runs_node_child.md new file mode 100644 index 0000000000..3867dadb4c --- /dev/null +++ b/crates/vite_cli_snapshots/tests/cli_snapshots/fixtures/shim_bun_runs_node_child/snapshots/shim_bun_runs_node_child.md @@ -0,0 +1,12 @@ +# shim_bun_runs_node_child + +## `vp install -g bun` + + +## `bun run node-child` + +Bun scripts can invoke the managed Node runtime + +``` +$ node -e "if (process.version !== '') process.exit(1)" +``` diff --git a/crates/vite_global_cli/src/shim/dispatch.rs b/crates/vite_global_cli/src/shim/dispatch.rs index 47776f7a31..18d608aedd 100644 --- a/crates/vite_global_cli/src/shim/dispatch.rs +++ b/crates/vite_global_cli/src/shim/dispatch.rs @@ -954,7 +954,7 @@ pub async fn dispatch(tool: &str, args: &[String]) -> i32 { /// Finds the package that provides this binary and executes it with the /// Node.js version that was used to install the package. async fn dispatch_package_binary(tool: &str, args: &[String]) -> i32 { - if let Some(pm_family) = PackageManagerType::from_tool(tool) { + if PackageManagerType::from_tool(tool).is_some() { let cwd = match current_dir() { Ok(path) => path, Err(e) => { @@ -965,36 +965,32 @@ async fn dispatch_package_binary(tool: &str, args: &[String]) -> i32 { match resolve_matching_package_manager_tool(&cwd, tool).await { Ok(Some(tool_path)) => { - // Bun is a native binary and does not need a Node.js runtime on PATH; - // JS-based PMs (npm/pnpm/yarn) do. - if pm_family != PackageManagerType::Bun { - let node_version = match resolve_with_cache(&cwd).await { - Ok(resolution) => resolution.version, - Err(_) => match find_package_for_binary(tool).await { - Ok(Some(metadata)) => metadata.platform.node, - _ => String::new(), - }, - }; + let node_version = match resolve_with_cache(&cwd).await { + Ok(resolution) => resolution.version, + Err(_) => match find_package_for_binary(tool).await { + Ok(Some(metadata)) => metadata.platform.node, + _ => String::new(), + }, + }; - if !node_version.is_empty() { - match ensure_installed(&node_version).await { - Ok(node_path) => { - if let Some(node_bin_dir) = node_path.parent() { - if let Err(e) = - prepend_js_child_process_path_env(&cwd, node_bin_dir).await - { - eprintln!( - "vp: Failed to resolve package manager for child \ + if !node_version.is_empty() { + match ensure_installed(&node_version).await { + Ok(node_path) => { + if let Some(node_bin_dir) = node_path.parent() { + if let Err(e) = + prepend_js_child_process_path_env(&cwd, node_bin_dir).await + { + eprintln!( + "vp: Failed to resolve package manager for child \ process PATH: {e}" - ); - return 1; - } + ); + return 1; } } - Err(e) => { - eprintln!("vp: Failed to install Node {}: {e}", node_version); - return 1; - } + } + Err(e) => { + eprintln!("vp: Failed to install Node {}: {e}", node_version); + return 1; } } }