mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 00:03:13 +03:00
fix(core): default #sqlite resolution to the node driver (#41834)
This commit is contained in:
committed by
GitHub
Unverified
parent
549a8f826b
commit
f1366d80c8
@@ -28,7 +28,7 @@
|
||||
"workerd": "./src/database/sqlite.workerd.ts",
|
||||
"bun": "./src/database/sqlite.bun.ts",
|
||||
"node": "./src/database/sqlite.node.ts",
|
||||
"default": "./src/database/sqlite.bun.ts"
|
||||
"default": "./src/database/sqlite.node.ts"
|
||||
},
|
||||
"#pty": {
|
||||
"bun": "./src/pty/pty.bun.ts",
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, test } from "bun:test"
|
||||
import type { BunPlugin } from "bun"
|
||||
import { join } from "path"
|
||||
|
||||
// Pins the #sqlite subpath-import condition gate: bundling database.ts for a
|
||||
// non-Bun runtime must never reach the static `import "bun:sqlite"` in
|
||||
// sqlite.bun.ts, which crashes workerd (and any other non-Bun bundle) at
|
||||
// module load. Bare imports are externalized so only core-relative modules —
|
||||
// including the #sqlite resolution under test — end up in the bundle.
|
||||
const externalizeBare: BunPlugin = {
|
||||
name: "externalize-bare",
|
||||
setup(build) {
|
||||
build.onResolve({ filter: /^[^.#/]/ }, (args) => ({ path: args.path, external: true }))
|
||||
},
|
||||
}
|
||||
|
||||
const bundle = async (conditions: Array<string>) => {
|
||||
const result = await Bun.build({
|
||||
// join over URL.pathname: on Windows the latter yields "/C:/..." which
|
||||
// module resolution rejects.
|
||||
entrypoints: [join(import.meta.dir, "../src/database/database.ts")],
|
||||
target: "browser",
|
||||
conditions,
|
||||
plugins: [externalizeBare],
|
||||
throw: false,
|
||||
})
|
||||
expect(result.logs).toEqual([])
|
||||
expect(result.success).toBe(true)
|
||||
return result.outputs[0].text()
|
||||
}
|
||||
|
||||
// Skipped on Windows: Bun.build inside `bun test` reliably panics Bun 1.3.14
|
||||
// there ("Internal assertion failure", twice in a row on CI, always at this
|
||||
// file). The assertions pin platform-independent package.json condition
|
||||
// resolution, so Linux coverage loses nothing.
|
||||
describe.skipIf(process.platform === "win32")("sqlite bundle conditions", () => {
|
||||
test("workerd conditions select the Durable Object driver and never bun:sqlite", async () => {
|
||||
const output = await bundle(["workerd"])
|
||||
expect(output).not.toContain("bun:sqlite")
|
||||
expect(output).not.toContain("node:sqlite")
|
||||
expect(output).toContain("SqliteWorkerd")
|
||||
})
|
||||
|
||||
test("default conditions fall back to node:sqlite, not bun:sqlite", async () => {
|
||||
const output = await bundle([])
|
||||
expect(output).not.toContain("bun:sqlite")
|
||||
expect(output).toContain("SqliteNode")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user