39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
// Post-build hook: ad-hoc sign the .app bundle so macOS 14+ will open it
|
|
// without requiring an Apple Developer certificate.
|
|
const { execSync } = require('child_process');
|
|
const path = require('path');
|
|
|
|
exports.default = async function (context) {
|
|
const appPath = path.join(
|
|
context.appOutDir,
|
|
`${context.packager.appInfo.productFilename}.app`,
|
|
);
|
|
console.log(`Ad-hoc signing: ${appPath}`);
|
|
|
|
// Remove Finder/iCloud metadata that can make codesign fail with
|
|
// "resource fork, Finder information, or similar detritus not allowed".
|
|
const cleanupCmds = [
|
|
`xattr -cr "${appPath}"`,
|
|
`dot_clean -m "${appPath}"`,
|
|
`find "${appPath}" -name '._*' -delete`,
|
|
`xattr -r -d com.apple.FinderInfo "${appPath}"`,
|
|
`xattr -r -d com.apple.ResourceFork "${appPath}"`,
|
|
`xattr -r -d com.apple.quarantine "${appPath}"`,
|
|
];
|
|
|
|
for (const cmd of cleanupCmds) {
|
|
try {
|
|
execSync(cmd, { stdio: 'ignore' });
|
|
} catch {
|
|
// Cleanup commands are best-effort.
|
|
}
|
|
}
|
|
|
|
try {
|
|
execSync(`codesign --force --deep --sign - "${appPath}"`, { stdio: 'inherit' });
|
|
console.log('Ad-hoc signing complete.');
|
|
} catch (err) {
|
|
console.warn('Ad-hoc signing skipped due to codesign error. Build artifacts are still usable locally.');
|
|
}
|
|
};
|