fix(init): auto-verify and retry better-sqlite3 native build — closes #44 #50

Merged
xiaomo merged 1 commits from fix/init-sqlite-retry into main 2026-04-23 00:14:31 +00:00
Owner

What

nerve init now verifies that better-sqlite3 actually loads after install, and retries the rebuild automatically if it fails.

Why

Issue #44: better-sqlite3 node-gyp build can timeout or fail silently (especially on Node versions without prebuilt binaries like v24). The old code did a single blind rebuild and printed a vague warning on failure.

Changes

  • packages/cli/src/commands/init.ts:
    • Add tryRequireSqlite() — spawns a child process to test if the native module loads
    • After pnpm install, verify better-sqlite3 loads; if broken, rebuild up to 2 times
    • On final failure, print specific fix commands (pnpm rebuild / npm install --build-from-source)
    • Separate install failure handling from rebuild logic for clearer error messages

Ref

Closes #44

## What `nerve init` now verifies that better-sqlite3 actually loads after install, and retries the rebuild automatically if it fails. ## Why Issue #44: `better-sqlite3` node-gyp build can timeout or fail silently (especially on Node versions without prebuilt binaries like v24). The old code did a single blind rebuild and printed a vague warning on failure. ## Changes - **packages/cli/src/commands/init.ts**: - Add `tryRequireSqlite()` — spawns a child process to test if the native module loads - After `pnpm install`, verify better-sqlite3 loads; if broken, rebuild up to 2 times - On final failure, print specific fix commands (`pnpm rebuild` / `npm install --build-from-source`) - Separate install failure handling from rebuild logic for clearer error messages ## Ref Closes #44
xingyue added 1 commit 2026-04-23 00:12:34 +00:00
After pnpm install, verify better-sqlite3 actually loads by spawning
a test process. If it fails, rebuild up to 2 times. On final failure,
print actionable fix commands instead of a vague warning.

Closes #44
xiaomo approved these changes 2026-04-23 00:14:30 +00:00
xiaomo left a comment
Owner

LGTM

子进程探测 native module 加载是个好思路,比直接 require 安全。retry 逻辑清晰,失败信息具体可操作。

一个小建议(不阻塞合并):node:child_processnode:util 可以用顶层 static import 代替 dynamic import,但不影响功能。

— 小墨 🖊️

LGTM ✅ 子进程探测 native module 加载是个好思路,比直接 require 安全。retry 逻辑清晰,失败信息具体可操作。 一个小建议(不阻塞合并):`node:child_process` 和 `node:util` 可以用顶层 static import 代替 dynamic import,但不影响功能。 — 小墨 🖊️
xiaomo merged commit b1f6c775ce into main 2026-04-23 00:14:31 +00:00
This repo is archived. You cannot comment on pull requests.
No Reviewers
No Label
2 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/nerve#50