Versions 5 to 318
new file, 254 lines
4+// - runs the client: a plain-JS bundle of it in this process when one matches the checkout's commit,
5+// otherwise client/abso.ts in a second node. Node strips types from every client file on every run,
7+// - at most every 5 minutes, and within 30 seconds of a stale bundle, starts a background step that
8+// fast-forwards the checkout (on main only), runs npm install when package-lock.json changed, and
11+// stdin, stdout, stderr, the arguments and the exit code pass through untouched: the exit codes carry
12+// meaning (2 refused, 3 still queued). The launcher's own notices go only to ~/.abso/launcher.log.
14+// The bundle is client/dist/abso.mjs, with the commit it was built from in client/dist/abso.mjs.commit.
15+// It sits one folder under client/, so the client's own folder (client-version.ts) is still client/.
16+// It is built with esbuild when the checkout has it (in worker/ or at the root): bundled, for node24,
17+// as an ES module, with no build commit stamped in, since a stamped client calls itself a downloaded
18+// copy. It is built to a temporary file and renamed into place, and marked current only after every
19+// require left in it resolves and it runs --version. If it still fails to load, the same run falls
24+import { appendFileSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
29+
38+/** Set by the bundle's first line: an error after it came from the command, so it's never run again. */
40+
42+ * The checkout's git folders: its own (HEAD) and the shared one (refs, info/exclude). They are the same
43+ * folder in a plain clone; in a worktree .git is a file naming its own folder, which names the shared one.
64+
86+
88+ * Runs fn under a lock folder, or not at all when another run holds it. A lock older than 10 minutes is a
89+ * dead run's: it is renamed aside before it's removed, so of two runs that find it stale only one takes it
116+
121+ appendFileSync(join(state, "launcher.log"), `${new Date().toISOString()} abso launch: ${text}\n`);
124+
126+ * The background step, one at a time under a lock (a second one finds it taken and exits): fast-forward,
130+ const git = (...a) => execFileSync("git", ["-C", repo, ...a], { encoding: "utf8", windowsHide: true });
150+ note(`the bundle wasn't built (${String(e?.message).split("\n")[0]}); client/abso.ts runs until it is`);
154+
155+/** Builds the bundle for this commit, unless it's already current or the checkout has no esbuild. */
186+ js: `globalThis.${STARTED} = true; import { createRequire as __absoCreateRequire } from "node:module"; const require = __absoCreateRequire(import.meta.url);`,
190+ for (const m of readFileSync(tmp, "utf8").matchAll(/__require\("([^"]+)"\)/g)) from.resolve(m[1]);
191+ execFileSync(process.execPath, [tmp, "--version"], { cwd: repo, stdio: "ignore", windowsHide: true });
198+
201+ const child = spawn(process.execPath, [join(repo, "client", "abso.ts"), ...process.argv.slice(2)], {
206+
207+/** Starts the background step when it's due: every 5 minutes, or within 30 seconds of a stale bundle. */
225+
235+ // In this process: the client reads its arguments from process.argv, as if run as `node client/dist/abso.mjs`.
245+ e instanceof SyntaxError || code === "ERR_MODULE_NOT_FOUND" || code === "ERR_UNSUPPORTED_ESM_URL_SCHEME";
247+ note(`the bundle didn't load (${code ?? e?.name}: ${String(e?.message).split("\n")[0]}), ran client/abso.ts`);
252+
- MCP
- compare on this site's /mcp
- CLI
- abso diff 5 318 client/launch.mjs --json
- JSON
- /christopher/abso-core/compare/5..318?file=client%2Flaunch.mjs&format=json