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