Files
openchamber/packages/electron/scripts/bundle-main.mjs
T
Bohdan Triapitsyn 56f2b972f0 chore(deps): drop better-sqlite3 and its desktop packaging support
The SQLite write into OpenCode's database was the only consumer of
better-sqlite3 in the repository. Everything that existed to ship its native
binary went with it:

- the dependency in @openchamber/web and @openchamber/electron
- the afterPack hook staging better_sqlite3.node into app.asar.unpacked
- a dedicated @electron/rebuild pass (onlyModules) and its binary assertion,
  so desktop packaging now runs one native rebuild instead of two
- the bundler external entry and the AppImage required-native-module check

Desktop packaging, the AppImage verification tests, and the extension bundle
were re-validated after a clean reinstall, so no stale module could satisfy a
missed import.
2026-08-03 23:38:01 +03:00

48 lines
1.6 KiB
JavaScript

/**
* 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, '..');
const updaterE2eBuild = process.env.OPENCHAMBER_UPDATER_E2E_BUILD === '1';
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',
define: {
__OPENCHAMBER_UPDATER_E2E_BUILD__: updaterE2eBuild ? 'true' : 'false',
},
});
if (!result.success) {
for (const msg of result.logs) console.error(msg);
process.exit(1);
}
console.log(`[electron] main.mjs bundled -> dist-bundle/main.mjs (updater E2E=${updaterE2eBuild})`);