From 554ee2aecbb32ad80703fbe3edb4c21d6271fe8e Mon Sep 17 00:00:00 2001 From: mrsibe Date: Wed, 30 Sep 2026 13:40:20 +0800 Subject: [PATCH] deps(better-sqlite3): move to the N-API 13.x line and stop ABI rebuilds better-sqlite3 12.11.1 -> 13.0.3. Why this is not just a version bump: 12.x ships one ABI-specific binary per Electron version and downloads it with prebuild-install. Its published prebuilds stop at electron-v146 (Electron 42). Electron 44 is ABI 149, so `electron-builder install-app-deps` could not find a prebuild and fell back to `node-gyp rebuild --build-from-source`, which needs Python + MSVC. CI runners and Linux have that toolchain, so every CI check passed; a plain Windows dev machine did not, and `npm install` failed with "Could not find any Python installation to use". 13.x is N-API and ships a prebuild per platform/arch inside the npm package itself (prebuilds/win32-x64.node, darwin-arm64.node, ...), with no install script. N-API binaries are stable across Node and Electron versions, so there is nothing left to rebuild. Changes: - `better-sqlite3` -> `^13.0.3`. - Removed the `postinstall` hook. `electron-builder install-app-deps` ignores `npmRebuild` and always rebuilds; with every native dependency now N-API that rebuild can only replace a correct prebuild with a locally compiled one. - `npmRebuild: false` in electron-builder.yml, with the reasoning recorded there. This also means packaging no longer needs a C++ toolchain. - release.yml asserted that `better_sqlite3.node` was unpacked. That filename no longer exists (13.x uses `prebuilds/-.node`), so the check would have failed the first macOS release. It now asserts a `better-sqlite3/prebuilds/*.node` file instead. - CONTRIBUTING: the native-toolchain requirement is gone. - docs/dependency-audit.md: better-sqlite3 is no longer "rebuilt against the Electron ABI and cannot load in plain Node"; SQLite is now 3.53.4, not 3.53.2. Verified on Linux x64 (WSL2): - `npm install` - better-sqlite3 13.0.3 with prebuilds, and no `build/` directory, i.e. nothing was compiled. - `npm run typecheck` - clean; `npm test` - 472/472 pass. - `npm run build:unpack` - "skipped dependencies rebuild reason=npmRebuild is set to false"; the packaged app carries every platform's prebuild. - `npm run smoke:packaged` - 29 checks pass, better-sqlite3 opens the database from the N-API prebuild, FTS5 + bm25() rank, sqlite-vec v0.1.9 loads. Not verified locally, left to CI: macOS arm64 and Windows packaging. The one thing to watch is cross-arch. Rebuilding could never fetch sharp's or @napi-rs/canvas's target-arch prebuilds anyway, so `npmRebuild: false` does not make that worse; better-sqlite3 now carries every platform/arch itself, and the release matrix builds each artifact on its own architecture. Separately noticed while measuring: the packaged onnxruntime-node is ~416 MB, of which ~260 MB is `libonnxruntime_providers_cuda.so`. That predates this change (it is what `npm ci` installs) and is the "ships binaries for the wrong platform" follow-up already recorded in the audit, only larger. --- .github/workflows/release.yml | 11 +- .github/workflows/verify.yml | 2 +- CONTRIBUTING.md | 9 +- build/entitlements.mac.plist | 3 +- docs/dependency-audit.md | 28 ++- electron-builder.yml | 27 ++- package-lock.json | 324 +++------------------------------- package.json | 6 +- src/main/smokeTest.ts | 3 +- 9 files changed, 85 insertions(+), 328 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d92a842..aa46c6d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -176,7 +176,7 @@ jobs: # Inspect the artifact we just shipped. This is the check that was missing # when v1.2.0 went out ad-hoc signed, hardened-runtime, and unable to load - # better_sqlite3.node. + # its native module. - name: Verify macOS artifact (signature, entitlements, native modules) if: matrix.os == 'macos-latest' run: | @@ -220,7 +220,7 @@ jobs: echo "::warning title=Unsigned macOS build::No identity was available, so the bundle carries no entitlements. This build is not notarized and cannot be launched on Apple Silicon until the user clears the quarantine flag; README.md documents the command." else echo "::error::shipped app is missing com.apple.security.cs.disable-library-validation." - echo "::error::It will crash on launch when the main process loads better_sqlite3.node." + echo "::error::It will crash on launch when the main process loads better-sqlite3's native module." exit 1 fi @@ -236,8 +236,11 @@ jobs: echo done - if ! echo "$NATIVES" | grep -q 'better_sqlite3.node'; then - echo "::error::better_sqlite3.node was not unpacked; the database will fail to open" + # better-sqlite3 >= 13 is N-API and ships its binary as + # `prebuilds/-.node`, not the old + # `build/Release/better_sqlite3.node`, and nothing rebuilds it. + if ! echo "$NATIVES" | grep -qE 'better-sqlite3/prebuilds/.+\.node'; then + echo "::error::a better-sqlite3 prebuild was not unpacked; the database will fail to open" exit 1 fi diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml index 70c1f6a..03f1843 100644 --- a/.github/workflows/verify.yml +++ b/.github/workflows/verify.yml @@ -10,7 +10,7 @@ name: Verify # it, so it is the step that actually catches those. It runs on all three # platforms because the native addons are arch-specific: # -# better_sqlite3.node, vec0.so/.dylib/.dll, skia.*.node +# better-sqlite3 (prebuilds/-.node), vec0.so/.dylib/.dll, skia.*.node # # `lint` is deliberately not part of this gate: it reports no errors but still # carries a large pre-existing `@typescript-eslint/no-explicit-any` baseline, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a87f6b9..367398a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,10 +28,11 @@ Requirements: `electron-builder` is built around npm's `node_modules` layout and silently drops transitive dependencies under pnpm. See the `//dependencies` comment in `package.json` for the full story. -- A working native build toolchain. `npm install` runs - `electron-builder install-app-deps` as a `postinstall` step, which compiles - the native addons (`better-sqlite3`, `sqlite-vec`), so the first install - takes a while. +- **No native build toolchain.** Every native dependency is N-API and ships + prebuilt binaries, most of them inside the npm package itself + (`better-sqlite3` >= 13 carries `prebuilds/` for every supported + platform/arch), so `npm install` compiles nothing and `npmRebuild` is off. + See the `npmRebuild` note in `electron-builder.yml`. ```bash git clone https://github.com/MrSibe/KnowNote.git diff --git a/build/entitlements.mac.plist b/build/entitlements.mac.plist index 96f428d..3cf8e87 100644 --- a/build/entitlements.mac.plist +++ b/build/entitlements.mac.plist @@ -10,7 +10,8 @@