2026-04-20 15:41:15 +03:00
|
|
|
/**
|
|
|
|
|
* Bundle main.mjs into a single file. Small electron-* helper deps are
|
|
|
|
|
* inlined; everything else — including the in-process web server
|
|
|
|
|
* (@openchamber/web) and native modules — stays external so it resolves
|
|
|
|
|
* from node_modules at runtime inside the packaged app.
|
|
|
|
|
*
|
|
|
|
|
* Why external matters: packages/web/server pulls in bun-pty, which has
|
|
|
|
|
* a top-level `import { dlopen } from "bun:ffi"`. If we inline it here,
|
|
|
|
|
* Node's ESM loader sees `bun:ffi` at package load time and crashes with
|
|
|
|
|
* ERR_UNSUPPORTED_ESM_URL_SCHEME before any runtime guard can skip it.
|
|
|
|
|
* Leaving @openchamber/web external means the conditional
|
|
|
|
|
* `if (isBunRuntime) await import('bun-pty')` stays dynamic and is never
|
|
|
|
|
* reached under Electron.
|
|
|
|
|
*/
|
|
|
|
|
import path from 'node:path';
|
|
|
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
|
|
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
const root = path.resolve(__dirname, '..');
|
2026-07-13 08:59:31 +03:00
|
|
|
const updaterE2eBuild = process.env.OPENCHAMBER_UPDATER_E2E_BUILD === '1';
|
2026-04-20 15:41:15 +03:00
|
|
|
|
|
|
|
|
const result = await Bun.build({
|
|
|
|
|
entrypoints: [path.join(root, 'main.mjs')],
|
|
|
|
|
outdir: path.join(root, 'dist-bundle'),
|
|
|
|
|
target: 'node',
|
|
|
|
|
format: 'esm',
|
|
|
|
|
external: [
|
|
|
|
|
'electron',
|
|
|
|
|
'@openchamber/web',
|
|
|
|
|
'@openchamber/web/*',
|
|
|
|
|
'bun-pty',
|
|
|
|
|
'node-pty',
|
|
|
|
|
],
|
|
|
|
|
minify: false,
|
|
|
|
|
sourcemap: 'none',
|
|
|
|
|
naming: '[name].mjs',
|
2026-07-13 08:59:31 +03:00
|
|
|
define: {
|
|
|
|
|
__OPENCHAMBER_UPDATER_E2E_BUILD__: updaterE2eBuild ? 'true' : 'false',
|
|
|
|
|
},
|
2026-04-20 15:41:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (!result.success) {
|
|
|
|
|
for (const msg of result.logs) console.error(msg);
|
|
|
|
|
process.exit(1);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-13 08:59:31 +03:00
|
|
|
console.log(`[electron] main.mjs bundled -> dist-bundle/main.mjs (updater E2E=${updaterE2eBuild})`);
|