From 413ede2487d7bdf454cc95cf0a435a1f21f4818a Mon Sep 17 00:00:00 2001 From: Gremlin Date: Thu, 19 Mar 2026 17:37:13 +0000 Subject: [PATCH] build: strip macOS Electron binaries after pack --- package.json | 1 + scripts/strip-macos-binaries.js | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 scripts/strip-macos-binaries.js diff --git a/package.json b/package.json index 2411ef8..3449308 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "electronLanguages": [ "en" ], + "afterPack": "./scripts/strip-macos-binaries.js", "files": [ "src/**/*", "assets/**/*", diff --git a/scripts/strip-macos-binaries.js b/scripts/strip-macos-binaries.js new file mode 100644 index 0000000..f0c2b0d --- /dev/null +++ b/scripts/strip-macos-binaries.js @@ -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}`); + } + } +};