fix: probe SQLite when Node denies worker threads (#152075)

This commit is contained in:
Peter Steinberger
2026-09-18 13:43:21 -07:00
committed by GitHub
parent f953dbdf47
commit d2a5196a2f
2 changed files with 86 additions and 3 deletions
+8 -3
View File
@@ -56,12 +56,17 @@ function isSqliteCapabilities(value) {
);
}
async function probeCurrentSqliteInWorker() {
async function probeCurrentSqlite() {
let worker;
try {
if (typeof process.getBuiltinModule?.("node:sqlite")?.DatabaseSync !== "function") {
const DatabaseSync = process.getBuiltinModule?.("node:sqlite")?.DatabaseSync;
if (typeof DatabaseSync !== "function") {
return unavailableSqliteCapabilities(new Error("node:sqlite is unavailable"));
}
// Keep the real capability check when Node's permission policy forbids workers.
if (!process.versions.bun && process.permission?.has("worker") === false) {
return probeSqlite(DatabaseSync);
}
const env = Object.fromEntries(
Object.entries(process.env).filter(([name]) => !/^(NODE_OPTIONS|BUN_OPTIONS)$/i.test(name)),
);
@@ -126,7 +131,7 @@ async function probeCurrentSqliteInWorker() {
export function detectCurrentSqliteCapabilities() {
// Publish the Promise before Worker construction can notify another startup caller.
globalThis[capabilityCacheKey] ??= Promise.resolve().then(probeCurrentSqliteInWorker);
globalThis[capabilityCacheKey] ??= Promise.resolve().then(probeCurrentSqlite);
return Promise.resolve(globalThis[capabilityCacheKey]);
}