2026-05-26 11:13:59 -04:00
|
|
|
import { spawn } from 'node:child_process';
|
|
|
|
|
import fs from 'node:fs';
|
|
|
|
|
import path from 'node:path';
|
2026-07-13 08:59:31 +03:00
|
|
|
import { resolveTargetArchitecture } from './target-architecture.mjs';
|
2026-05-26 11:13:59 -04:00
|
|
|
|
|
|
|
|
const env = { ...process.env };
|
2026-07-13 08:59:31 +03:00
|
|
|
const builderArgs = process.argv.slice(2);
|
|
|
|
|
const targetArchitecture = resolveTargetArchitecture({ environment: env, builderArgs });
|
2026-05-26 11:13:59 -04:00
|
|
|
|
|
|
|
|
if (process.platform === 'win32' && !env.CSC_LINK && !env.WINDOWS_CSC_LINK) {
|
|
|
|
|
env.CSC_IDENTITY_AUTO_DISCOVERY = 'false';
|
|
|
|
|
console.log('[electron] Windows code signing disabled; building unsigned installer.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const bunBinaryCandidates = [
|
|
|
|
|
process.env.npm_execpath,
|
|
|
|
|
process.env.BUN_INSTALL ? path.join(process.env.BUN_INSTALL, 'bin', process.platform === 'win32' ? 'bun.exe' : 'bun') : null,
|
|
|
|
|
process.platform === 'win32' ? 'bun.exe' : 'bun',
|
|
|
|
|
].filter(Boolean);
|
|
|
|
|
|
|
|
|
|
const bunBinary = bunBinaryCandidates.find((candidate) => {
|
|
|
|
|
if (path.basename(candidate).toLowerCase().startsWith('bun')) {
|
|
|
|
|
return candidate === 'bun' || candidate === 'bun.exe' || fs.existsSync(candidate);
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}) || (process.platform === 'win32' ? 'bun.exe' : 'bun');
|
|
|
|
|
|
2026-07-13 08:59:31 +03:00
|
|
|
if (process.platform === 'linux' && !builderArgs.some((argument) => (
|
|
|
|
|
argument === '--x64' || argument === '--arm64' || argument === '--arch' || argument.startsWith('--arch=')
|
|
|
|
|
))) {
|
|
|
|
|
builderArgs.push(`--${targetArchitecture.electronBuilder}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const child = spawn(bunBinary, ['x', 'electron-builder', ...builderArgs], {
|
2026-05-26 11:13:59 -04:00
|
|
|
env,
|
|
|
|
|
stdio: 'inherit',
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
child.on('exit', (code, signal) => {
|
|
|
|
|
if (signal) {
|
|
|
|
|
process.kill(process.pid, signal);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
process.exit(code ?? 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
child.on('error', (error) => {
|
|
|
|
|
console.error('[electron] failed to start electron-builder:', error);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
});
|