Path: blob/main/lang/bun/files/patch-src_codegen_bake-codegen.ts
46591 views
-- Replace Bun.spawnSync with async Bun.spawn in bake-codegen.1-- On FreeBSD linux compat layer, Bun.spawnSync with stdio:"pipe" fails2-- with EINVAL because pread() is not valid on pipes. Using async Bun.spawn3-- with Response.arrayBuffer() works correctly on FreeBSD linux compat.452026-04-27 07:15:02 UTC6+++ src/codegen/bake-codegen.ts7@@ -30,20 +30,27 @@ function convertZigEnum(zig: string, names: string[])8return output;9}1011-function css(file: string, is_development: boolean): string {12- const { success, stdout, stderr } = Bun.spawnSync({13+async function css(file: string, is_development: boolean): Promise<string> {14+ const proc = Bun.spawn({15cmd: [process.execPath, "build", file, "--minify"],16cwd: import.meta.dir,17stdio: ["ignore", "pipe", "pipe"],18});19- if (!success) throw new Error(stderr.toString("utf-8"));20- return stdout.toString("utf-8");21+ const [stdoutBuf, stderrBuf] = await Promise.all([22+ new Response(proc.stdout).arrayBuffer(),23+ new Response(proc.stderr).arrayBuffer(),24+ ]);25+ const exitCode = await proc.exited;26+ if (exitCode !== 0) throw new Error(Buffer.from(stderrBuf).toString("utf-8"));27+ return Buffer.from(stdoutBuf).toString("utf-8");28}2930async function run() {31const devServerZig = readFileSync(join(base_dir, "DevServer.zig"), "utf-8");32writeIfNotChanged(join(base_dir, "generated.ts"), convertZigEnum(devServerZig, ["IncomingMessageId", "MessageId"]));3334+ const overlayCSS = await css("../bake/client/overlay.css", !!debug);35+36const results = await Promise.allSettled(37["client", "server", "error"].map(async file => {38const side = file === "error" ? "client" : file;39@@ -53,7 +60,7 @@ async function run() {40side: JSON.stringify(side),41IS_ERROR_RUNTIME: String(file === "error"),42IS_BUN_DEVELOPMENT: String(!!debug),43- OVERLAY_CSS: css("../bake/client/overlay.css", !!debug),44+ OVERLAY_CSS: overlayCSS,45},46minify: {47syntax: !debug,484950