fix(agent-hooks): keep Node 18 relay companion loadable (#13135)

Co-authored-by: Jinwoo-H <Jinwoo-H@users.noreply.github.com>
This commit is contained in:
Jinwoo Hong
2026-08-08 01:55:06 -04:00
committed by Jinwoo-H
co-authored by Jinwoo-H
parent 5f3d5950d0
commit 985dbec060
5 changed files with 207 additions and 3 deletions
+11 -3
View File
@@ -1,8 +1,6 @@
import { existsSync } from 'node:fs'
import { DatabaseSync, type StatementSync, type SQLInputValue } from 'node:sqlite'
import type { DatabaseSync, StatementSync, SQLInputValue } from 'node:sqlite'
// Why: keep existing synchronous DB call sites on a tiny adapter while using
// Electron's built-in Node SQLite instead of a third-party native addon.
type SqlitePath = ConstructorParameters<typeof DatabaseSync>[0]
type SyncDatabaseOptions = {
@@ -17,6 +15,15 @@ type PragmaOptions = {
export type SqliteStatement = StatementSync
// Why: SSH companions target Node 18 and import this adapter without opening SQLite.
function loadDatabaseSync(): typeof DatabaseSync {
if (typeof process.getBuiltinModule !== 'function') {
throw new Error('node:sqlite is unavailable in this Node.js runtime')
}
return (process.getBuiltinModule('node:sqlite') as { DatabaseSync: typeof DatabaseSync })
.DatabaseSync
}
class SyncDatabase {
private readonly db: DatabaseSync
@@ -29,6 +36,7 @@ class SyncDatabase {
) {
throw new Error(`SQLite database does not exist: ${path}`)
}
const DatabaseSync = loadDatabaseSync()
this.db = new DatabaseSync(path, {
readOnly: options.readonly,
timeout: options.timeout