Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "shim-bun-runs-node-child",
"private": true,
"scripts": {
"node-child": "node -v"
Comment thread
BlankParticle marked this conversation as resolved.
Outdated
},
"engines": {
"node": "22.12.0"
},
"packageManager": "bun@1.3.11"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[case]]
name = "shim_bun_runs_node_child"
vp = "global"
skip-platforms = ["windows"]
Comment thread
BlankParticle marked this conversation as resolved.
Outdated
steps = [
{ argv = ["vp", "install", "-g", "bun"], snapshot = false },
{ argv = ["bun", "run", "node-child"], comment = "Bun scripts can invoke the managed Node runtime" },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# shim_bun_runs_node_child

## `vp install -g bun`


## `bun run node-child`

Bun scripts can invoke the managed Node runtime

```
$ node -v
<version>
```
92 changes: 43 additions & 49 deletions crates/vite_global_cli/src/shim/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,66 +954,60 @@ 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) {
let cwd = match current_dir() {
Ok(path) => path,
Err(e) => {
eprintln!("vp: Failed to get current directory: {e}");
return 1;
}
};
let cwd = match current_dir() {
Comment thread
BlankParticle marked this conversation as resolved.
Outdated
Comment thread
BlankParticle marked this conversation as resolved.
Outdated
Ok(path) => path,
Err(e) => {
eprintln!("vp: Failed to get current directory: {e}");
return 1;
}
};

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(),
},
};
match resolve_matching_package_manager_tool(&cwd, tool).await {
Ok(Some(tool_path)) => {
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;
}
}
}
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;
}
}
}

if let Some(pm_bin_dir) = tool_path.parent() {
let _ = prepend_to_path_env(pm_bin_dir, PrependOptions::default());
}

// SAFETY: Setting env vars at this point before exec is safe
unsafe {
std::env::set_var(RECURSION_ENV_VAR, "1");
}
return exec::exec_tool(&tool_path, args);
if let Some(pm_bin_dir) = tool_path.parent() {
let _ = prepend_to_path_env(pm_bin_dir, PrependOptions::default());
}
Ok(None) => {}
Err(e) => {
eprintln!("vp: Failed to resolve package manager for '{tool}': {e}");
return 1;

// SAFETY: Setting env vars at this point before exec is safe
unsafe {
std::env::set_var(RECURSION_ENV_VAR, "1");
}
return exec::exec_tool(&tool_path, args);
}
Ok(None) => {}
Err(e) => {
eprintln!("vp: Failed to resolve package manager for '{tool}': {e}");
return 1;
}
}

Expand Down