From 5957cc6a305a3cd1c2a4e3d01d8c08dfce1d148f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 2 Dec 2026 16:44:51 +0100 Subject: [PATCH 1/2] fix(build): find npm when only npm.exe exists on Windows On Windows, build.rs and cargo xtask always spawned `npm.cmd`. A Node install without that shim, like the nvm v2 one on a contributor machine that ships only `npm.exe`, failed with "program not found": `cargo build` stopped in build.rs, and `cargo xtask ci` stopped at its UI test step. SKIP_UI_BUILD=1 got past build.rs only. Use `npm.cmd` when a directory on PATH has it, and plain `npm` otherwise (which resolves to `npm.exe`). Installs that ship the `.cmd` shim, as on GitHub's Windows runners (unverified), keep the same behavior. build.rs cannot share code with xtask, so the small lookup exists in both; housekeeping.rs reuses the xtask one. Verified on the affected machine: `cargo build -p braid` without SKIP_UI_BUILD reran `npm ci` and the vite build and finished. The xtask copy was not run with an npm.exe-only install. --- crates/braid/build.rs | 9 ++++++++- crates/xtask/src/housekeeping.rs | 3 +-- crates/xtask/src/main.rs | 13 ++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/braid/build.rs b/crates/braid/build.rs index b3f3078..add2ec8 100644 --- a/crates/braid/build.rs +++ b/crates/braid/build.rs @@ -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" } } diff --git a/crates/xtask/src/housekeeping.rs b/crates/xtask/src/housekeeping.rs index ff88325..888a2c5 100644 --- a/crates/xtask/src/housekeeping.rs +++ b/crates/xtask/src/housekeeping.rs @@ -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"), }; diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index 9dcc89a..34a238e 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -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 ` 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(); @@ -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() { From 038a5ebf6b4a939a34c47980926af633fcd34e93 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 2 Dec 2026 16:51:38 +0100 Subject: [PATCH 2/2] style: apply rustfmt --- crates/xtask/src/housekeeping.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/xtask/src/housekeeping.rs b/crates/xtask/src/housekeeping.rs index 888a2c5..0eb2c58 100644 --- a/crates/xtask/src/housekeeping.rs +++ b/crates/xtask/src/housekeeping.rs @@ -799,7 +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 out = match tool(crate::npm_program(),&[subcommand], &ui) { + let out = match tool(crate::npm_program(), &[subcommand], &ui) { Ok(out) => out, Err(_) => return Outcome::skipped("needs Node.js / npm"), };