Skip to content

fix: support for bun/deno via node codepath #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
26 changes: 24 additions & 2 deletions sqlite-wasm/jswasm/sqlite3-bundler-friendly.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ var sqlite3InitModule = (() => {
typeof process.versions == 'object' &&
typeof process.versions.node == 'string' &&
process.type != 'renderer';
var ENVIRONMENT_IS_BUN =
!!globalThis.Bun;
var ENVIRONMENT_IS_DENO =
!!globalThis.Deno;
var ENVIRONMENT_IS_NODE_COMPATIBLE =
ENVIRONMENT_IS_NODE ||
ENVIRONMENT_IS_BUN ||
ENVIRONMENT_IS_DENO;
var ENVIRONMENT_IS_SHELL =
!ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
!ENVIRONMENT_IS_WEB &&
!ENVIRONMENT_IS_NODE_COMPATIBLE &&
!ENVIRONMENT_IS_WORKER;

const sqlite3InitModuleState =
globalThis.sqlite3InitModuleState ||
Expand Down Expand Up @@ -129,7 +139,19 @@ var sqlite3InitModule = (() => {
});
};
}
} else {
} else if (ENVIRONMENT_IS_NODE_COMPATIBLE) {
readAsync = (filename, binary = true) => {
filename = isFileURI(filename)
? new URL(filename)
: nodePath.normalize(filename);
return new Promise((resolve, reject) => {
const { readFile } = require("node:fs");
readFile(filename, binary ? undefined : 'utf8', (err, data) => {
if (err) reject(err);
else resolve(binary ? data.buffer : data);
});
});
}
}

var out = Module['print'] || console.log.bind(console);
Expand Down