Root cause: esbuild 0.27.3 misparses `node-pty` inside JSDoc comments as a code expression `node - pty` (subtraction). This produces a bare `ReferenceError: node is not defined` at app.asar/dist-electron/main.js:35 on startup. Fixes: - terminal-manager.ts: replace JSDoc block with line comments and remove all literal `node-pty` strings (reference docs/handover instead) - build-electron.mjs: clean dist-electron/ before every build to prevent stale artifact contamination in app.asar Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
import { build } from 'esbuild';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
|
|
// Replace symlinks in standalone with real copies so electron-builder can package them
|
|
function resolveStandaloneSymlinks() {
|
|
const standaloneModules = '.next/standalone/.next/node_modules';
|
|
if (!fs.existsSync(standaloneModules)) return;
|
|
|
|
const entries = fs.readdirSync(standaloneModules);
|
|
for (const entry of entries) {
|
|
const fullPath = path.join(standaloneModules, entry);
|
|
const stat = fs.lstatSync(fullPath);
|
|
if (stat.isSymbolicLink()) {
|
|
const target = fs.readlinkSync(fullPath);
|
|
const resolved = path.resolve(standaloneModules, target);
|
|
if (fs.existsSync(resolved)) {
|
|
fs.rmSync(fullPath, { recursive: true, force: true });
|
|
fs.cpSync(resolved, fullPath, { recursive: true });
|
|
console.log(`Resolved symlink: ${entry} -> ${target}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function buildElectron() {
|
|
// Clean dist-electron/ before every build to prevent stale artifacts
|
|
// from leaking into app.asar (caused v0.34 crash on upgrade).
|
|
if (fs.existsSync('dist-electron')) {
|
|
fs.rmSync('dist-electron', { recursive: true });
|
|
console.log('Cleaned dist-electron/');
|
|
}
|
|
fs.mkdirSync('dist-electron', { recursive: true });
|
|
|
|
const shared = {
|
|
bundle: true,
|
|
platform: 'node',
|
|
target: 'node18',
|
|
external: ['electron'],
|
|
sourcemap: true,
|
|
minify: false,
|
|
};
|
|
|
|
await build({
|
|
...shared,
|
|
entryPoints: ['electron/main.ts'],
|
|
outfile: 'dist-electron/main.js',
|
|
});
|
|
|
|
await build({
|
|
...shared,
|
|
entryPoints: ['electron/preload.ts'],
|
|
outfile: 'dist-electron/preload.js',
|
|
});
|
|
|
|
console.log('Electron build complete');
|
|
|
|
// Fix standalone symlinks after next build
|
|
resolveStandaloneSymlinks();
|
|
}
|
|
|
|
buildElectron().catch((err) => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|