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:
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user