clients/apps/desktop/scripts/before-pack.js
aj-bw 2e6cbf4be1
[bre-1650] update electron-builder and update MacOS installer UI background (#19558)
* add updated background and background2x images, remove old image

* update build instructions with background file location

* test bumping electron-builder version to resolve bug

* drop electron-builder version to earliest with the background fix, newer version had breakage

* attempt to resolve build errors due to dep changes including prebuild files to be bundled with other platform types

* fix macos universal build conflicts due electron builder bump

* simplify approach, push to ci for further testing after local tests hit some arch friction

* pulling in @abergs change from PR#18474 to fix the same issue

* add identifier name, add desktop_napi version to see if that resolve it not being found during ci build

* address changes in getTreeFromWorkspaces in electron-builder

* bump electron-builder version further up to resolve dep getTreeFromWorkspaces resolution issue

* update pack script to work around bug during intermediate signing process for mac MAS app

* updated background resources, arrow moved up slightly. assets provided by design team

* electron-builder 26.8.2's collector only bundles modules found in _dependencies (from npm list). Workspace members must be explicitly declared as dependencies to appear there — the workspaces array alone is not sufficient. Without this, desktop-napi is silently missing from the asar on all platforms.

* filter by platform and arch

* update before pack script

* revert before-pack change, update x64 arch files in EB json

* fix linting fail due to missing dep, fix matching logic
2026-03-26 08:59:46 -04:00

37 lines
1.3 KiB
JavaScript

/* eslint-disable no-console */
/** @import { BeforePackContext } from 'app-builder-lib' */
exports.default = run;
/**
* @param {BeforePackContext} context
*/
async function run(context) {
console.log("## before pack");
console.log("Stripping .node files that don't belong to this platform...");
removeExtraNodeFiles(context);
}
/**
* Removes .node files for platforms other than the current target platform.
*
* Architecture-specific filtering is intentionally NOT done here. During macOS
* universal builds, @electron/universal requires all non-asar files to be
* present in both the x64 and arm64 per-arch builds. The `singleArchFiles`
* and `x64ArchFiles` options in electron-builder.json handle arch-specific
* .node files during the universal merge phase instead.
*
* @param {BeforePackContext} context
*/
function removeExtraNodeFiles(context) {
const packagerPlatform = context.packager.platform.nodeName;
const platforms = ["darwin", "linux", "win32"];
const fileFilter = context.packager.info._configuration.files[0].filter;
for (const platform of platforms) {
if (platform != packagerPlatform) {
fileFilter.push(`!node_modules/@bitwarden/desktop-napi/desktop_napi.${platform}-*.node`);
fileFilter.push(`!node_modules/**/prebuilds/${platform}-*/*.node`);
}
}
}