Skip to content

fix: fail the build with instructions when compiled front-end assets are missing - #404

Merged
dubadub merged 1 commit into
mainfrom
fix/233-missing-frontend-assets-guard
Aug 7, 2026
Merged

dubadub merged 1 commit into
mainfrom
fix/233-missing-frontend-assets-guard

Conversation

@dubadub

@dubadub dubadub commented Aug 7, 2026

Copy link
Copy Markdown
Member

Problem (#233)

static/css/output.css and static/js/editor.bundle.js are generated by npm and gitignored. rust-embed does not fail when files are absent from static/ — it silently embeds nothing — so any build from git source produces a binary whose web UI (cook server, cook build web) renders unstyled pages:

  • Arch pacman -S cookcli builds from the GitHub tag tarball, which never contains gitignored files (verified: v0.32.1.tar.gz has neither asset).
  • git clone + cargo build without the npm steps reproduces it on current main (the "fresh cargo build today" report).
  • crates.io was broken in 0.19.3 but is fine now — the publish job builds the assets first, and the published 0.32.1 package contains both files.

Fix

A build.rs guard fails compilation with actionable instructions when either asset is missing:

error: missing compiled front-end assets:
  - static/css/output.css  (generate with: npm run build-css)
  - static/js/editor.bundle.js  (generate with: npm run build-js)

These files are generated and not checked into git, so they are absent
from git clones and source tarballs. Building them requires Node.js:
...

The cargo:rerun-if-changed lines also mean editing/creating the compiled assets correctly triggers a rebuild of the embedded files.

Also:

  • Reorders the Playwright CI job to run npm run build-css/build-js before cargo build (the only CI spot that built cargo first).
  • Adds /build.rs to the include list so the published crate carries it (verified via cargo package --list).
  • Documents npm run build-js in the README build-from-source steps.

Verification

  • Red: moved both assets away → cargo check fails with the message above.
  • Green: restored → builds clean.
  • cargo fmt, cargo clippy --all-targets --all-features (no warnings), cargo test (all pass).

Closes #233

…are missing

output.css and editor.bundle.js are generated by npm and gitignored, so
builds from git clones and source tarballs (e.g. the Arch package) ship
binaries whose web UI renders unstyled pages - rust-embed silently
embeds nothing when the files are absent. A build.rs guard now fails
compilation with instructions to run the npm builds (or install from
crates.io, whose package ships the assets prebuilt).

Also reorders the Playwright CI job to build CSS/JS before cargo build,
ships build.rs in the crates.io package, and documents npm run build-js
in the README build-from-source steps.

Closes #233
@claude

claude Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review

Reviewed the diff (build.rs, Cargo.toml, .github/workflows/test.yml, README.md). Overall this is a clean, well-scoped fix — verified several claims directly against the repo rather than taking the PR description at face value.

Verified correct:

  • The asset paths in build.rs (static/css/output.css, static/js/editor.bundle.js) match both the npm run build-css/build-js script outputs in package.json and the #[folder = "static/"] RustEmbed target in src/web/mod.rs.
  • static/css/output.css and static/js/editor.bundle.js are indeed gitignored, confirming the root cause.
  • I reproduced the failure locally (assets absent in this checkout) — the guard is exercised correctly and would fail loudly instead of silently shipping an unstyled UI.
  • --no-default-features builds (.github/workflows/test.yml:68,71) still compile src/web/mod.rs unconditionally (per its own doc comment, since cook build needs it even without the server feature), so the build script correctly does not gate the asset check behind the server feature — an unconditional check is the right call here, not an oversight.
  • cargo:rerun-if-changed on a not-yet-existing path is valid Cargo usage — the build script reruns until the file appears, so running npm run build-css/build-js after a failed build and re-running cargo build will pick it up without a cargo clean.
  • The CI reordering in the Playwright job (npm run build-* before cargo build) fixes the one job where the order was actually backwards; the other jobs already had npm before cargo.
  • Adding /build.rs to the include list in Cargo.toml is required — without it, cargo package would drop the build script from the published tarball entirely, and the crates.io flow relies on the compiled assets already being present in that same package, not on build.rs regenerating them (build.rs only checks for existence, it doesn't invoke npm).

Minor/non-blocking observations:

  • build.rs only checks file existence, not that the files are non-empty or well-formed. That's fine and matches the scope of the issue (Cook Server has no styling #233) — flagging only because a 0-byte output.css from an interrupted npm run build-css would still pass silently. Not worth adding complexity for.
  • Using eprintln! + std::process::exit(1) instead of panic! is the right choice here — avoids a noisy backtrace for what's an expected/actionable user error, and Cargo surfaces the stderr output directly.
  • No automated test covers this behavior, but that's consistent with the project's current testing approach (manual testing per CONTRIBUTING.md), so not a gap introduced by this PR specifically.

Security: No concerns — the script only does local path existence checks and printing; no untrusted input, no shell invocation.

Performance: Negligible — two Path::exists() calls at build time.

Nice fix — good root-cause diagnosis (rust-embed silently embedding nothing rather than failing) and the error message is genuinely actionable for someone hitting this from a fresh git clone.

@dubadub
dubadub merged commit 664db46 into main Aug 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cook Server has no styling

1 participant