#!/usr/bin/env node
// extract-zip/yauzl streams hang on Node 26 (no data events emitted).
// bsdtar (libarchive) handles both Linux and macOS zips including chained symlinks in .app bundles.
const { writeFileSync, existsSync } = require('fs');
const { resolve } = require('path');

const target = resolve('node_modules/@electron/packager/dist/unzip.js');
if (!existsSync(target)) {
  console.log('patch-packager-unzip: target not found, skipping');
  process.exit(0);
}

const patched = `import { execSync } from 'node:child_process';
// extract-zip/yauzl streams are broken on Node 26; use bsdtar (libarchive) instead.
// bsdtar correctly handles chained symlinks in macOS .app bundles that 7z refuses.
export async function extractElectronZip(zipPath, targetDir) {
    execSync(\`bsdtar -xf "\${zipPath}" -C "\${targetDir}"\`, { stdio: 'pipe' });
}
//# sourceMappingURL=unzip.js.map
`;

writeFileSync(target, patched);
console.log('patch-packager-unzip: patched @electron/packager/dist/unzip.js to use bsdtar');
