From 9b8503d13dc81267588ecca4140fbe273f6c4da4 Mon Sep 17 00:00:00 2001 From: claude-code-best Date: Mon, 13 Apr 2026 09:44:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20node=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=B2=A1=E6=9C=89=20bun=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.ts | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/build.ts b/build.ts index 7b2169e0a..349a21e7e 100644 --- a/build.ts +++ b/build.ts @@ -118,7 +118,39 @@ const cliBun = join(outdir, 'cli-bun.js') const cliNode = join(outdir, 'cli-node.js') await writeFile(cliBun, '#!/usr/bin/env bun\nimport "./cli.js"\n') -await writeFile(cliNode, '#!/usr/bin/env node\nimport "./cli.js"\n') + +// Node.js entry needs a Bun API polyfill because Bun.build({ target: 'bun' }) +// emits globalThis.Bun references (e.g. Bun.$ shell tag in computer-use-input, +// Bun.which in chunk-ys6smqg9) that crash at import time under plain Node.js. +const NODE_BUN_POLYFILL = `#!/usr/bin/env node +// Bun API polyfill for Node.js runtime +if (typeof globalThis.Bun === "undefined") { + const { execFileSync } = await import("child_process"); + const { resolve, delimiter } = await import("path"); + const { accessSync, constants: { X_OK } } = await import("fs"); + function which(bin) { + const isWin = process.platform === "win32"; + const pathExt = isWin ? (process.env.PATHEXT || ".EXE").split(";") : [""]; + for (const dir of (process.env.PATH || "").split(delimiter)) { + for (const ext of pathExt) { + const candidate = resolve(dir, bin + ext); + try { accessSync(candidate, X_OK); return candidate; } catch {} + } + } + return null; + } + // Bun.$ is the shell template tag (e.g. $\`osascript ...\`). Only used by + // computer-use-input/darwin — stub it so the top-level destructuring + // \`var { $ } = globalThis.Bun\` doesn't crash. + function $(parts, ...args) { + throw new Error("Bun.$ shell API is not available in Node.js. Use Bun runtime for this feature."); + } + globalThis.Bun = { which, $ }; +} +import "./cli.js" +` +await writeFile(cliNode, NODE_BUN_POLYFILL) +// NOTE: when new Bun-specific globals appear in bundled output, add them here. // Make both executable const { chmodSync } = await import('fs')