build: strip macOS Electron binaries after pack
All checks were successful
electron-linux-amd64 / electron-linux-amd64 (push) Successful in 2m10s
electron-macos-arm64 / electron-macos-arm64 (push) Successful in 4m26s

This commit is contained in:
Gremlin 2026-03-19 17:37:13 +00:00
parent 84f3282bbd
commit 413ede2487
2 changed files with 40 additions and 0 deletions

View File

@ -22,6 +22,7 @@
"electronLanguages": [
"en"
],
"afterPack": "./scripts/strip-macos-binaries.js",
"files": [
"src/**/*",
"assets/**/*",

View File

@ -0,0 +1,39 @@
const { execFileSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
function walk(dir, out = []) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) walk(full, out);
else out.push(full);
}
return out;
}
function isMachO(file) {
try {
const out = execFileSync('file', ['-b', file], { encoding: 'utf8' });
return out.includes('Mach-O');
} catch {
return false;
}
}
exports.default = async function afterPack(context) {
if (context.electronPlatformName !== 'darwin') return;
const appOutDir = context.appOutDir;
const appName = `${context.packager.appInfo.productFilename}.app`;
const appPath = path.join(appOutDir, appName);
const targets = walk(appPath).filter(isMachO);
for (const file of targets) {
try {
execFileSync('strip', ['-x', file], { stdio: 'inherit' });
} catch (err) {
console.warn(`[strip] skipped ${file}: ${err.message}`);
}
}
};