Compare commits

...

1 Commits

Author SHA1 Message Date
Aiden Cline e8b92c5375 fix(tui): bundle parser worker separately
Avoid registering the OpenTUI parser worker source itself as a build entrypoint. Bun otherwise resolves OpenTUI’s file import as a module namespace without a default path, crashing compiled TUI startup. Bundle an equivalent virtual worker entrypoint so the worker remains executable without colliding with the package asset import.
2026-07-17 23:04:21 +00:00
+13 -10
View File
@@ -1,7 +1,6 @@
#!/usr/bin/env bun #!/usr/bin/env bun
import { $ } from "bun" import { $ } from "bun"
import fs from "fs"
import path from "path" import path from "path"
import { fileURLToPath } from "url" import { fileURLToPath } from "url"
import { createSolidTransformPlugin } from "@opentui/solid/bun-plugin" import { createSolidTransformPlugin } from "@opentui/solid/bun-plugin"
@@ -49,6 +48,7 @@ const createEmbeddedWebUIBundle = async () => {
} }
const embeddedFileMap = skipEmbedWebUi ? null : await createEmbeddedWebUIBundle() const embeddedFileMap = skipEmbedWebUi ? null : await createEmbeddedWebUIBundle()
const treeSitterWorker = await Bun.file(fileURLToPath(import.meta.resolve("@opentui/core/parser.worker"))).text()
const allTargets: { const allTargets: {
os: string os: string
@@ -156,14 +156,9 @@ for (const item of targets) {
console.log(`building ${name}`) console.log(`building ${name}`)
await $`mkdir -p dist/${name}/bin` await $`mkdir -p dist/${name}/bin`
const localPath = path.resolve(dir, "node_modules/@opentui/core/parser.worker.js")
const rootPath = path.resolve(dir, "../../node_modules/@opentui/core/parser.worker.js")
const parserWorker = fs.realpathSync(fs.existsSync(localPath) ? localPath : rootPath)
const workerPath = "./src/cli/tui/worker.ts" const workerPath = "./src/cli/tui/worker.ts"
const treeSitterWorkerPath = "opentui-tree-sitter-worker.js"
// Use platform-specific bunfs root path based on target OS
const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/" const bunfsRoot = item.os === "win32" ? "B:/~BUN/root/" : "/$bunfs/root/"
const workerRelativePath = path.relative(dir, parserWorker).replaceAll("\\", "/")
await Bun.build({ await Bun.build({
conditions: ["bun", "node"], conditions: ["bun", "node"],
@@ -184,13 +179,21 @@ for (const item of targets) {
execArgv: [`--user-agent=opencode/${Script.version}`, "--use-system-ca", "--"], execArgv: [`--user-agent=opencode/${Script.version}`, "--use-system-ca", "--"],
windows: {}, windows: {},
}, },
files: embeddedFileMap ? { "opencode-web-ui.gen.ts": embeddedFileMap } : {}, files: {
entrypoints: ["./src/index.ts", parserWorker, workerPath, ...(embeddedFileMap ? ["opencode-web-ui.gen.ts"] : [])], [treeSitterWorkerPath]: treeSitterWorker,
...(embeddedFileMap ? { "opencode-web-ui.gen.ts": embeddedFileMap } : {}),
},
entrypoints: [
"./src/index.ts",
workerPath,
treeSitterWorkerPath,
...(embeddedFileMap ? ["opencode-web-ui.gen.ts"] : []),
],
define: { define: {
FFF_LIBC: JSON.stringify(item.abi === "musl" ? "musl" : "gnu"), FFF_LIBC: JSON.stringify(item.abi === "musl" ? "musl" : "gnu"),
OPENCODE_VERSION: `'${Script.version}'`, OPENCODE_VERSION: `'${Script.version}'`,
OPENCODE_MODELS_DEV: generated.modelsData, OPENCODE_MODELS_DEV: generated.modelsData,
OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + workerRelativePath, OTUI_TREE_SITTER_WORKER_PATH: bunfsRoot + treeSitterWorkerPath,
OPENCODE_WORKER_PATH: workerPath, OPENCODE_WORKER_PATH: workerPath,
OPENCODE_CHANNEL: `'${Script.channel}'`, OPENCODE_CHANNEL: `'${Script.channel}'`,
OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "", OPENCODE_LIBC: item.os === "linux" ? `'${item.abi ?? "glibc"}'` : "",