You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bitwarden-clients/apps/desktop/scripts/before-pack.js

37 lines
1.3 KiB

/* 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`);
}
}
}