- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/scripts/build-client.mjs?version=299&format=json
61 linesnode20 95% · pinch 5%Last change pinch in version 287, 4 versions changed it
You're reading version 299. The newest is 318, and no version since then changed this file.
1// Builds client/bin/abso.mjs: the whole client, client/abso.ts and everything it imports (yaml included),
2// as one plain-JS file for Node 20 or later. Node 20 can't run the .ts files themselves (it has no type
3// stripping), so this file is how a checkout runs on it:
4//
5// npm ci && npm run build
6// node client/bin/abso.mjs help
7//
8// The file isn't committed (.gitignore leaves client/bin/ out); build it again after pulling. It sits one
9// folder under client/, so the client's own folder (client-version.ts) is still client/. scripts/pack-npm.mjs
10// puts the same build in the npm package.
11//
12// Plain JS on purpose: it runs before anything is built.
13import { mkdirSync, writeFileSync } from "node:fs";
14import { createRequire } from "node:module";
15import { dirname, join, resolve } from "node:path";
16import { fileURLToPath } from "node:url";
18const root = resolve(dirname(fileURLToPath(import.meta.url)), "..");
19const OUT = "client/bin/abso.mjs";
21/** The bundle's text, built in memory. `banner` adds lines at its top (the npm package stamps its version). */
22export function buildClient(banner = []) {
23 const esbuild = createRequire(import.meta.url)("esbuild");
24 const result = esbuild.buildSync({
25 absWorkingDir: root,
26 entryPoints: ["client/abso.ts"],
27 bundle: true,
28 platform: "node",
29 format: "esm",
30 target: "node20",
31 write: false,
32 outfile: OUT,
33 logLevel: "warning",
34 // Local projects run the open server's code in the client (client/src/local-store.ts); its Durable Object
35 // base class comes from the Workers runtime, so the bundle gets the client's stand-in.
36 alias: { "cloudflare:workers": "./client/src/durable-object-stand-in.ts" },
37 // A bundled CommonJS package (yaml) calls require("process") lazily, which an ES module bundle
38 // can't do without a real require.
39 banner: {
40 js: [
41 "// Built from client/abso.ts by scripts/build-client.mjs (npm run build). Don't edit it by hand.",
42 'import { createRequire as __absoCreateRequire } from "node:module";',
43 "const require = __absoCreateRequire(import.meta.url);",
44 ...banner,
45 ].join("\n"),
46 },
47 });
48 // esbuild leaves control characters in string literals as they are (yaml's lexer has \x02, \x18 and \x1f).
49 // Escaped, the file is plain text that every tool shows and stores as it is.
50 return result.outputFiles[0].text.replace(
51 /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,
52 (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`,
53 );
54}
56if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
57 const path = join(root, OUT);
58 mkdirSync(dirname(path), { recursive: true });
59 writeFileSync(path, buildClient());
60 process.stdout.write(`Built ${OUT}: node ${OUT} help\n`);
61}