Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 -e \"if (process.version !== 'v22.12.0') process.exit(1)\""
},
"engines": {
"node": "22.12.0"
},
"packageManager": "bun@1.3.11"
}
Original file line number Diff line number Diff line change
@@ -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" },
]
Original file line number Diff line number Diff line change
@@ -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 !== '<version>') process.exit(1)"
```
50 changes: 23 additions & 27 deletions crates/vite_global_cli/src/shim/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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;
Comment thread
BlankParticle marked this conversation as resolved.
}
}
}
Expand Down