diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-07-15 15:35:22 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-07-15 15:35:22 -0400 |
| commit | 9ad439d16e797d04804b5d80706fd0e86041b161 (patch) | |
| tree | 8081bc6224db1bd5c4cd36f451dd68cce0ea3a0f | |
| parent | f74b82450aa15b3e3e47617839c297cd1d60780e (diff) | |
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.
| -rwxr-xr-x | tools/run | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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 & |
