Repository navigation
compile: build-time defines (--define, Bun.build semantics) and the no-define fallbacks OpenCode relies on (import.meta.resolve, new URL(..., import.meta.url)) #10101
Copy link
Copy link
Closed
Labels
enhancementNew capability or improvementNew capability or improvementparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystemCompatibility gap with Node.js, ECMAScript, or the supported ecosystem
Description
Parent: #10107.
Problem
packages/opencode/script/build.ts:191-201 injects eight compile-time constants with Bun.build define. Perry has no define mechanism (no --define, no perry.json key). Every constant is typeof-guarded, so the source still compiles, but each fallback must then work and the product identity is wrong:
| define | used at | fallback when undefined |
|---|---|---|
OPENCODE_VERSION |
packages/core/src/installation/version.ts:6 |
"local" (→ --version prints local, update checks, user-agent) |
OPENCODE_CHANNEL |
version.ts:7 |
"local" |
OPENCODE_MODELS_DEV (models.dev JSON snapshot from script/generate.ts) |
packages/core/src/models-dev.ts:199 |
undefined → fetched from models.dev at runtime |
OPENCODE_WORKER_PATH |
packages/opencode/src/cli/cmd/tui.ts:53 |
new URL("../tui/worker.ts", import.meta.url) |
OPENCODE_LIBC |
packages/core/src/filesystem/watcher.ts:28 |
undefined → @parcel/watcher-<platform>-<arch>[-glibc] |
OTUI_TREE_SITTER_WORKER_PATH |
@opentui/core/chunk-bun-t2myhmwd.js:8464 |
import.meta.resolve("@opentui/core/parser.worker") |
FFF_LIBC |
@ff-labs/fff-bun/src/embedded.ts:43 |
"gnu" |
process.env.OPENTUI_LIBC (linux) |
@opentui/core/chunk-bun-t2myhmwd.js:7924,7965 |
env lookup |
import.meta.resolve is lowered to undefined by perry (crates/perry-hir/src/lower/expr_member.rs:270-280: only url/main/dirname/filename/require are known), so the OTUI fallback throws undefined is not a function, and packages/core/src/npm.ts:53 import.meta.resolve(name, dir) (Bun's two-argument form, used to locate runtime-installed npm plugins/providers) silently yields no entrypoint.
Scope
- Add
--define NAME=<json-or-identifier-expr>(repeatable) andperry.json"define": { … }, with Bun.build semantics: identifier replacement at parse/lower time,typeof NAMEfolding, dotted keys (process.env.X), string values are JS expressions (Bun passesJSON.stringify(...)for strings). Include the define map in build and object-cache keys (likePERRY_LL_SIZE_OPTper perf(compile): reduce generated bundle bloat #8418). import.meta.resolve(specifier[, parent]): static specifier → the compile-time resolvedfile://URL of that module/asset (works for@opentui/core/parser.workerandweb-tree-sitter/tree-sitter.wasm); dynamic specifier → runtime resolver against the givenparentdirectory/URL (needed bycore/src/npm.ts:53for~/.cache/opencode/node_modules/<pkg>), returning afile://string, throwing like Bun on failure.- Verify
new Worker(new URL("../tui/worker.ts", import.meta.url))is discovered as a worker entry (a test already coversnew URL("./web-worker.ts", import.meta.url),crates/perry/tests/issue_worker_threads_cross_thread_delivery.rs:196) — see AOT/runtime: verify the three Worker entrypoints of OpenCode v1.18.30 end-to-end (TUI server worker, OpenTUI parser worker, thread-stream) #10103. - Harness: supply the eight defines exactly as
script/build.tsdoes (version frompackages/opencode/package.json, channellatest, models snapshot viascript/generate.ts, worker paths pointing at the compiled worker entries, libc flags).
Acceptance
-
perry compile --define OPENCODE_VERSION='"1.18.30"' …→opencode --versionprints1.18.30; without the define printslocal. -
typeof OPENCODE_MODELS_DEV === "undefined"folds to a constant with and without the define; the models.dev runtime fetch path runs when undefined. -
import.meta.resolve("@opentui/core/parser.worker")returns a usablefile://URL in the native binary;import.meta.resolve("x", "/tmp/dir")resolves/tmp/dir/node_modules/xat runtime. - Object cache invalidates when a define value changes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew capability or improvementNew capability or improvementparityCompatibility gap with Node.js, ECMAScript, or the supported ecosystemCompatibility gap with Node.js, ECMAScript, or the supported ecosystem
Activity
proggeramlug commentedon Sep 12, 2026
Fixed by #10129, landed on
mainvia merge train #10139 atf085eac679.The close keyword does not fire through a train branch, so closing manually.