social-kit / scripts / compile-check.mjs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// `shadow-cljs compile lib`, with its warnings promoted to a failure.
//
// The compiler already knows about a whole class of defect this repo cares
// about — :redef in particular, which is what a `(defn- object? …)` shadowing
// `cljs.core/object?` for a whole namespace looks like — and it says so. It
// just says so on stdout and exits 0, so the finding scrolls past inside a
// green `npm run check` and nothing ever fails. That happened here: the
// idiomatic rewrite of envelope.cljs introduced exactly that shadow and the
// gate reported success.
//
// shadow-cljs has no --fail-on-warnings for `compile`, so the build's own
// summary line is the signal: it always ends with "(N files, M compiled, W
// warnings, T)". Anything but zero warnings fails here.
//
// Deliberately a `check` step and not a `pretest` hook: ~/.npmrc on at least
// one machine in this suite sets ignore-scripts=true, which makes an npm
// lifecycle hook a gate that passes by never running.
import { spawnSync } from "node:child_process";

const args = ["compile", "lib", "--config-merge", '{:output-dir "target/check-dist"}'];
const r = spawnSync("shadow-cljs", args, { encoding: "utf8", shell: false });

const out = `${r.stdout ?? ""}${r.stderr ?? ""}`;
process.stdout.write(out);

if (r.error) {
  console.error(`compile-check: could not run shadow-cljs — ${r.error.message}`);
  process.exit(1);
}
if (r.status !== 0) process.exit(r.status ?? 1);

// "[:lib] Build completed. (90 files, 67 compiled, 0 warnings, 2.54s)"
const summary = [...out.matchAll(/Build completed\. \(\d+ files, \d+ compiled, (\d+) warnings/g)];
if (summary.length === 0) {
  console.error("compile-check: no build-completed summary in the output — the gate cannot see the warning count");
  process.exit(1);
}
const warnings = summary.reduce((n, m) => n + Number(m[1]), 0);
if (warnings > 0) {
  console.error(`compile-check: ${warnings} compiler warning(s) — every one of them is a gate, not a note`);
  process.exit(1);
}
console.log(`compile-check: OK (${summary.length} build(s), 0 warnings)`);

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/social-kit.git