Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.
fix(build): bundle React so standalone binaries can render the TUI
Salman Qureshia2c155ca21fa
diff --git a/scripts/post-build.cjs b/scripts/post-build.cjsindex 38e07703..7b83a18c 100644--- a/scripts/post-build.cjs+++ b/scripts/post-build.cjs@@ -37,6 +37,24 @@ function copyDirSync(src, dest) {console.log(' ✓ patched ink is bundled (vendor/ink)');}+// 0b. Standalone binaries have no node_modules: a CommonJS `require("pkg")`+// left in the bundle resolves at runtime only, so `bun build --compile`+// cannot see it and the binary throws "Cannot find package" when that code+// first runs (react-reconciler → react broke the TUI this way). Only node+// builtins may be required at runtime.+{+ const { builtinModules } = require('node:module');+ const bundle = fs.readFileSync(path.join(__dirname, '..', 'dist', 'mercury.js'), 'utf8');+ const runtime = new Set([...bundle.matchAll(/__require\("([^"]+)"\)/g)].map((m) => m[1]));+ const foreign = [...runtime].filter((id) => !id.startsWith('node:') && !builtinModules.includes(id.split('/')[0]));+ if (foreign.length) {+ console.error(` ✗ runtime require of bundled-away packages (breaks standalone binaries): ${foreign.join(', ')}`);+ console.error(' add them to tsup noExternal so they are bundled');+ process.exit(1);+ }+ console.log(' ✓ no runtime requires of npm packages (binary-safe)');+}+// 1. Copy src/web/static -> dist/web/staticconst staticSrc = path.join(__dirname, '..', 'src', 'web', 'static');const staticDest = path.join(__dirname, '..', 'dist', 'web', 'static');diff --git a/tsup.config.ts b/tsup.config.tsindex eaa4423c..762d03e5 100644--- a/tsup.config.ts+++ b/tsup.config.ts@@ -55,7 +55,13 @@ export default defineConfig({"globalThis.__MERCURY_VERSION__": JSON.stringify(channelVersion),"globalThis.__MERCURY_CHANNEL_VERSION__": JSON.stringify(channelStamp),},- noExternal: ["ink"],+ // React is bundled too. The vendored ink bundles react-reconciler, a+ // CommonJS module whose `require("react")` would otherwise stay a runtime+ // lookup: fine with node_modules on disk, fatal in a Bun-compiled binary+ // ("Cannot find package 'react'" at the first render). Bundling also+ // guarantees one React instance. post-build.cjs fails on any such+ // runtime require of a non-builtin package.+ noExternal: ["ink", /^react($|\/)/],esbuildOptions(options) {options.alias = { ...(options.alias ?? {}), ink: VENDORED_INK };},