mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-08-22 03:13:58 +02:00
Rationale that explains a decision rather than the code below it belongs in the sandbox README or the PR, not in a header paragraph on every file.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
/**
|
|
* 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`);
|