fix(build): inject tree-sitter worker path at compile time - #350
Conversation
Replace file-embedding approach for the Tree-sitter parser worker with compile-time path injection via Bun define API. This fixes worker resolution failures in compiled binaries where import.meta.url points to the binary rather than the original package location. - Add src/scripts/build-binary.ts that wraps bun build --compile with OTUI_TREE_SITTER_WORKER_PATH define pointing to $bunfs root - Update package.json build script and CI workflow to use build-binary.ts - Refactor initTreeSitterAssets() to prefer compile-time constant with runtime fallback for local dev - Add web-tree-sitter dependency - Add unit and binary integration tests for worker path resolution Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PR Review: fix(build): inject tree-sitter worker path at compile timeSummaryThis PR addresses worker resolution failures in compiled binaries by replacing the file-embedding approach with compile-time path injection via Bun's ✅ StrengthsCode Quality
Test Coverage
Architecture
|
Replace file-embedding approach for the Tree-sitter parser worker with compile-time path injection via Bun define API. This fixes worker resolution failures in compiled binaries where import.meta.url points to the binary rather than the original package location. - Add src/scripts/build-binary.ts that wraps bun build --compile with OTUI_TREE_SITTER_WORKER_PATH define pointing to $bunfs root - Update package.json build script and CI workflow to use build-binary.ts - Refactor initTreeSitterAssets() to prefer compile-time constant with runtime fallback for local dev - Add web-tree-sitter dependency - Add unit and binary integration tests for worker path resolution Co-authored-by: lavaman131 <dev@example.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace file-embedding approach for the Tree-sitter parser worker with compile-time path injection via Bun define API. This fixes worker resolution failures in compiled binaries where import.meta.url points to the binary rather than the original package location. - Add src/scripts/build-binary.ts that wraps bun build --compile with OTUI_TREE_SITTER_WORKER_PATH define pointing to $bunfs root - Update package.json build script and CI workflow to use build-binary.ts - Refactor initTreeSitterAssets() to prefer compile-time constant with runtime fallback for local dev - Add web-tree-sitter dependency - Add unit and binary integration tests for worker path resolution Co-authored-by: lavaman131 <dev@example.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
When compiling Atomic with
bun build --compile, Tree-sitter syntax highlighting failed in the binary because the file-embedding approach (import ... with { type: "file" }) resolved paths relative toimport.meta.url, which points to the compiled binary rather than the original package location. This caused the parser worker to fail initialization.Solution
Replace the file-embedding approach with compile-time path injection using Bun's
defineAPI, following the pattern used by OpenCode SDK. The worker path is now injected as a compile-time constant pointing to$bunfs/root/(Bun's virtual filesystem in compiled binaries), with a runtime fallback for local development.Changes
src/scripts/build-binary.ts: New build wrapper that uses Bun'sdefineAPI to injectOTUI_TREE_SITTER_WORKER_PATHpointing to the worker's location in$bunfs/root/package.jsonbuild script and all CI workflow build steps to usebuild-binary.tsinitTreeSitterAssets(): Now prefers compile-time constant with runtime fallback for local developmentweb-tree-sitterdependency: Required for Tree-sitter functionalityTesting
The binary integration test (
tree-sitter-assets.binary.test.ts) compiles a test binary with the new build approach and verifies that markdown highlighting initializes successfully, ensuring the fix works end-to-end.