Skip to content

fix(core): default #sqlite resolution to the node driver - #41834

Open
kitlangton wants to merge 1 commit into
v2from
bun-sqlite-gate
Open

fix(core): default #sqlite resolution to the node driver#41834
kitlangton wants to merge 1 commit into
v2from
bun-sqlite-gate

Conversation

@kitlangton

Copy link
Copy Markdown
Contributor

What

Repoints the default condition of the #sqlite subpath import from sqlite.bun.ts to sqlite.node.ts, and adds a bundling smoke test that pins bun:sqlite out of non-Bun bundles of database.ts.

Why

sqlite.bun.ts has a static import { Database } from "bun:sqlite". Any non-Bun bundle that resolves #sqlite to it crashes at module load on the unresolvable bun:sqlite specifier — downstream workerd embedders currently carry wrangler alias/stubs to work around this.

#41659 added the workerd condition (so wrangler's ["workerd", "worker", "browser"] set resolves to sqlite.workerd.ts), but default still pointed at the bun variant: any bundler without the bun, node, or workerd condition (browser-target esbuild/Bun.build, or a workerd toolchain that drops the condition) selected sqlite.bun.ts and shipped the crash. Reproduced at v2 head: a browser-conditions Bun.build of database.ts bundles SqliteBun and the bun:sqlite specifier.

How

  • packages/core/package.json: #sqlite now maps workerd → workerd driver, bunbun:sqlite driver, node/default → the node:sqlite driver. Bun and Node runtimes match their own conditions first, so their resolution is unchanged; only the fallback moves off the Bun-only module.
  • packages/core/test/sqlite-bundle.test.ts: builds database.ts with Bun.build, externalizing bare imports so only core-relative modules (including the #sqlite resolution) are bundled, and asserts:
    • conditions: ["workerd"] selects the Durable Object driver with no bun:sqlite or node:sqlite in the output
    • default (browser) conditions fall back to SqliteNode, never bun:sqlite

The dynamic import("bun:sqlite") in v1-migration.ts is lazy and unaffected; it does not appear in either bundle.

Scope

packages/core only: one condition-map line plus a new test file.

Testing

  • packages/core: bun run typecheck clean; bun test green (1666 pass, 0 fail) including the new bundle test
  • Repo root: bun run typecheck clean (33/33 tasks)
  • bunx oxlint on touched files: 0 errors, 0 warnings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant