From 9ad439d16e797d04804b5d80706fd0e86041b161 Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Tue, 15 Jul 2025 15:35:22 -0400 Subject: Prevent race conditions between `cargo run` and `npx vite build` in `tools/run`. To reproduce: * Make any change (even just `touch`) to a file in `ui`. * Run `tools/run`. There's a decent chance that the script will fail, with esoteric and variable errors: ``` failed to load config from .../pilcrow/vite.config.js_api(buil... error when starting dev server: Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@sveltejs/kit' imported from .../pilcrow/vite.config.js.timestamp-1752608239248-52b6b8965ad28.mjs ``` is one such exmple. These errors are due to the `npm ci` carried out by `cargo` at build time (see `build.rs`), which deletes and re-creates `node_modules`. Vite and Svelte do not like having `node_modules` deleted out from under them. As `cargo` will rerun `build.rs` any time `ui` changes, this means that `tools/run` effectively requires a complete build _first_, before it can be run. --- tools/run | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tools/run') diff --git a/tools/run b/tools/run index 8560c31..04ae2d8 100755 --- a/tools/run +++ b/tools/run @@ -5,8 +5,12 @@ ## Runs the service, and runs a development version of the UI, with hot ## reloading and live code changes enabled. -PIDS=() +# Stop `cargo run` and `npx vite dev` from racing with each other with +# respect to the build output by forcing a build _first_, while neither +# is running. +cargo build +PIDS=() trap 'kill "${PIDS[@]}"' EXIT cargo run & -- cgit v1.2.3