- 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=258&format=json
58 linesnode20 100%Last change node20 in version 172, 3 versions changed it
You're reading version 258. The newest is 318, and 1 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 // A bundled CommonJS package (yaml) calls require("process") lazily, which an ES module bundle
35 // can't do without a real require.
36 banner: {
37 js: [
38 "// Built from client/abso.ts by scripts/build-client.mjs (npm run build). Don't edit it by hand.",
39 'import { createRequire as __absoCreateRequire } from "node:module";',
40 "const require = __absoCreateRequire(import.meta.url);",
41 ...banner,
42 ].join("\n"),
43 },
44 });
45 // esbuild leaves control characters in string literals as they are (yaml's lexer has \x02, \x18 and \x1f).
46 // Escaped, the file is plain text that every tool shows and stores as it is.
47 return result.outputFiles[0].text.replace(
48 /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,
49 (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`,
50 );
51}
53if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
54 const path = join(root, OUT);
55 mkdirSync(dirname(path), { recursive: true });
56 writeFileSync(path, buildClient());
57 process.stdout.write(`Built ${OUT}: node ${OUT} help\n`);
58}