Public: anyone can read this; the crew can change it.
Lazy-load the boards, studio and the other optional modules a small forge never uses #12373
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/12372-lazy-load-the-boards-studio-and-the-othe → main 5 commits fork 4 threads · 4 unresolved
2 files
changed +14
−2
src/main.ts +10 −2
| @@ -54,7 +54,6 @@ import { runGuardSweep } from "./origins/credential.ts"; | ||
| 54 | 54 | import { warmHome } from "./web/pages/home_flow.ts"; |
| 55 | 55 | import { warmPlans } from "./web/pages/milestones.ts"; |
| 56 | 56 | import { warmBoards } from "./web/pages/boards-view.ts"; |
| 57 | import { startForgeSsh } from "./tui/ssh.ts"; | |
| 58 | 57 | import { AppsRuntime, IDLE_PULL_DAYS } from "./apps/runtime.ts"; |
| 59 | 58 | import { previewIdleMs } from "./apps/sleep_window.ts"; |
| 60 | 59 | import { listApps } from "./core/apps.ts"; |
| @@ -434,8 +433,17 @@ keepFlowReadings(KEPT_MS); | ||
| 434 | 433 | // The home's picture is read by a worker from here, so the first page finds it (web/pages/home_flow.ts). |
| 435 | 434 | warmHome(app); |
| 436 | 435 | warmBoards(app); |
| 436 | // The terminal is optional: its modules load only when a port is set, so a forge with | |
| 437 | // FORGE_SSH_PORT=0 never loads them (test/boot-lazy.test.ts). | |
| 437 | 438 | const sshStarted = |
| 438 | sshPort > 0 ? await startForgeSsh(app, { port: sshPort }) : undefined; | |
| 439 | sshPort > 0 | |
| 440 | ? await import("./tui/ssh.ts") | |
Non-blocking: this catch also swallows errors thrown by startForgeSsh, not only the import, and reports them as a load failure. |
||
| 441 | .then((m) => m.startForgeSsh(app, { port: sshPort })) | |
| 442 | .catch((error) => { | |
| 443 | app.log.warn("ssh is off: the terminal failed to load", { error: String(error) }); | |
| 444 | return undefined; | |
| 445 | }) | |
| 446 | : undefined; | |
| 439 | 447 | if (sshStarted && !sshStarted.ok) |
| 440 | 448 | app.log.warn("ssh is off: the terminal could not start", { |
| 441 | 449 | port: sshPort, |
test/boot-lazy.test.ts +4
| @@ -28,3 +28,7 @@ test("the boot's static imports do not reach the terminal UI", () => { | ||
| 28 | 28 | const tui = closure.filter((f) => f.includes("/src/tui/screens/") || f.endsWith("/src/tui/forge.ts")); |
| 29 | 29 | expect(tui).toEqual([]); |
| 30 | 30 | }); |
| 31 | ||
| 32 | test("the terminal's server is imported dynamically by the boot", () => { | |
| 33 | expect(readFileSync(resolve("src/main.ts"), "utf8")).toContain('import("./tui/ssh.ts")'); | |
| 34 | }); |
new above
offline
Unrelated to what the router loads anyway;
sshPort > 0lazy import is good, keep it. Add a log on failure instead of silence.