-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathafterPack.js
More file actions
38 lines (32 loc) · 1.5 KB
/
afterPack.js
File metadata and controls
38 lines (32 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { execSync } from 'child_process';
import path from 'path';
import fs from 'fs';
export default async function afterPack({ appOutDir, packager }) {
const platformName = packager.platform.name;
// Remove Next.js SWC native binaries that don't belong on this target platform.
// They are bundled because `next` is in dependencies, but only the host-platform
// binary is ever used at runtime in the Electron app.
const nextDir = path.join(appOutDir,
platformName === 'mac'
? `${packager.appInfo.productName}.app/Contents/Resources`
: 'resources',
'app.asar.unpacked/node_modules/@next'
);
if (fs.existsSync(nextDir)) {
const keepPrefix = platformName === 'mac' ? 'swc-darwin'
: platformName === 'windows' ? 'swc-win32'
: 'swc-linux';
for (const entry of fs.readdirSync(nextDir)) {
if (entry.startsWith('swc-') && !entry.startsWith(keepPrefix)) {
const fullPath = path.join(nextDir, entry);
fs.rmSync(fullPath, { recursive: true, force: true });
console.log(` • removed foreign SWC binary path=${fullPath}`);
}
}
}
if (platformName !== 'mac') return;
const appPath = path.join(appOutDir, `${packager.appInfo.productName}.app`);
console.log(` • ad-hoc signing path=${appPath}`);
execSync(`codesign --deep --force --sign - "${appPath}"`, { stdio: 'inherit' });
console.log(` • ad-hoc signing complete`);
}