Skip to content

refactor: replace Bun.build with fossilize for Node SEA binaries#1003

Merged
BYK merged 1 commit into
mainfrom
refactor/phase5-cleanup
May 22, 2026
Merged

refactor: replace Bun.build with fossilize for Node SEA binaries#1003
BYK merged 1 commit into
mainfrom
refactor/phase5-cleanup

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented May 22, 2026

Phase 6: Replace Bun Binary Compilation with Fossilize

Final phase of the Bun → Node.js migration. Replaces Bun.build({ compile: true }) with fossilize for producing Node SEA (Single Executable Application) binaries. This completely removes Bun from the codebase.

Architecture Change

BEFORE:
  src/bin.ts → [esbuild ESM] → dist-bin/bin.js → [Bun.build compile] → binary

AFTER:
  src/bin.ts → [esbuild CJS] → dist-build/bin.js → [fossilize --no-bundle] → binary

Changes

Build script (script/build.ts):

  • Replaced Bun.build({ compile: true }) with npx fossilize --no-bundle
  • Switched esbuild format from ESM to CJS (Node SEA requirement)
  • Added import-meta-url.js inject + define for CJS compatibility
  • Target node22 (downlevels using declarations unsupported in CJS)
  • Removed sourcemap backup/restore dance (fossilize doesn't generate its own map)
  • Separated build output (dist-build/) from fossilize output (dist-bin/)
  • Replaced all Bun.$, Bun.file, Bun.write with Node.js equivalents
  • Dropped musl targets (Node doesn't publish musl/Alpine binaries)

Ink sidecar (src/lib/init/ui/ink-ui.ts):

  • Added node:sea.getAsset() runtime path for SEA binaries
  • Sidecar embedded via fossilize --assets flag
  • Extracts to temp file and import()s at runtime
  • Dev and npm bundle paths unchanged

SQLite (src/lib/db/sqlite.ts):

  • Removed bun:sqlite try/catch fallback — Node-only now

Binary entry (src/bin.ts):

  • Suppresses ExperimentalWarning: SQLite is an experimental feature

CI (.github/workflows/ci.yml):

  • Removed setup-bun entirely (no more Bun in CI)
  • Added rcodesign v0.29.0 installation for macOS code signing from Linux
  • Added Apple cert/key environment setup (matches Spotlight's approach)
  • FOSSILIZE_SIGN env var controls signing (enabled on main/release pushes)
  • Dropped musl targets from build matrix (7 → 5 targets)

Other cleanup:

  • Removed Bun from biome.jsonc globals
  • Updated package.json build scripts: bun runpnpm tsx
  • Added dist-build/ to .gitignore and biome excludes
  • text-import-plugin: file imports return path string for all formats (no more ESM external for Bun.compile)

Benchmark Results

Mode Avg Startup Notes
Baseline (no cache) ~870ms Current approach
useCodeCache ~740ms ~15% faster (same-platform only)
useSnapshot N/A Crashes — too many unsupported modules

Code cache improvement deferred — requires fossilize PR to support per-platform useCodeCache.

What's Gone

  • setup-bun from CI
  • bun:sqlite fallback
  • Bun.build() / Bun.$ / Bun.file / Bun.write in build script
  • Bun global declaration
  • musl binary targets

Testing

  • Local build succeeds on Linux x64 (Node SEA via fossilize)
  • Binary runs --help and --version correctly
  • No SQLite warning in output
  • binpunch ICU hole-punching works on Node SEA binaries

Comment thread .github/workflows/ci.yml
Comment thread src/lib/init/ui/ink-ui.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch from 8237365 to 1939ab9 Compare May 22, 2026 10:38
Comment thread src/lib/init/ui/ink-ui.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch from 1939ab9 to fee2e04 Compare May 22, 2026 10:49
Comment thread .github/workflows/ci.yml
Comment thread src/commands/local/run.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch from fee2e04 to 83525b2 Compare May 22, 2026 11:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/_preview/pr-1003/

Built to branch gh-pages at 2026-05-22 11:49 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Codecov Results 📊

❌ Patch coverage is 50.00%. Project has 4237 uncovered lines.
❌ Project coverage is 81.85%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
src/commands/local/run.ts 33.33% ⚠️ 2 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
- Coverage    81.86%    81.85%    -0.01%
==========================================
  Files          328       328         —
  Lines        23349     23347        -2
  Branches     15114     15114         —
==========================================
+ Hits         19115     19110        -5
- Misses        4234      4237        +3
- Partials      1620      1618        -2

Generated by Codecov Action

Comment thread src/lib/db/sqlite.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch 2 times, most recently from 5a46789 to c89949e Compare May 22, 2026 11:14
Comment thread script/build.ts
Comment thread script/build.ts
Comment thread script/build.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch from c89949e to 8d8607c Compare May 22, 2026 11:25
Comment thread script/build.ts
@BYK BYK force-pushed the refactor/phase5-cleanup branch from 8d8607c to d994421 Compare May 22, 2026 11:36
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d994421. Configure here.

Comment thread src/bin.ts
- Replace Bun.build({ compile: true }) with fossilize --no-bundle
- Switch esbuild output from ESM to CJS (Node SEA requirement)
- Add import-meta-url.js shim for CJS format
- Target node22 to downlevel 'using' declarations
- Embed Ink sidecar via fossilize --assets + node:sea.getAsset()
- Update text-import-plugin: file imports return path string (no ESM external)
- Drop musl targets (Node doesn't publish musl binaries)
- Remove bun:sqlite fallback from sqlite.ts (Node-only now)
- Remove setup-bun from CI, add rcodesign for macOS signing
- Remove Bun global from biome.jsonc
- Suppress SQLite ExperimentalWarning in bin.ts
- Add dist-build/ to .gitignore and biome excludes
@BYK BYK force-pushed the refactor/phase5-cleanup branch from d994421 to ddacf83 Compare May 22, 2026 11:48
@BYK BYK merged commit 6c6ea45 into main May 22, 2026
29 checks passed
@BYK BYK deleted the refactor/phase5-cleanup branch May 22, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant