fix(desktop): hide bun:sqlite import from Node.js/Electron ESM loader

Uses new Function() to prevent the static ESM loader from seeing
the bun: protocol import at parse time. In Electron/Node.js, the
import() call is evaluated at runtime and gracefully returns null
when bun:sqlite is unavailable.

Fixes #3829, likely fixes #3762
This commit is contained in:
herjarsa
2026-05-07 10:38:31 +02:00
parent 10f9559ccc
commit 3a93a40e68
2 changed files with 23 additions and 3 deletions
@@ -13,7 +13,9 @@ describe("scheduleDeferredModelOverride bun:sqlite unavailable", () => {
//#then
expect(hasStaticBunSqliteImport).toBe(false)
expect(source).toContain('await import("bun:sqlite").catch(() => null)')
// new Function() hides the bun: import from Node.js/Electron static ESM loader
expect(source).toContain("new Function(\"return import('bun:sqlite')\")")
expect(source).toContain("typeof globalThis.Bun === \"undefined\"")
expect(source).toContain("bun:sqlite unavailable")
expect(source).toContain("return")
})