| 84 | |
| 85 | // Lazy-load heavy modules (CodeGraph, runInstaller) to keep CLI startup fast. |
| 86 | async function loadCodeGraph(): Promise<typeof import('../index')> { |
| 87 | try { |
| 88 | return await import('../index'); |
| 89 | } catch (err) { |
| 90 | const msg = err instanceof Error ? err.message : String(err); |
| 91 | const [red, reset] = COLORS_ENABLED ? ['\x1b[31m', '\x1b[0m'] : ['', '']; |
| 92 | console.error(`${red}${getGlyphs().err}${reset} Failed to load CodeGraph modules.`); |
| 93 | console.error(`\n Node: ${process.version} Platform: ${process.platform} ${process.arch}`); |
| 94 | console.error(`\n Error: ${msg}`); |
| 95 | console.error('\n Try reinstalling with: npm install -g @colbymchenry/codegraph\n'); |
| 96 | process.exit(1); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // Dynamic import helper — tsc compiles import() to require() in CJS mode, |
| 101 | // which fails for ESM-only packages. This bypasses the transformation. |