feat(cache)!: migrate from better-sqlite3 to node:sqlite; require Node 24 - #96
Merged
Conversation
…e 24 Replace the better-sqlite3 native addon with Node's built-in node:sqlite module and raise engines.node to >=24.0.0 (first release where node:sqlite is non-experimental). The on-disk cache format is unchanged; a fixture database written by better-sqlite3 12.11.1 (WAL mode, user_version = 1) is committed and read back as a permanent back-compat regression guard. The production dependency tree no longer contains any native addon, removing the ABI-mismatch failure class (ERR_DLOPEN_FAILED after a Node major upgrade), a 1.9 MB platform-specific binary, and the compilation toolchain requirement. The cacheless-degradation safety net now guards node:sqlite absence (Node < 22.5.0) instead of native-binding failures. BREAKING CHANGE: Node.js >= 24.0.0 is now required. Node 18/20 lack node:sqlite entirely; Node 22 emits an ExperimentalWarning and bundles an older SQLite (3.50.4). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
better-sqlite3native addon with Node's built-innode:sqlitemodule and raisesengines.nodeto>=24.0.0. This removes the last native module from the production dependency tree, eliminating the ABI-mismatch failure class (ERR_DLOPEN_FAILEDafter a Node major upgrade, e.g.brew upgrade node) before the first npm publish — no published version will ever have carried the native dependency.Closes the transitional inconsistency where
engines.node(>=20.19.0) disagreed with commander 15's>=22.12.0: the engines bump lands together with the code that requires it.Changes Made
src/storage/cache.ts— swappedbetter-sqlite3'sDatabasefornode:sqlite'sDatabaseSync.prepare/exec/closemap 1:1; the three.pragma()call sites (the only API gap) becomeexec('PRAGMA …')for writes andprepare('PRAGMA user_version').get()for the read. No behavior change otherwise.package.json— removedbetter-sqlite3and@types/better-sqlite3;engines.nodeis now>=24.0.0.tests/fixtures/cache-better-sqlite3.db(new, force-added past the*.dbignore) — a cache database generated by better-sqlite3 12.11.1 / SQLite 3.53.2 mirroring the real on-disk layout: WAL journal mode,user_version = 1, three entries.tests/unit/cache-backcompat.test.ts(new) — opens the fixture with the new backend: no corruption quarantine, all entries readable, stats accurate, mixed old/new writes, close/reopen cycle.tests/unit/cache-native-failure.test.ts— backend mock retargeted frombetter-sqlite3tonode:sqlite'sDatabaseSync; the load-failure-vs-corruption classification cases are unchanged.tests/e2e/cli-cache-degraded.e2e.test.ts— the subprocess module-resolution hijack now interceptsnode:sqliteand throws the realisticERR_UNKNOWN_BUILTIN_MODULE(verifiedregisterHooksintercepts builtin specifiers in both CJS and ESM).tests/unit/cache-service.test.ts— three tests that reached into the privatedbhandle via.pragma()now use thenode:sqliteAPI.src/cli/cache-loader.ts, CLAUDE.md — comment/architecture references updated. README/TROUBLESHOOTING native-module sections are deliberately NOT touched here — they are deleted by the docs issue, which is dependency-ordered after this change.Test Coverage
node:sqlitewarns once and runs cacheless without touching the database.npm auditat 0 vulnerabilities;npm pack --dry-runshows 0 internal-name hits, 0.mapfiles, README + LICENSE present;npm ls --omit=devconfirms no native module remains.Backward Compatibility
❌ Breaking: Node.js >= 24.0.0 is now required (hence v2.0.0). Node 18/20 lack
node:sqliteentirely; Node 22 emits anExperimentalWarningon every invocation and bundles an older SQLite (3.50.4 vs 3.53.1).✅ Cache data fully preserved: the on-disk format is unchanged; existing databases (including WAL sidecars and the
user_versionstamp) are read in place with no migration.✅ Degradation behavior preserved: backend-load failure still degrades to cacheless operation with a single warning and never touches the database.
Size: Medium ✓
Small mechanical diff in
cache.ts(one import, three pragma call sites), but it carries the engines bump, a dependency removal, a committed binary fixture, and four test-file updates that must land atomically.🤖 Generated with Claude Code