{"draft":null,"from":169,"to":318,"files":[{"path":"scripts/build-client.mjs","added":21,"removed":24,"diff":"--- a/scripts/build-client.mjs\n+++ b/scripts/build-client.mjs\n@@ -2,17 +2,15 @@\n // as one plain-JS file for Node 20 or later. Node 20 can't run the .ts files themselves (it has no type\n // stripping), so this file is how a checkout runs on it:\n //\n+//   npm ci && npm run build\n //   node client/bin/abso.mjs help\n //\n-//   npm run build:client           rebuilds it; run it after changing the client and push the result.\n-//   npm run check:client-bundle    fails when the file isn't what a build of this folder gives (the check runs it).\n+// The file isn't committed (.gitignore leaves client/bin/ out); build it again after pulling. It sits one\n+// folder under client/, so the client's own folder (client-version.ts) is still client/. scripts/pack-npm.mjs\n+// puts the same build in the npm package.\n //\n-// The file is committed, so a fresh clone runs it with no install and no build. It sits one folder under\n-// client/, so the client's own folder (client-version.ts) is still client/. The build is deterministic:\n-// paths in it are relative to the repo, so it comes out the same on every machine.\n-//\n // Plain JS on purpose: it runs before anything is built.\n-import { readFileSync, writeFileSync } from \"node:fs\";\n+import { mkdirSync, writeFileSync } from \"node:fs\";\n import { createRequire } from \"node:module\";\n import { dirname, join, resolve } from \"node:path\";\n import { fileURLToPath } from \"node:url\";\n@@ -20,8 +18,8 @@\n const root = resolve(dirname(fileURLToPath(import.meta.url)), \"..\");\n const OUT = \"client/bin/abso.mjs\";\n \n-/** The bundle's text, built in memory. */\n-export function buildClient() {\n+/** The bundle's text, built in memory. `banner` adds lines at its top (the npm package stamps its version). */\n+export function buildClient(banner = []) {\n \tconst esbuild = createRequire(import.meta.url)(\"esbuild\");\n \tconst result = esbuild.buildSync({\n \t\tabsWorkingDir: root,\n@@ -33,32 +31,31 @@\n \t\twrite: false,\n \t\toutfile: OUT,\n \t\tlogLevel: \"warning\",\n+\t\t// Local projects run the open server's code in the client (client/src/local-store.ts); its Durable Object\n+\t\t// base class comes from the Workers runtime, so the bundle gets the client's stand-in.\n+\t\talias: { \"cloudflare:workers\": \"./client/src/durable-object-stand-in.ts\" },\n \t\t// A bundled CommonJS package (yaml) calls require(\"process\") lazily, which an ES module bundle\n \t\t// can't do without a real require.\n \t\tbanner: {\n \t\t\tjs: [\n-\t\t\t\t\"// Built from client/abso.ts by scripts/build-client.mjs (npm run build:client). Don't edit it by hand.\",\n+\t\t\t\t\"// Built from client/abso.ts by scripts/build-client.mjs (npm run build). Don't edit it by hand.\",\n \t\t\t\t'import { createRequire as __absoCreateRequire } from \"node:module\";',\n \t\t\t\t\"const require = __absoCreateRequire(import.meta.url);\",\n+\t\t\t\t...banner,\n \t\t\t].join(\"\\n\"),\n \t\t},\n \t});\n-\treturn result.outputFiles[0].text;\n+\t// esbuild leaves control characters in string literals as they are (yaml's lexer has \\x02, \\x18 and \\x1f).\n+\t// Escaped, the file is plain text that every tool shows and stores as it is.\n+\treturn result.outputFiles[0].text.replace(\n+\t\t/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/g,\n+\t\t(c) => `\\\\x${c.charCodeAt(0).toString(16).padStart(2, \"0\")}`,\n+\t);\n }\n \n if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {\n \tconst path = join(root, OUT);\n-\tconst text = buildClient();\n-\tif (process.argv.includes(\"--check\")) {\n-\t\tlet have = \"\";\n-\t\ttry {\n-\t\t\thave = readFileSync(path, \"utf8\").replace(/\\r\\n/g, \"\\n\");\n-\t\t} catch {}\n-\t\tif (have !== text) {\n-\t\t\tprocess.stderr.write(\n-\t\t\t\t`${OUT} is not a build of this folder's client: run npm run build:client and push the file it writes.\\n`,\n-\t\t\t);\n-\t\t\tprocess.exit(1);\n-\t\t}\n-\t} else writeFileSync(path, text);\n+\tmkdirSync(dirname(path), { recursive: true });\n+\twriteFileSync(path, buildClient());\n+\tprocess.stdout.write(`Built ${OUT}: node ${OUT} help\\n`);\n }"}],"unmatched":[]}