@colbymchenry/codegraph cannot be imported as a library on any platform
Problem
The npm thin-installer package (@colbymchenry/codegraph) currently ships only a CLI shim (npm-shim.js). It has no main, no types, and no exports field in its published package.json. This means:
import type { CodeGraph } from "@colbymchenry/codegraph" fails — TypeScript cannot resolve any types from the package.
import { CodeGraph } from "@colbymchenry/codegraph" fails at runtime — there is no JS entry point; the package only exposes a bin script.
As a workaround, downstream projects (e.g. Pi extensions, MCP servers, or any Node.js consumer) currently hard-code a platform-specific deep path:
import type {
CodeGraph,
Node,
NodeKind,
Edge,
SearchResult,
} from "@colbymchenry/codegraph-win32-x64/lib/dist/index";
This is brittle and breaks on every platform except Windows x64, because npm skips optionalDependencies that do not match the host os/cpu. On macOS and Linux, the win32-x64 package is never installed, so TypeScript reports:
error TS2307: Cannot find module '@colbymchenry/codegraph-win32-x64/lib/dist/index' or its corresponding type declarations.
Impact
- TypeScript consumers (Pi extensions, VS Code extensions, test suites) need
tsconfig.json paths workarounds that list all six platform packages in priority order.
- Runtime consumers must manually
require.resolve a deep path like @colbymchenry/codegraph-darwin-arm64/lib/dist/index.js instead of using the package name.
- CI / cross-platform builds fail because the hard-coded path only exists on one platform.
Steps to Reproduce
-
On macOS or Linux, install the package:
npm install @colbymchenry/codegraph
-
Create test.ts:
import type { CodeGraph } from "@colbymchenry/codegraph";
-
Run tsc --noEmit:
error TS2307: Cannot find module '@colbymchenry/codegraph' or its corresponding type declarations.
-
Alternatively, try the hard-coded workaround from the README examples:
import type { CodeGraph } from "@colbymchenry/codegraph-win32-x64/lib/dist/index";
This fails on macOS because the win32-x64 optional dependency is not installed.
Environment
@colbymchenry/codegraph: 0.9.3 (and all previous versions)
- Node.js: >= 20
- OS: darwin-arm64, darwin-x64, linux-x64, linux-arm64, win32-x64, win32-arm64
Proposed Solution
See PR #343. In short:
- Add
main / types / exports to every platform package (@colbymchenry/codegraph-<target>) so each can be imported directly without deep paths.
- Copy the
.d.ts tree from the first platform bundle into the main shim package so TypeScript can resolve types from @colbymchenry/codegraph itself.
- Generate a small CJS proxy (
index.js) in the main shim that resolves the matching platform package at require() time and re-exports everything.
- Update the main shim
package.json with main, types, and exports (types / require / default conditions).
@colbymchenry/codegraphcannot be imported as a library on any platformProblem
The npm thin-installer package (
@colbymchenry/codegraph) currently ships only a CLI shim (npm-shim.js). It has nomain, notypes, and noexportsfield in its publishedpackage.json. This means:import type { CodeGraph } from "@colbymchenry/codegraph"fails — TypeScript cannot resolve any types from the package.import { CodeGraph } from "@colbymchenry/codegraph"fails at runtime — there is no JS entry point; the package only exposes abinscript.As a workaround, downstream projects (e.g. Pi extensions, MCP servers, or any Node.js consumer) currently hard-code a platform-specific deep path:
This is brittle and breaks on every platform except Windows x64, because
npmskipsoptionalDependenciesthat do not match the hostos/cpu. On macOS and Linux, thewin32-x64package is never installed, so TypeScript reports:Impact
tsconfig.jsonpathsworkarounds that list all six platform packages in priority order.require.resolvea deep path like@colbymchenry/codegraph-darwin-arm64/lib/dist/index.jsinstead of using the package name.Steps to Reproduce
On macOS or Linux, install the package:
Create
test.ts:Run
tsc --noEmit:Alternatively, try the hard-coded workaround from the README examples:
This fails on macOS because the
win32-x64optional dependency is not installed.Environment
@colbymchenry/codegraph: 0.9.3 (and all previous versions)Proposed Solution
See PR #343. In short:
main/types/exportsto every platform package (@colbymchenry/codegraph-<target>) so each can be imported directly without deep paths..d.tstree from the first platform bundle into the main shim package so TypeScript can resolve types from@colbymchenry/codegraphitself.index.js) in the main shim that resolves the matching platform package atrequire()time and re-exports everything.package.jsonwithmain,types, andexports(types / require / default conditions).