Merge pull request #10958 from Kilo-Org/fix/cli-disable-bun-splitting

fix(cli): disable Bun code-splitting to fix baseline release crash
This commit is contained in:
Catriel Müller
2026-06-05 17:46:49 -03:00
committed by GitHub
3 changed files with 11 additions and 53 deletions
+10 -20
View File
@@ -287,35 +287,25 @@ for (const item of targets) {
const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/"
const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/")
// kilocode_change start - redirect @morphllm/morphsdk ESM barrel to self-contained CJS bundle
// Bun 1.3.14 (with conditions:["browser"]) resolves via the "import" condition, pulling in the
// pre-split ESM barrel (client.js) whose 52 chunk-*.js side-imports make the ESM splitter emit
// invalid minified output: SyntaxError: Exported binding 'G9' needs to refer to a top-level...
// Redirecting onResolve to client.cjs (2300-line self-contained CJS bundle) bypasses the splitter.
// require.resolve uses the package's "require" condition, which maps the warp-grep/client
// subpath straight to client.cjs. The deep dist path is not an exported subpath, so resolving
// it directly throws "Cannot find module" — go through the public specifier instead.
const morphsdkCjs = require.resolve("@morphllm/morphsdk/tools/warp-grep/client")
const morphsdkCjsPlugin: import("bun").BunPlugin = {
name: "morphsdk-cjs",
setup(build) {
build.onResolve({ filter: /^@morphllm\/morphsdk\/tools\/warp-grep\/client$/ }, () => ({
path: morphsdkCjs,
}))
},
}
// kilocode_change end
await Bun.build({
conditions: ["browser"],
tsconfig: "./tsconfig.json",
plugins: [plugin, morphsdkCjsPlugin], // kilocode_change
plugins: [plugin],
// kilocode_change start - skip sourcemaps for release builds (each .js.map adds ~50 MB per target → ~600 MB total)
sourcemap: Script.release ? "none" : "external",
// kilocode_change end
external: ["node-gyp", ...LanceDBRuntime.external], // kilocode_change
format: "esm",
minify: true,
splitting: true,
// kilocode_change start - disable code-splitting to avoid a Bun 1.3.14 codegen bug.
// With splitting:true Bun emits cross-chunk re-exports like `import{vn as G9}` whose
// binding isn't top-level, so the compiled binary crashes at startup on the baseline
// target: "SyntaxError: Exported binding 'G9' needs to refer to a top-level declared
// variable." (Bun oven-sh/bun#25621, #5344, #7265; also opencode#23349). Fixed upstream
// in Bun#26089, post-1.3.14. Splitting only deduped shared code between the entrypoints;
// turning it off inlines per entrypoint and produces a valid binary.
splitting: false,
// kilocode_change end
compile: {
autoloadBunfig: false,
autoloadDotenv: false,
@@ -1,32 +0,0 @@
// kilocode_change - new file
// Re-exports from @morphllm/morphsdk/tools/warp-grep/client.
//
// WHY THIS INDIRECTION EXISTS
// ----------------------------
// @morphllm/morphsdk ships a pre-split ESM distribution for this path:
// dist/tools/warp_grep/client.js (805-byte barrel)
// └─ imports from ../../chunk-P7G3CJB2.js ... (52 total pre-split chunks)
//
// Bun 1.3.14 bundling with `conditions: ["browser"]` resolves via the "import" condition
// (ESM barrel) even inside createRequire() calls. When its ESM splitter merges those
// external pre-split chunks into the bundle, it generates invalid minified output:
// SyntaxError: Exported binding 'G9' needs to refer to a top-level declared variable.
//
// FIX: script/build.ts adds a morphsdkCjsPlugin (onResolve) that redirects this module
// specifier to client.cjs — a fully self-contained CJS bundle (~2300 lines, no chunk-*.js
// imports). The plugin runs at bundle time before the ESM splitter is invoked. It resolves
// client.cjs via require.resolve("@morphllm/morphsdk/tools/warp-grep/client") (the package's
// "require" export condition); the raw dist/.../client.cjs path is not an exported subpath
// and throws "Cannot find module".
//
// HOW TO DETECT THIS FOR FUTURE DEPS
// ------------------------------------
// If a new dependency causes the SyntaxError above in release builds, check whether its
// ESM entry point is a barrel that re-imports from internal `chunk-*.js` files:
//
// head -5 node_modules/<pkg>/dist/index.js
// → imports { ... } from "./chunk-XYZ123.js" ← pre-split ESM
//
// If so, add a matching onResolve redirect to the CJS counterpart in build.ts.
export { WarpGrepClient } from "@morphllm/morphsdk/tools/warp-grep/client"
+1 -1
View File
@@ -1,6 +1,6 @@
import { Effect, Schema } from "effect"
import * as Tool from "./tool"
import { WarpGrepClient } from "@/kilocode/compat/morphsdk" // kilocode_change
import { WarpGrepClient } from "@morphllm/morphsdk/tools/warp-grep/client" // kilocode_change
import { Telemetry } from "@kilocode/kilo-telemetry" // kilocode_change
import { Instance } from "../project/instance"
import { Bus } from "../bus"