| 1 | // Entry point. Loads configuration, installs the shims Strudel needs, then |
| 2 | // hands off to the app. |
| 3 | // |
| 4 | // The dynamic import at the bottom is required, not stylistic: loader-hooks.ts |
| 5 | // must finish evaluating before anything under @strudel/* is resolved. See its |
| 6 | // header. |
| 7 | import fs from 'node:fs'; |
| 8 | import path from 'node:path'; |
| 9 | import { fileURLToPath } from 'node:url'; |
| 10 | |
| 11 | import './loader-hooks.ts'; |
| 12 | import './browser-shim.ts'; |
| 13 | |
| 14 | // Read .env here rather than relying on the launcher's --env-file flag, so |
| 15 | // ANTHROPIC_API_KEY is picked up however the app is started — `npm run |
| 16 | // node-tui`, `node node-tui/boot.ts`, or from another directory entirely. The |
| 17 | // path is resolved relative to this file, not the working directory, for the |
| 18 | // same reason. |
| 19 | // |
| 20 | // Existing environment variables win: an explicitly exported key should not be |
| 21 | // silently overridden by a stale .env. |
| 22 | const ENV_FILE = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '.env'); |
| 23 | if (fs.existsSync(ENV_FILE)) { |
| 24 | try { |
| 25 | process.loadEnvFile(ENV_FILE); |
| 26 | } catch (err) { |
| 27 | process.stderr.write(`could not read ${ENV_FILE}: ${(err as Error).message}\n`); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | await import('./app.ts'); |