Skip to content

Commit 11b3de8

Browse files
iamtorukaaronflorey
authored andcommitted
fix(sqlite): load node:sqlite in ESM runtime
Replace eval-based require with createRequire(import.meta.url) so the SQLite driver loads correctly when the CLI runs as ESM. This restores OpenCode and Cursor session discovery instead of returning empty results when require is unavailable.
1 parent 82df214 commit 11b3de8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/sqlite.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import { createRequire } from 'node:module'
2+
13
/// Thin SQLite read-only wrapper over Node's built-in `node:sqlite` module (stable in
24
/// Node 24, experimental in Node 22 / 23). Replaces the earlier `better-sqlite3` binding
35
/// so the dependency graph no longer pulls in the deprecated `prebuild-install` package
46
/// (issue #75). Works across Cursor and OpenCode session DBs, both of which we only read.
57

8+
const requireForSqlite = createRequire(import.meta.url)
9+
610
type Row = Record<string, unknown>
711

812
export type SqliteDatabase = {
@@ -55,10 +59,7 @@ function loadDriver(): boolean {
5559
} as typeof process.emit
5660

5761
try {
58-
// Dynamic require via createRequire avoids TypeScript chasing types we don't need at
59-
// build time (node:sqlite landed in @types/node much later than in Node itself).
60-
// eslint-disable-next-line @typescript-eslint/no-require-imports
61-
const mod = eval('require')('node:sqlite') as { DatabaseSync: DatabaseSyncCtor }
62+
const mod = requireForSqlite('node:sqlite') as { DatabaseSync: DatabaseSyncCtor }
6263
DatabaseSync = mod.DatabaseSync
6364
return true
6465
} catch (err) {

0 commit comments

Comments
 (0)