feat(e2e): run the CLI on Bun 1.4.3 and newer, without Node.js

Merged
OK
12d ago
+1004-277

The e2e CLI runs on Bun 1.4.3 or newer with no Node.js installed: bunx --bun e2e run. Node.js behavior does not change.

What changed

  • Loader. e2e's Node.js loader runs on module.registerHooks, which Bun lacks (oven-sh/bun#35690 is a draft). On Bun, e2e registers no hooks. Bun compiles TypeScript and resolves tsconfig paths and # imports itself (config/bun-loader.ts).
  • Fresh instances. Bun ignores the query e2e uses on Node.js to key module instances. So the loader deletes the module from require.cache, which holds ES modules too, and imports it again. A fresh graph also reloads every project file the entry imports by path, # import, or tsconfig alias. Bun.Transpiler.scanImports and Bun.resolveSync find those files.
  • Redaction. Bun's console writes past the process.stdout.write that e2e patches to redact secrets and route output. The loader points console at the streams before any project code runs.
  • One run per process. Bun runs an imported module's top level outside its importer's AsyncLocalStorage context, and holds one instance of each module per process. Two runs in one process can't be kept apart, so on Bun:
    • e2e/runner throws NODE_UNSUPPORTED. It already did, because of the missing hooks.
    • e2e mcp opens one session at a time.
  • Version guard. A Bun older than 1.4.3 gets the version to upgrade to: Bun 1.4.2 races a require() of an ES module whose graph waits on top-level await. Deno is still refused.
  • Fixes Bun exposed:
    • The signal ladder trusts process.connected only when there is an IPC channel (cli/signals.ts).
    • Stack frames may have no column (collect/registry.ts).
    • Config errors read Bun's syntax and resolve error shapes (config/diagnose.ts).
  • Init. In a Bun project, e2e init registers the MCP server with bunx.
  • CI. A bun job runs tests/integration/bun-runtime.test.ts on Bun 1.4.3 and on the latest Bun. The CLI, and everything it spawns, gets a PATH with no node on it.
flowchart LR
  L[load a config or test file] --> R{runtime}
  R -- Node.js --> N["registerHooks + oxc<br/>an instance per ?e2e-graph= query"]
  R -- Bun --> B["Bun compiles it<br/>delete from require.cache, import again"]

CLI reference, Bun lists what still differs on Bun:

  • # imports that map to a directory.
  • Legacy decorators in .cts files.
  • Watch mode and MCP read tsconfig.json and computed-path imports one time.
  • executable: 'node' under bun <file>.
  • The line reported for a test that a helper declares after an await.

The mobile engine and the integrations are not verified on Bun yet.

Verified

Ran it locally: yes

  • Released e2e vs this branch: e2e --version on Bun 1.4.4, with only Bun and git on PATH.

    e2e 0.23.0 from npmthis branch
    e2e runs on Node.js: Bun 1.4.4 reports Node.js 26.3.0 but has no module.registerHooks, which e2e's TypeScript loader needs. (exit 2)0.23.0. Then e2e doctor on the testbed prints ✓ node Bun 1.4.4 (>=1.4.3) and e2e run can start here
  • Testbed on Bun: the built CLI on Bun 1.4.4, run with env -i PATH=<bun and git>:/usr/bin:/bin bun run e2e run. Same totals as on Node.js 24.19:

     Test Files  47 passed (47)
          Tests  587 passed | 1 skipped (588)
       Duration  23.41s
    
  • e2e mcp --max-sessions 3 on Bun: it logs that the flag is ignored. A second open_session gets no session slot is free (e2e mcp --max-sessions 1).

  • Reverting fixes: each Bun test added for a loader or MCP fix fails with its fix reverted. That covers reloading a JSX .js file and a data file in a fresh graph, query imports, dotted aliases, console redaction, and the one-session cap.