@compilr-dev/sdk 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Uses better-sqlite3 (optional peer dependency).
|
|
5
5
|
* Consumers must install better-sqlite3 to use the SQLite repositories.
|
|
6
6
|
*/
|
|
7
|
+
import { createRequire } from 'module';
|
|
7
8
|
import * as fs from 'fs';
|
|
8
9
|
import * as path from 'path';
|
|
9
10
|
import { SCHEMA_SQL, SCHEMA_VERSION } from './schema.js';
|
|
@@ -17,9 +18,10 @@ export function getDatabase(dbPath) {
|
|
|
17
18
|
const existing = instances.get(dbPath);
|
|
18
19
|
if (existing)
|
|
19
20
|
return existing;
|
|
20
|
-
// Dynamic require of better-sqlite3 — it's an optional peer dep
|
|
21
|
-
//
|
|
22
|
-
const
|
|
21
|
+
// Dynamic require of better-sqlite3 — it's an optional peer dep.
|
|
22
|
+
// Use createRequire() for ESM compatibility (works in Node.js and Electron).
|
|
23
|
+
const esmRequire = createRequire(import.meta.url);
|
|
24
|
+
const BetterSqlite3 = esmRequire('better-sqlite3');
|
|
23
25
|
// Ensure directory exists
|
|
24
26
|
fs.mkdirSync(path.dirname(dbPath), { recursive: true });
|
|
25
27
|
const db = new BetterSqlite3(dbPath);
|