feat: add async SQLite on Node 24 and improve messaging diagnostics (#520)
Move database work off the main thread on Node.js 24 and improve message handling and runtime diagnostics. Preserve migration, restart, and concurrency coverage with the async SQLite driver.
This commit is contained in:
1 parent
20f48d11ec
commit
c7428363cb
170 files changed
+7748
-3913
No files matched your search
@@ -5,6 +5,7 @@ import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { defineConfig, PluginOption, UserConfig } from 'vite';
|
||||
import cp from 'vite-plugin-cp';
|
||||
import { sqliteBuildPlugin } from '@snowluma/sqlite/vite';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const repoRoot = path.resolve(__dirname, '..', '..');
|
||||
@@ -24,13 +25,6 @@ const toPosix = (p: string) => p.replace(/\\/g, '/');
|
||||
// in-tree TS workspace wrapper that routes its native `.node`
|
||||
// addon through `dist/native/`. Only Node builtins stay external.
|
||||
//
|
||||
// `node:sqlite` is an experimental builtin that Node 22.x lines don't
|
||||
// list in `builtinModules`, so the `nodeModules` sweep below misses it.
|
||||
// Externalise it explicitly — otherwise Vite bundles it and swaps in a
|
||||
// browser shell, crashing the hook with `DatabaseSync is not a
|
||||
// constructor` (the bug PR #68 set out to fix).
|
||||
const external: string[] = ['node:sqlite', 'sqlite'];
|
||||
|
||||
const nodeModules = [...builtinModules, ...builtinModules.map((m) => `node:${m}`)].flat();
|
||||
|
||||
const runtimeSrc = toPosix(runtimeDir);
|
||||
@@ -108,6 +102,7 @@ const BaseConfigPlugin: PluginOption[] = [
|
||||
// before `cp` so the transform runs on every source file Vite asks
|
||||
// for, regardless of where `cp` later copies emitted assets.
|
||||
protobufVitePlugin(),
|
||||
sqliteBuildPlugin(targetTriple),
|
||||
cp({
|
||||
targets: [
|
||||
...runtimeDistFiles.map((file) => ({
|
||||
@@ -146,7 +141,7 @@ const BaseConfig = (source_map: boolean = false) =>
|
||||
},
|
||||
build: {
|
||||
sourcemap: source_map,
|
||||
target: 'esnext',
|
||||
target: 'node24',
|
||||
minify: false,
|
||||
lib: {
|
||||
entry: {
|
||||
@@ -156,22 +151,9 @@ const BaseConfig = (source_map: boolean = false) =>
|
||||
fileName: (_, entryName) => `${entryName}.mjs`,
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [...nodeModules, ...external],
|
||||
external: nodeModules,
|
||||
output: {
|
||||
// better-sqlite3's JS wrapper is pure CJS — its `require('fs')` /
|
||||
// `require('path')` / `require('bindings')` calls get inlined into
|
||||
// the ESM bundle as `__require("fs")` shims by rolldown. Those
|
||||
// shims gate on `typeof require !== "undefined"`, which is true
|
||||
// in CJS but FALSE in our `.mjs` output, so they fall through to
|
||||
// a runtime `throw Error("Calling \`require\` ... in an environment
|
||||
// that doesn't expose the \`require\` function.")` on first call —
|
||||
// crashing the launcher immediately.
|
||||
//
|
||||
// Defining a module-scope `require` via `createRequire(import.meta.url)`
|
||||
// at the very top of the bundle satisfies the `typeof` check, and
|
||||
// the shim then transparently delegates every inlined CJS require
|
||||
// to the real CJS loader. Node 18+ ships `createRequire` in the
|
||||
// `node:module` builtin, so this is supported on every target.
|
||||
// Bundled CommonJS dependencies still need Node's native require.
|
||||
banner: [
|
||||
"import { createRequire as __snowlumaCreateRequire } from 'node:module';",
|
||||
'const require = __snowlumaCreateRequire(import.meta.url);',
|
||||
|
||||
Reference in new issue
Block a user