Commit 6c6ea45
authored
refactor: replace Bun.build with fossilize for Node SEA binaries (#1003)
## Phase 6: Replace Bun Binary Compilation with Fossilize
Final phase of the Bun → Node.js migration. Replaces `Bun.build({
compile: true })` with [fossilize](https://github.com/BYK/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 run` → `pnpm 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 binaries1 parent c064547 commit 6c6ea45
17 files changed
Lines changed: 577 additions & 376 deletions
File tree
- .github/workflows
- script
- src
- commands/local
- lib
- db
- init/ui
- test/e2e
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
93 | 91 | | |
94 | 92 | | |
95 | 93 | | |
| |||
246 | 244 | | |
247 | 245 | | |
248 | 246 | | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | 247 | | |
253 | 248 | | |
254 | 249 | | |
| |||
262 | 257 | | |
263 | 258 | | |
264 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
265 | 282 | | |
266 | 283 | | |
267 | 284 | | |
| |||
278 | 295 | | |
279 | 296 | | |
280 | 297 | | |
281 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
282 | 303 | | |
283 | 304 | | |
284 | 305 | | |
| |||
288 | 309 | | |
289 | 310 | | |
290 | 311 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | 312 | | |
297 | 313 | | |
298 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | 36 | | |
40 | 37 | | |
41 | 38 | | |
| |||
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
61 | | - | |
| 58 | + | |
62 | 59 | | |
63 | 60 | | |
64 | 61 | | |
| |||
70 | 67 | | |
71 | 68 | | |
72 | 69 | | |
73 | | - | |
74 | | - | |
| 70 | + | |
| 71 | + | |
75 | 72 | | |
76 | 73 | | |
77 | 74 | | |
| |||
80 | 77 | | |
81 | 78 | | |
82 | 79 | | |
83 | | - | |
84 | | - | |
| 80 | + | |
| 81 | + | |
85 | 82 | | |
86 | 83 | | |
87 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 39 | | |
43 | 40 | | |
44 | 41 | | |
| |||
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
53 | | - | |
| 50 | + | |
54 | 51 | | |
55 | 52 | | |
56 | 53 | | |
57 | | - | |
| 54 | + | |
58 | 55 | | |
59 | 56 | | |
60 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
0 commit comments