diff --git a/bin/package-electron b/bin/package-electron index 4d0f317631c..b827d0015a0 100755 --- a/bin/package-electron +++ b/bin/package-electron @@ -34,8 +34,6 @@ if [ "$OSTYPE" == "msys" ]; then fi fi -yarn rebuild-electron - yarn workspace loot-core build:node yarn workspace @actual-app/web build --mode=desktop @@ -50,10 +48,10 @@ yarn workspace desktop-electron update-client if [ -f ../../.secret-tokens ]; then source ../../.secret-tokens fi - yarn build --publish never --arm64 --x64 + yarn build echo "\nCreated release" else - SKIP_NOTARIZATION=true yarn build --publish never --x64 + SKIP_NOTARIZATION=true yarn build fi ) diff --git a/packages/desktop-electron/beforePackHook.ts b/packages/desktop-electron/beforePackHook.ts new file mode 100644 index 00000000000..3446378e70a --- /dev/null +++ b/packages/desktop-electron/beforePackHook.ts @@ -0,0 +1,36 @@ +import { rebuild } from '@electron/rebuild'; +import { Arch, AfterPackContext } from 'electron-builder'; + +/* The beforePackHook runs before packing the Electron app for an architecture +We hook in here to build anything architecture dependent - such as beter-sqlite3 +To build, we call @electron/rebuild on the better-sqlite3 module */ +const beforePackHook = async (context: AfterPackContext) => { + const arch: string = Arch[context.arch]; + const buildPath = context.packager.projectDir; + const projectRootPath = buildPath + '/../../'; + const electronVersion = context.packager.config.electronVersion; + + if (!electronVersion) { + console.error('beforePackHook: Unable to find electron version.'); + process.exit(); // End the process - electron version is required + } + + try { + await rebuild({ + arch, + buildPath, + electronVersion, + force: true, + projectRootPath, + onlyModules: ['better-sqlite3'], + }); + + console.info(`Rebuilt better-sqlite3 with ${arch}!`); + } catch (err) { + console.error('beforePackHook:', err); + process.exit(); // End the process - unsuccessful build + } +}; + +// eslint-disable-next-line import/no-unused-modules, import/no-default-export +export default beforePackHook; diff --git a/packages/desktop-electron/package.json b/packages/desktop-electron/package.json index 851d28f42ee..327f1990f88 100644 --- a/packages/desktop-electron/package.json +++ b/packages/desktop-electron/package.json @@ -24,26 +24,22 @@ "!node_modules/better-sqlite3/{benchmark,src,bin,docs,deps,build/Release/obj,build/Release/sqlite3.a,build/Release/test_extension.node}", "build" ], - "publish": { - "provider": "github", - "repo": "actual", - "owner": "actualbudget", - "vPrefixedTagName": true - }, + "beforePack": "./build/beforePackHook.js", "mac": { "category": "public.app-category.finance", "icon": "icons/icon.icns", "hardenedRuntime": true, "gatekeeperAssess": false, - "artifactName": "${productName}-mac.${ext}", + "artifactName": "${productName}-mac-${arch}.${ext}", "notarize": { "teamId": "79ANZ983YF" }, "target": [ { - "target": "default", + "target": "dmg", "arch": [ - "universal" + "x64", + "arm64" ] } ] @@ -63,7 +59,8 @@ "target": "nsis", "icon": "icons/icon.ico", "artifactName": "${productName}-windows.${ext}" - } + }, + "npmRebuild": false }, "dependencies": { "electron-is-dev": "2.0.0", diff --git a/upcoming-release-notes/3220.md b/upcoming-release-notes/3220.md new file mode 100644 index 00000000000..4db0be806d4 --- /dev/null +++ b/upcoming-release-notes/3220.md @@ -0,0 +1,7 @@ +--- +category: Bugfix +authors: [MikesGlitch] +--- + +Fix electron builds throwing "We had an unknown problem opening file" +