bot / scripts / build.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
44
45
46
47
48
49
50
51
52
// Build the committed dists: four isolated shadow-cljs release builds (one per
// process entry — the two-stack law is enforced by build structure), assembled
// onto the fixed artifact paths systemd/install-fleet.sh expect.
//
// ONE compile, TWO npm roots. Node resolves a bare import from the IMPORTING
// FILE's directory upward, so which directory a bundle lands in decides which
// libp2p generation it gets. That is the whole reason the outputs are split:
//
//   stack-a/dist/main.js  stack-a/dist/rl/train.js  stack-a/dist/fleet/link.js
//   stack-b/dist/worker.js
//
// Then normalize the JVM-global gensym numbering so both dists are
// byte-deterministic (deploy/check-dist.sh rebuilds and diffs).
import { execFileSync } from "node:child_process";
import { rmSync, mkdirSync, copyFileSync } from "node:fs";
import { dirname, join } from "node:path";

const ROOT = join(dirname(new URL(import.meta.url).pathname), "..");
const run = (cmd, args) => execFileSync(cmd, args, { cwd: ROOT, stdio: "inherit" });

// ALWAYS a cold build (rooms-kit's own npm build does the same): the JVM-global
// gensym counter numbers more than the normalizer's dyn/proto vars — promesa's
// reify metas bake the number into a Symbol CONSTANT's name and hash — and a
// warm .shadow-cljs cache numbers them differently from the clean rebuild
// check-dist diffs against. Cold-to-cold is deterministic; warm-to-cold is not.
rmSync(join(ROOT, ".shadow-cljs"), { recursive: true, force: true });
rmSync(join(ROOT, "stack-a", "dist"), { recursive: true, force: true });
rmSync(join(ROOT, "stack-b", "dist"), { recursive: true, force: true });
for (const b of ["esm-main", "esm-worker", "esm-train", "esm-link"]) {
  rmSync(join(ROOT, "target", b), { recursive: true, force: true });
}

// one JVM, four disjoint module graphs
run("npx", ["shadow-cljs", "release", "main", "worker", "train", "link"]);

const out = {
  "target/esm-main/main.js": "stack-a/dist/main.js",
  "target/esm-train/train.js": "stack-a/dist/rl/train.js",
  "target/esm-link/link.js": "stack-a/dist/fleet/link.js",
  "target/esm-worker/worker.js": "stack-b/dist/worker.js",
};
for (const [src, dst] of Object.entries(out)) {
  mkdirSync(join(ROOT, dirname(dst)), { recursive: true });
  copyFileSync(join(ROOT, src), join(ROOT, dst));
}
// canon hygiene: only the four .js files are copied, but keep the guard
for (const s of ["stack-a", "stack-b"]) {
  rmSync(join(ROOT, s, "dist", "manifest.edn"), { force: true });
}

run("node", ["scripts/normalize-gensyms.mjs"]);
console.log("build: stack-a/dist (main, rl/train, fleet/link) + stack-b/dist (worker)");

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/bot.git