fix: stage rebuilt better-sqlite3 for Electron packaging

Rebuilds better-sqlite3 separately for Electron before packaging
Copies the native binary into the packaged app resources
Updates packaging docs to explain the afterPack workaround
This commit is contained in:
Bohdan Triapitsyn
2026-07-28 14:05:03 +03:00
parent fbc064c16f
commit 92abdefea8
3 changed files with 35 additions and 5 deletions
+14 -1
View File
@@ -133,6 +133,19 @@ const ensureWindowsNodeAddonApiForNodePty = async (rebuildRootPath) => {
console.log(`[electron] rebuilding native modules against Electron ${electronVersion}...`);
await rebuild({
buildPath: electronDir,
electronVersion,
force: true,
arch: targetArchitecture.electronBuilder,
onlyModules: ['better-sqlite3'],
});
const betterSqliteDir = path.dirname(require.resolve('better-sqlite3/package.json'));
const betterSqliteBinary = path.join(betterSqliteDir, 'build', 'Release', 'better_sqlite3.node');
if (!existsSync(betterSqliteBinary)) {
throw new Error(`better-sqlite3 rebuild did not produce ${betterSqliteBinary}`);
}
// Rebuild against the hoisted root node_modules (bun workspace layout).
// force=true re-links regardless of cached state; prebuild-install lookup is
// bypassed by @electron/rebuild in favor of direct node-gyp builds.
@@ -145,7 +158,7 @@ try {
electronVersion,
force: true,
arch: targetArchitecture.electronBuilder,
onlyModules: ['better-sqlite3', 'node-pty', 'bun-pty'],
onlyModules: ['node-pty', 'bun-pty'],
});
} finally {
try {