// After `npm run build`: write dist/node-path, the Node that built brain and can load its native // module (better-sqlite3). The Coucou app runs brain with that Node, not whichever `node` comes // first in its own PATH: a different Node version can't open the index ("compiled against a // different Node.js version") and the Memory pages would see nothing. const fs = require("node:fs"); const path = require("node:path"); const out = path.join(__dirname, "..", "dist", "node-path"); // `npm install` in the repo runs this before any build: nothing to pin yet if (!fs.existsSync(path.dirname(out))) process.exit(0); try { require("better-sqlite3"); fs.writeFileSync(out, process.execPath + "\n"); console.log(`brain: Node pinned for the app → ${process.execPath}`); } catch (e) { fs.rmSync(out, { force: true }); console.warn(`brain: this Node (${process.version}) can't load better-sqlite3 — run « npm rebuild better-sqlite3 », then « npm run build ».`); }