()
| 36 | // Throws an actionable error (rather than a bare MODULE_NOT_FOUND) when no bundle |
| 37 | // is present, so an embedded consumer knows exactly what to install. |
| 38 | function resolveLibrary() { |
| 39 | // 1) The npm-installed optional dependency — the normal case. |
| 40 | try { |
| 41 | return require.resolve(pkg + '/lib/dist/index.js'); |
| 42 | } catch (e) { |
| 43 | /* fall through to the self-healed cache */ |
| 44 | } |
| 45 | |
| 46 | // 2) A bundle the CLI shim self-healed from GitHub Releases into the cache |
| 47 | // (issue #303). Same node/lib/bin layout as the npm package. We only REUSE a |
| 48 | // cached bundle here — unlike the CLI shim we never trigger a network |
| 49 | // download from inside require(), which must stay synchronous and cheap. |
| 50 | var cached = cachedLibrary(); |
| 51 | if (cached) return cached; |
| 52 | |
| 53 | throw new Error( |
| 54 | 'codegraph: the programmatic API is unavailable because the platform bundle\n' + |
| 55 | '(' + pkg + ') is not installed.\n' + |
| 56 | 'The compiled library ships inside that per-platform optional dependency.\n' + |
| 57 | 'Fixes:\n' + |
| 58 | ' - install from the official npm registry so the matching bundle is fetched:\n' + |
| 59 | ' npm i @colbymchenry/codegraph --registry=https://registry.npmjs.org\n' + |
| 60 | ' - or run the CLI once (e.g. `npx @colbymchenry/codegraph status`) to\n' + |
| 61 | ' self-heal the bundle into ~/.codegraph, then require() will find it.' |
| 62 | ); |
| 63 | } |
| 64 | |
| 65 | function cachedLibrary() { |
| 66 | try { |
no test coverage detected