Jump to…
snowinitial commitqoxwzsukwmkx1mo
1//! Make the CodeMirror bundle optional at compile time.
2//!
3//! `assets/editor.min.js` is produced by esbuild in a Docker build stage, so it
4//! does not exist in a source checkout. `include_str!` needs *something*
5//! though, and a missing file would make `cargo build` fail outside Docker —
6//! which would mean the test suite could not run without a Node toolchain.
7//!
8//! An empty placeholder is the right fallback rather than a workaround: the
9//! edit page ships a working `<textarea>` and the bundle only enhances it, so a
10//! build without the bundle produces a product where editing still works,
11//! plainly. That is the documented behaviour when the script fails to load, and
12//! this makes it the behaviour when it was never built either.
13
14use std::path::Path;
15
16fn main() {
17 let bundle = Path::new("assets/editor.min.js");
18 println!("cargo:rerun-if-changed=assets/editor.min.js");
19
20 if !bundle.exists() {
21 std::fs::write(
22 bundle,
23 "/* No editor bundle in this build. The edit page falls back to a \
24 plain textarea, which is a working editor. */\n",
25 )
26 .expect("writing the editor placeholder");
27 println!(
28 "cargo:warning=assets/editor.min.js was not built; \
29 the web editor will fall back to a plain textarea"
30 );
31 }
32}

32 lines · Rust