/** * The shell has to reach QuickJS as source text. Emitted as a `.ts` module, not * a `.js` asset, so Vite and plain Node get at it the same way. Committed, like * the wasm packages, so a checkout builds without this having run. */ import { build } from "esbuild"; import { mkdirSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const here = dirname(fileURLToPath(import.meta.url)); const outDir = join(here, "src", "generated"); const result = await build({ entryPoints: [join(here, "src", "guest", "index.ts")], bundle: true, write: false, format: "iife", platform: "browser", target: "es2022", minify: false, legalComments: "none", }); const source = result.outputFiles[0].text; mkdirSync(outDir, { recursive: true }); writeFileSync( join(outDir, "guest.ts"), [ "// Generated by build-guest.mjs. Do not edit.", "//", "// The runtime shell, as source text, for evaluation inside QuickJS.", "// Regenerate with `npm run build --workspace @yaakapp-internal/plugin-sandbox`.", "", `export const GUEST_SOURCE = ${JSON.stringify(source)};`, "", ].join("\n"), ); console.log(`Bundled guest shell: ${(source.length / 1024).toFixed(1)} KB`);