Cross-runtime shim layer for Node.js compat (Phase 1)#491
Open
evantahler wants to merge 2 commits into
Open
Conversation
Phase 1 of dual-runtime (Bun + Node.js) support. Introduces packages/keryx/util/runtime.ts as the single abstraction over Bun-only primitives and swaps all non-server framework source onto it: - sleep, glob/globSync (tinyglobby), sha256Hex (node:crypto), readFileText/readFileJson/writeFile/fileExists/mimeType (node:fs/promises + mime), spawnProcess (node:child_process) - Bun.env -> process.env (a global on both runtimes) - initializers/db.ts drizzle-kit shell ($) -> spawnProcess(packageRunner) - webStaticFiles.ts streams via node:fs + Readable.toWeb; ETag from fs.stat fileExists matches Bun.file(p).exists() semantics (regular files only, not directories) so the static-file index.html fallback keeps working. No behavior change on Bun: tsc + biome clean, full suite (54 files / 777 tests) passes. The only remaining Bun.* in source is the server transport (servers/web.ts, util/webSocket.ts), deferred to the srvx + crossws port. Part of #488 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Phase 2 of dual-runtime support. globLoader and API.loadLocalConfig now match both TypeScript sources (.ts/.tsx — the dev/source layout) and compiled JavaScript (.js/.mjs/.cjs — the built dist/ layout a plain-Node consumer runs), skip declaration files (.d.ts), and dedupe by basename so a stray compiled .js next to its .ts source can't double-instantiate. In dev only .ts is present, so loading order/behavior is unchanged: full suite (54 files / 777 tests) still passes on Bun. Asset + scaffold-source path resolution (packageRoot/scaffoldSourceRoot) is deferred to the build-step PR, where it can be validated against the real tsup output layout. Part of #488 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Phase 1 of making the
keryxframework run on both Bun and Node.js (tracking issue #488). This PR is pure groundwork — it introduces a cross-runtime shim layer and moves all non-server framework code off Bun-only globals, with no behavior change on Bun.Changes
packages/keryx/util/runtime.ts— the single abstraction over Bun-only primitives:sleep·glob/globSync(tinyglobby) ·sha256Hex(node:crypto) ·readFileText/readFileJson/writeFile/fileExists/mimeType(node:fs/promises +mime) ·spawnProcess(node:child_process) ·isBun·packageRunnerBun.*:Bun.env→process.env(a global on both runtimes — no import, no scaffold-rewrite needed)Bun.Glob,Bun.CryptoHasher,Bun.file/Bun.write→ shim helpersinitializers/db.tsdrizzle-kit$shell →spawnProcess(packageRunner, …)util/webStaticFiles.tsnow streams vianode:fs+Readable.toWeb, with ETag fromfs.stattinyglobby+mime; version bump0.31.0 → 0.31.1.fileExistsdeliberately matchesBun.file(p).exists()semantics (regular files only, not directories) so the static-fileindex.htmldirectory-fallback keeps working — caught by the existing static-file tests.Out of scope (later phases)
The only
Bun.*left in source is the server transport (servers/web.ts,util/webSocket.ts), deferred to the srvx + crossws port (Phase 3). Build step (Phase 4), Node test run + CI matrix (Phase 5/6), and docs (Phase 7) follow.Verification
tsc --noEmit: clean ·biome check: cleanPart of #488
🤖 Generated with Claude Code