The 0.9.x thin-installer turned @colbymchenry/codegraph into a bin-only
shim: require("@colbymchenry/codegraph") threw MODULE_NOT_FOUND and no
types shipped, breaking embedded library consumers (e.g. Electron apps)
upgrading from 0.8.0.
Restore programmatic use without re-bloating the thin shim or duplicating
the ~49 MB of grammars the per-platform bundle already carries:
- main -> npm-sdk.js re-exports the installed per-platform bundle's compiled
library (lib/dist/index.js) at runtime, reusing that bundle's own deps; it
falls back to a self-healed cache bundle, else throws an actionable error.
- types -> ship the .d.ts tree only (~590 KB) in the main package, built from
the same release so it can never skew from the runtime it re-exports.
- exports map resolves the `types` condition (nodenext) and the default entry.
- DatabaseConnection + QueryBuilder are now top-level exports, so embedded
callers get the building blocks from the package entry instead of deep
dist/ imports (which the shim no longer ships).
The CLI/MCP `bin` keeps execing the bundled Node; only library consumers run
on their own runtime, which must be Node 22.5+ for the built-in node:sqlite.
Validated end-to-end: built a real darwin-arm64 bundle, packed the npm
packages, installed them into a throwaway consumer, and confirmed require()
plus a full init/indexAll/searchNodes round-trip and the low-level
DatabaseConnection/QueryBuilder path all work on the host Node; types resolve
under both nodenext and classic node resolution; and the CLI shim still
launches. New hermetic tests cover npm-sdk resolution, cache fallback, and the
missing-bundle error.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
3a1ddf41cd
commit
89d4d37a29
@@ -500,8 +500,14 @@ When running as an MCP server, CodeGraph exposes these tools to Claude Code:
|
||||
|
||||
## Library Usage
|
||||
|
||||
CodeGraph can be embedded directly. The npm package re-exports its programmatic
|
||||
API, so both `import` and `require` resolve the `CodeGraph` class in your own
|
||||
process — handy for embedding it in an app (e.g. an Electron main process).
|
||||
|
||||
```typescript
|
||||
import CodeGraph from '@colbymchenry/codegraph';
|
||||
// CommonJS works too:
|
||||
// const { CodeGraph } = require('@colbymchenry/codegraph');
|
||||
|
||||
const cg = await CodeGraph.init('/path/to/project');
|
||||
// Or: const cg = await CodeGraph.open('/path/to/project');
|
||||
@@ -520,6 +526,21 @@ cg.unwatch(); // stop watching
|
||||
cg.close();
|
||||
```
|
||||
|
||||
Lower-level building blocks are exported from the same entry point for callers
|
||||
that drive the graph directly: `DatabaseConnection`, `QueryBuilder`,
|
||||
`getDatabasePath`, `initGrammars` / `loadGrammarsForLanguages`, and `FileLock`.
|
||||
|
||||
**Embedding requirements**
|
||||
|
||||
- Install from npm (`npm i @colbymchenry/codegraph`) so the matching
|
||||
per-platform package — which carries the compiled library and its
|
||||
dependencies — is fetched alongside the shim.
|
||||
- The API runs on **your** runtime, so it needs **Node 22.5+** for the built-in
|
||||
`node:sqlite` (Electron qualifies when its bundled Node is 22.5+). The CLI and
|
||||
MCP server are unaffected — they run on the self-contained bundled runtime.
|
||||
- TypeScript types ship with the package. As with any Node-targeting library,
|
||||
keep `@types/node` available and `skipLibCheck: true` (the common default).
|
||||
|
||||
---
|
||||
|
||||
## Configuration
|
||||
|
||||
Reference in New Issue
Block a user