From a3bdf90237889e9194c49f6f7f2716843521a255 Mon Sep 17 00:00:00 2001 From: Bossiara13 <236771060+DmitryBykov-ISPO@users.noreply.github.com> Date: Fri, 15 May 2026 13:18:08 +0300 Subject: [PATCH] build(gui): build.rs auto-runs npm run build, no more stale frontend bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reproduction: cargo build --release -p jarvis-gui # before this commit → Tauri'\''s generate_context!() reads frontend/dist/client which is whatever the user (or me) last built, possibly hours ago. Result: new release exe ships with stale UI. Caught when /commands page kept rendering the placeholder after the new code was committed and the binary was rebuilt — because dist/ was generated before the Svelte file was rewritten. Fix: build.rs now invokes `npm run build` in frontend/ on every relink, and emits cargo:rerun-if-changed for frontend/src and package.json so cargo also reruns build.rs when Svelte/TS sources change. `cargo tauri build` still works (it runs npm twice, which is wasteful but harmless). If npm is not installed (unlikely but possible on a Rust-only CI), prints a cargo warning and bundles whatever dist is on disk. `dist` stays in frontend/.gitignore — this just makes sure a local working copy always has a fresh dist before Tauri picks it up. --- crates/jarvis-gui/build.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/crates/jarvis-gui/build.rs b/crates/jarvis-gui/build.rs index 765a6f3..0531b18 100644 --- a/crates/jarvis-gui/build.rs +++ b/crates/jarvis-gui/build.rs @@ -1,9 +1,40 @@ fn main() { let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let lib_path = std::path::Path::new(&manifest_dir) - .join("..\\..\\lib\\windows\\amd64"); + let manifest_path = std::path::Path::new(&manifest_dir); + let lib_path = manifest_path.join("..\\..\\lib\\windows\\amd64"); println!("cargo:rustc-link-search=native={}", lib_path.display()); + // Vite outputs the Svelte bundle into ../../frontend/dist/client. If the + // user runs a bare `cargo build -p jarvis-gui` without going through + // `cargo tauri build`, the beforeBuildCommand in tauri.conf.json never + // fires and the new release exe ends up bundling whatever stale dist is + // sitting on disk — including UI states from days ago. Force a rebuild + // here when any Svelte / TS source under frontend/src changes. + let frontend = manifest_path.join("..\\..\\frontend"); + let src = frontend.join("src"); + if src.is_dir() { + println!("cargo:rerun-if-changed={}", src.display()); + println!("cargo:rerun-if-changed={}", frontend.join("package.json").display()); + + let npm = if cfg!(target_os = "windows") { "npm.cmd" } else { "npm" }; + let status = std::process::Command::new(npm) + .arg("run") + .arg("build") + .current_dir(&frontend) + .status(); + match status { + Ok(s) if s.success() => { + println!("cargo:warning=jarvis-gui: frontend rebuilt via npm run build"); + } + Ok(s) => { + println!("cargo:warning=jarvis-gui: npm run build exited with {}", s); + } + Err(e) => { + println!("cargo:warning=jarvis-gui: npm not found ({}). Bundling existing dist; run `npm install && npm run build` in frontend/ if the UI looks stale.", e); + } + } + } + tauri_build::build() }