perf(startup): load canvas, node-pty, ssh2, html-to-text and the OpenCode SDK on first use

Main module evaluation drops from ~420 ms to ~330 ms. Types stay as import type; the DeepSeek Harness chunks stay static because the protocol chunk shares code with Main startup paths.
This commit is contained in:
mesalogo
2026-10-03 17:15:13 +08:00
parent 68cc0792e1
commit 010aafb6f4
12 changed files with 104 additions and 26 deletions
+14
View File
@@ -0,0 +1,14 @@
import { createRequire } from 'node:module'
/**
* Synchronously loads a dependency on first use instead of at module
* evaluation (P6). Main is ESM, but some test fixtures bundle the same code as
* CommonJS, where `import.meta.url` is empty and `__filename` exists instead.
*/
export function createLazyRequire<T>(specifier: string): () => T {
let loaded: T | undefined
return () => {
loaded ??= createRequire(import.meta.url || __filename)(specifier) as T
return loaded
}
}