Skip to content
Closed
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0213e0b
run: shim npm/npx alongside node in the --bun PATH dir
robobun Jul 24, 2026
0ea0f32
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 24, 2026
478b40e
address review: fallback-only npm shim, map npm exec/init, translate …
robobun Jul 25, 2026
9b0a189
npm shim: pass publish/version flags through, map npm version
robobun Jul 25, 2026
84fe62f
[autofix.ci] apply automated fixes
autofix-ci[bot] Jul 25, 2026
cef8bf7
npm shim: filter npx config flags, map npm pack, fix hoisted flag pla…
robobun Jul 25, 2026
3d0099e
npm shim: map upgrade/cache/c, apply keep list before the subcommand,…
robobun Jul 25, 2026
f525298
npm shim: delete stale Windows npm/npx hardlinks, decide init vs crea…
robobun Jul 25, 2026
de1eaca
npm shim: rename stale Windows shim links when deletion is denied
robobun Jul 25, 2026
f72a0ea
npm shim: ignore own shim in the PATH probe, gate --workspace rename …
robobun Jul 25, 2026
e7dc0f9
npm shim: map the subcommand after a leading --, gate the stale-link …
robobun Jul 25, 2026
24b83df
npm shim: handle short save aliases, missing config flags, and create…
robobun Jul 25, 2026
f5164f9
npm shim: remove comment blocks flagged by review
robobun Jul 25, 2026
16e9d8b
npm shim: drop remaining flagged doc comments
robobun Jul 25, 2026
2105f8b
npm shim: pass npx --package and its value through the flag filter
robobun Jul 25, 2026
a2666db
npm shim: hoist npm config flags appearing after the script name
robobun Jul 25, 2026
ec433e1
npm shim: consume unknown config flag values in the run mapping
robobun Jul 25, 2026
ed8da95
npm shim: do not pair boolean npm flags with the following token
robobun Jul 25, 2026
466c7fa
npm shim: drop flagged comment
robobun Jul 25, 2026
fe7751a
npm shim: cover remaining npm booleans, pre-subcommand flags, and ven…
robobun Jul 25, 2026
4de95c8
npm shim: drain pre-subcommand flags for bunx/pm mappings, drop colli…
robobun Jul 25, 2026
ada11e3
npm shim: filter the bunx-mapped tail too
robobun Jul 25, 2026
564ecc1
npm shim: close the -dd/-l/-m shorthand gaps
robobun Jul 25, 2026
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
12 changes: 8 additions & 4 deletions src/install/PackageManager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,12 +1083,16 @@ fn configure_env_for_scripts_run(
.load_node_js_config(paths_fs, node_path_z.as_ref())?;
} else {
'brk: {
let current_path = this.env().get(b"PATH").unwrap_or(b"");
let current_path: Vec<u8> = this.env().get(b"PATH").unwrap_or(b"").to_vec();
let mut path_var: Vec<u8> = Vec::with_capacity(current_path.len());
path_var.extend_from_slice(current_path);
path_var.extend_from_slice(&current_path);
let mut bun_path: &[u8] = b"";
if RunCommand::create_fake_temporary_node_executable(&mut path_var, &mut bun_path)
.is_err()
if RunCommand::create_fake_temporary_node_executable(
&mut path_var,
&mut bun_path,
&current_path,
)
.is_err()
{
break 'brk;
}
Expand Down
101 changes: 99 additions & 2 deletions src/install/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ impl RunCommand {
pub fn create_fake_temporary_node_executable(
path: &mut Vec<u8>,
optional_bun_path: &mut &[u8],
original_path: &[u8],
) -> Result<(), crate::Error> {
// If we are already running as "node", the path should exist
if PRETEND_TO_BE_NODE.load(core::sync::atomic::Ordering::Relaxed) {
Expand Down Expand Up @@ -593,6 +594,16 @@ impl RunCommand {
// SAFETY: literal ends in NUL; len excludes it.
ZStr::from_static(B)
};
const NPM_LINK: &ZStr = {
const B: &[u8] = concatcp!(RunCommand::BUN_NODE_DIR, "/npm\0").as_bytes();
// SAFETY: literal ends in NUL; len excludes it.
ZStr::from_static(B)
};
const NPX_LINK: &ZStr = {
const B: &[u8] = concatcp!(RunCommand::BUN_NODE_DIR, "/npx\0").as_bytes();
// SAFETY: literal ends in NUL; len excludes it.
ZStr::from_static(B)
};
const DIR_Z: &ZStr = {
const B: &[u8] = concatcp!(RunCommand::BUN_NODE_DIR, "\0").as_bytes();
// SAFETY: literal ends in NUL; len excludes it.
Expand All @@ -616,7 +627,25 @@ impl RunCommand {
Err(_) => return Ok(()),
}

for dest in [NODE_LINK, BUN_LINK] {
let mut which_buf = bun_paths::PathBuffer::uninit();
let mut real_in_path = |bin: &[u8]| -> bool {
bun_which::which(&mut which_buf, original_path, b".", bin).is_some_and(|p| {
!bun_core::strings::starts_with(p.as_bytes(), Self::BUN_NODE_DIR.as_bytes())
})
};
let need_npm = !real_in_path(b"npm");
let need_npx = !real_in_path(b"npx");

for (dest, wanted) in [
(NODE_LINK, true),
(BUN_LINK, true),
(NPM_LINK, need_npm),
(NPX_LINK, need_npx),
] {
if !wanted {
let _ = bun_sys::unlink(dest);
continue;
}
Comment thread
robobun marked this conversation as resolved.
Resolved
Comment thread
robobun marked this conversation as resolved.
Resolved
let mut replaced = false;
loop {
match bun_sys::symlink(argv0_z, dest) {
Expand Down Expand Up @@ -720,8 +749,76 @@ impl RunCommand {
let _ = bun_sys::Dir::cwd().make_dir(&dir_slice_u8);
}

let mut which_buf = bun_paths::PathBuffer::uninit();
let shim_dir_utf8 = bun_core::strings::to_utf8_alloc_with_type(
&target_path_buffer[prefix.len()..dir_slice_len],
);
let mut real_in_path = |bin: &[u8]| -> bool {
bun_which::which(&mut which_buf, original_path, b".", bin).is_some_and(|p| {
let pb = p.as_bytes();
!(pb.len() >= shim_dir_utf8.len()
&& strings::eql_case_insensitive_asciii_check_length(
&pb[..shim_dir_utf8.len()],
&shim_dir_utf8,
))
})
};
let need_npm = !real_in_path(b"npm");
let need_npx = !real_in_path(b"npx");
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

let image_path = win::exe_path_w();
for name in [strings::w!("\\node.exe\0"), strings::w!("\\bun.exe\0")] {
for (name, stale_name, wanted) in [
(
strings::w!("\\node.exe\0"),
strings::w!("\\node.exe.stale\0"),
true,
),
(
strings::w!("\\bun.exe\0"),
strings::w!("\\bun.exe.stale\0"),
true,
),
(
strings::w!("\\npm.exe\0"),
strings::w!("\\npm.exe.stale\0"),
need_npm,
),
(
strings::w!("\\npx.exe\0"),
strings::w!("\\npx.exe.stale\0"),
need_npx,
),
] {
if !wanted {
target_path_buffer[dir_slice_len..][..name.len()].copy_from_slice(name);
// SAFETY: `name` ends in NUL, so the written path is
// NUL-terminated.
let path_w = bun_core::WStr::from_buf(
&target_path_buffer[..],
dir_slice_len + name.len() - 1,
);
if let Err(e) = bun_sys::unlink_w(path_w)
&& matches!(
e.get_errno(),
bun_sys::E::EPERM | bun_sys::E::EACCES | bun_sys::E::EBUSY
)
{
let mut stale_buf = bun_paths::w_path_buffer_pool::get();
stale_buf[..dir_slice_len]
.copy_from_slice(&target_path_buffer[..dir_slice_len]);
stale_buf[dir_slice_len..][..stale_name.len()].copy_from_slice(stale_name);
// SAFETY: both paths are NUL-terminated (the name
// literals end in NUL).
let _ = unsafe {
win::kernel32::MoveFileExW(
target_path_buffer.as_ptr(),
stale_buf.as_ptr(),
win::MOVEFILE_REPLACE_EXISTING,
)
};
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
continue;
}
Comment thread
robobun marked this conversation as resolved.
Resolved
target_path_buffer[dir_slice_len..][..name.len()].copy_from_slice(name);
// `target_path_buffer` is mutated in place between FFI calls
// (the dir-NUL/backslash toggle below).
Expand Down
Loading
Loading