From d179968bb70358aab8da62c3fad8deae720bff72 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sat, 11 Jul 2026 08:03:19 +0200 Subject: [PATCH] build(coding-agent/scripts): migrated bundling from CLI to Bun.build API - Replaced the command-line execution of bun build with the native Bun.build API. - Resolved E2BIG errors occurring when passing large docs payloads as command-line arguments. --- packages/coding-agent/scripts/bundle-dist.ts | 38 ++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/packages/coding-agent/scripts/bundle-dist.ts b/packages/coding-agent/scripts/bundle-dist.ts index 49c18e24f..98534d251 100755 --- a/packages/coding-agent/scripts/bundle-dist.ts +++ b/packages/coding-agent/scripts/bundle-dist.ts @@ -88,21 +88,29 @@ async function main(): Promise { // afterwards to keep the checked-in placeholder empty. await runCommand(["bun", "--cwd=../stats", "run", "gen:stats"]); try { - await runCommand([ - "bun", - "build", - "--target=bun", - "--outdir", - "dist", - "--minify", - "--keep-names", - ...[...ALWAYS_EXTERNAL, ...RUNTIME_EXTERNAL].flatMap(dep => ["--external", dep]), - "--define", - 'process.env.PI_BUNDLED="true"', - "--define", - `process.env.PI_DOCS_EMBED=${JSON.stringify((await buildDocsIndexPayload()).payload)}`, - "./src/cli.ts", - ]); + // Build in-process: the docs embed payload is far larger than Linux's + // 128KiB per-argv-string cap, so it can never be passed as a CLI + // `--define` (posix_spawn fails with E2BIG). + const output = await Bun.build({ + entrypoints: [path.join(packageDir, "src/cli.ts")], + outdir: outDir, + target: "bun", + external: [...ALWAYS_EXTERNAL, ...RUNTIME_EXTERNAL], + define: { + "process.env.PI_BUNDLED": JSON.stringify("true"), + "process.env.PI_DOCS_EMBED": JSON.stringify((await buildDocsIndexPayload()).payload), + }, + minify: { + whitespace: true, + syntax: true, + identifiers: true, + keepNames: true, + }, + throw: false, + }); + if (!output.success) { + throw new Error(`CLI bundle failed:\n${output.logs.map(log => log.message).join("\n")}`); + } } finally { await runCommand(["bun", "--cwd=../stats", "run", "gen:stats:reset"]); }