Skip to content
Merged
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
9 changes: 8 additions & 1 deletion crates/braid/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ fn ensure_stub(dist: &Path) {
.expect("could not write ui/dist/index.html stub");
}

/// The npm executable to spawn. Rust's `Command` only appends `.exe` on
/// Windows, so the usual `npm.cmd` shim must be named in full; installs that
/// ship a real `npm.exe` instead (nvm) are found by the plain name.
fn npm_cmd() -> &'static str {
if cfg!(windows) { "npm.cmd" } else { "npm" }
let on_path = |name: &str| {
std::env::var_os("PATH")
.is_some_and(|path| std::env::split_paths(&path).any(|dir| dir.join(name).is_file()))
};
if cfg!(windows) && on_path("npm.cmd") { "npm.cmd" } else { "npm" }
}
3 changes: 1 addition & 2 deletions crates/xtask/src/housekeeping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,8 +799,7 @@ fn check_npm(root: &Path, options: &Options, subcommand: &str) -> Outcome {
if !ui.join("package.json").is_file() {
return Outcome::skipped("no ui/package.json");
}
let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };
let out = match tool(npm, &[subcommand], &ui) {
let out = match tool(crate::npm_program(), &[subcommand], &ui) {
Ok(out) => out,
Err(_) => return Outcome::skipped("needs Node.js / npm"),
};
Expand Down
13 changes: 12 additions & 1 deletion crates/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,17 @@ fn run_steps(steps: &[&[&str]]) -> i32 {
// build-ui / test-ui
// ---------------------------------------------------------------------------

/// The npm executable to spawn. Rust's `Command` only appends `.exe` on
/// Windows, so the usual `npm.cmd` shim must be named in full; installs that
/// ship a real `npm.exe` instead (nvm) are found by the plain name.
fn npm_program() -> &'static str {
let on_path = |name: &str| {
std::env::var_os("PATH")
.is_some_and(|path| std::env::split_paths(&path).any(|dir| dir.join(name).is_file()))
};
if cfg!(windows) && on_path("npm.cmd") { "npm.cmd" } else { "npm" }
}

/// Run `npm <args>` in `ui/`, returning a process-style exit code.
fn ui_npm(args: &[&str]) -> i32 {
let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
Expand All @@ -134,7 +145,7 @@ fn ui_npm(args: &[&str]) -> i32 {
return 1;
}
};
let npm = if cfg!(windows) { "npm.cmd" } else { "npm" };
let npm = npm_program();
let pretty = format!("npm {}", args.join(" "));
eprintln!("xtask: {pretty} (in {})", ui_dir.display());
match Command::new(npm).args(args).current_dir(&ui_dir).status() {
Expand Down
Loading