fix(desktop): upgrade better-sqlite3 to 13 so the Electron 43 installer builds and opens its database

better-sqlite3 12.8.0 has no prebuild for Electron 43 (ABI 148) and does not compile against
its V8 API, so the v1.18.0 installer build stopped in fix-native-abi and was never published.
13.2.0 ships Node-API prebuilds in the package; one binary runs on Node and Electron.

- fix-native-abi.mjs: nothing to swap when the packaged module is a Node-API prebuild.
- verify-native-abi.mjs: require the target prebuild, fail on a shadowing build/Release binary,
  and open a database through the packaged module.
- electron-builder: leave out the linux prebuilds we do not ship.

Verified: desktop 2,933 tests on Node 24, and WAL/transaction/FTS5 queries in an Electron
43.8.10 main process.
This commit is contained in:
Yun Chan 2026-11-20 15:30:08 +09:00
parent a117bc0d09
commit fb5f76f57f
9 changed files with 88 additions and 255 deletions

View file

@ -51,6 +51,18 @@ const targetBinary = inPlace
? join(root, relativeBinary)
: join(packagedDir, 'resources', 'app.asar.unpacked', relativeBinary)
// better-sqlite3 13 부터는 Node-API 프리빌드(prebuilds/<platform>-<arch>.node)가 패키지에 들어 있다.
// Node-API 바이너리는 런타임 ABI(NODE_MODULE_VERSION)에 묶이지 않아 Node 와 Electron 이 같은 파일을 쓴다 —
// 교체할 것이 없다. (12 이하는 Electron 43(ABI 148)용 프리빌드가 없고 소스 빌드도 V8 API 변경으로 실패한다.)
const moduleRoot = inPlace
? join(root, 'node_modules', 'better-sqlite3')
: join(packagedDir, 'resources', 'app.asar.unpacked', 'node_modules', 'better-sqlite3')
const napiPrebuild = join(moduleRoot, 'prebuilds', `${process.platform}-${arch}.node`)
if (!existsSync(targetBinary) && existsSync(napiPrebuild)) {
console.log(`[native-abi] better-sqlite3 는 Node-API 프리빌드입니다 — ABI 교체 불필요 (${napiPrebuild})`)
process.exit(0)
}
if (!existsSync(targetBinary)) {
console.error(`[native-abi] 패키징 트리에 better-sqlite3 바이너리가 없습니다: ${targetBinary}`)
process.exit(1)

View file

@ -150,7 +150,48 @@ const REQUIRED_ELECTRON_ABI = [
const failures = []
const notes = []
const packagedTarget = inferPackagedTarget(packagedDir)
/**
* better-sqlite3 13+ 는 Node-API 프리빌드를 패키지에 싣는다 (prebuilds/<platform>-<arch>.node).
* Node-API 는 런타임 ABI 에 묶이지 않으므로 "호스트 Node 가 거부해야 통과" 규칙이 뒤집힌다:
* 대상 플랫폼 프리빌드가 있어야 하고, 호스트와 같은 플랫폼이면 실제로 열어 질의까지 해 본다.
* build/Release 바이너리가 함께 있으면 로더가 그것을 먼저 집으므로(옛 ABI 종속 빌드) 실패로 본다.
*/
function verifyNapiSqlite(moduleDir) {
const prebuild = join(moduleDir, 'prebuilds', `${packagedTarget.platform}-${packagedTarget.arch}.node`)
if (!existsSync(prebuild)) return null
if (existsSync(join(moduleDir, 'build', 'Release', 'better_sqlite3.node'))) {
return { failure: 'better-sqlite3: Node-API 프리빌드와 build/Release 바이너리가 함께 있습니다 — 로더가 옛 빌드를 먼저 집습니다.' }
}
if (packagedTarget.platform !== process.platform || packagedTarget.arch !== process.arch) {
return { note: `better-sqlite3: ${packagedTarget.platform}-${packagedTarget.arch} Node-API 프리빌드 존재 확인` }
}
const probe = spawnSync(
process.execPath,
[
'-e',
`const D=require(${JSON.stringify(moduleDir)});const d=new D(':memory:');` +
`if(d.prepare('select 1 as one').get().one!==1)process.exit(3);d.close()`,
],
{ encoding: 'utf8' },
)
if (probe.status !== 0) {
const output = `${probe.stdout ?? ''}${probe.stderr ?? ''}`.trim().split(String.fromCharCode(10)).slice(0, 3).join(' | ')
return { failure: `better-sqlite3: 패키징된 Node-API 모듈이 열리지 않습니다 → ${output}` }
}
return { note: 'better-sqlite3: 패키징된 Node-API 모듈로 DB 를 열고 질의함 (런타임 ABI 무관)' }
}
for (const module of REQUIRED_ELECTRON_ABI) {
if (module.name === 'better-sqlite3') {
const napi = verifyNapiSqlite(join(unpackedRoot, 'better-sqlite3'))
if (napi) {
if (napi.failure) failures.push(napi.failure)
else notes.push(napi.note)
continue
}
}
const binaryPath = join(unpackedRoot, module.binary)
if (!existsSync(binaryPath)) {
failures.push(`${module.name}: 패키징된 네이티브 바이너리가 없습니다 → ${binaryPath}`)
@ -183,8 +224,7 @@ for (const module of REQUIRED_ELECTRON_ABI) {
}
}
const target = inferPackagedTarget(packagedDir)
const napiResults = requiredNapiResults(unpackedRoot, target)
const napiResults = requiredNapiResults(unpackedRoot, packagedTarget)
failures.push(...napiResults.failures)
notes.push(...napiResults.notes)