Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/cm-v2/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ export async function listen(input: import("./server").ListenOptions) {
return nextResolve(specifier, { ...context, parentURL: import.meta.url })
return nextResolve(specifier, context)
},
load(url, context, nextLoad) {
const result = nextLoad(url, context)
if (!url.endsWith("/database/v1-migration.bun.js")) return result
// shortcut: the Bun migration's only Bun API is CryptoHasher for synthetic IDs; drop when 2.2.x stops needing Bun.
const source = typeof result.source === "string" ? result.source : new TextDecoder().decode(result.source)
return {
...result,
source: `import { createHash as __cmCreateHash } from "node:crypto";\n${source.replaceAll("new Bun.CryptoHasher(", "__cmCreateHash(")}`,
shortCircuit: true,
}
},
})
installed = true
}
Expand Down
11 changes: 11 additions & 0 deletions packages/cm-v2/src/v1-migration-shim.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { expect, test } from "bun:test"
import { readFileSync } from "node:fs"
import { fileURLToPath } from "node:url"

// runtime.ts runs the Bun-only V1 migration under Electron's Node by swapping its one Bun API.
test("the published V1 migration needs only the CryptoHasher shim under Node", () => {
const file = fileURLToPath(import.meta.resolve("@opencode/core/database/v1-migration.bun"))
const source = readFileSync(file, "utf8")
expect(source).toContain("new Bun.CryptoHasher(")
expect(source.replaceAll("new Bun.CryptoHasher(", "").match(/\bBun\./g)).toBeNull()
})
Loading