fix: use dynamic import for node:sqlite with Node version guard
Replace static top-level import with runtime version check and dynamic import() so Node < 22.5 gracefully falls back to CLI path instead of crashing at module load time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { DatabaseSync } from 'node:sqlite'
|
||||
import { getActiveProfileDir } from './hermes-profile'
|
||||
|
||||
const SQLITE_AVAILABLE = (() => {
|
||||
const [major, minor] = process.versions.node.split('.').map(Number)
|
||||
return major > 22 || (major === 22 && minor >= 5)
|
||||
})()
|
||||
|
||||
export interface HermesSessionRow {
|
||||
id: string
|
||||
source: string
|
||||
@@ -115,6 +119,11 @@ const BASE_SELECT = `
|
||||
`
|
||||
|
||||
export async function listSessionSummaries(source?: string, limit = 2000): Promise<HermesSessionRow[]> {
|
||||
if (!SQLITE_AVAILABLE) {
|
||||
throw new Error(`node:sqlite requires Node >= 22.5, current: ${process.versions.node}`)
|
||||
}
|
||||
|
||||
const { DatabaseSync } = await import('node:sqlite')
|
||||
const db = new DatabaseSync(sessionDbPath(), { open: true, readOnly: true })
|
||||
|
||||
try {
|
||||
|
||||
@@ -6,7 +6,7 @@ const closeMock = vi.fn()
|
||||
const databaseSyncMock = vi.fn(() => ({ prepare: prepareMock, close: closeMock }))
|
||||
const getActiveProfileDirMock = vi.fn(() => '/tmp/hermes-profile')
|
||||
|
||||
vi.mock('node:sqlite', () => ({
|
||||
vi.doMock('node:sqlite', () => ({
|
||||
DatabaseSync: databaseSyncMock,
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user