You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support pnpm monorepos: resolve workspace packages to real files and cross-package type usage #462
In a pnpm workspace (and similar JS monorepos), shared code lives in packages such as packages/types, while apps live under apps/*. Imports use the published package name from package.json (for example @workspace/types), not relative file paths.
Graphify’s JS/TS import handling today effectively treats many non-relative specifiers like opaque external modules. In practice:
Scoped packages are easy to mis-handle (for example @workspace/types must not collapse to a meaningless or colliding token such as types).
imports_from edges often do not attach to real file nodes in the repository, so they can be dropped when building the graph and structure between apps and shared packages is lost.
There is no strong story for “this type from the shared package is used in the frontend (and backend)” at graph level, which matters for architecture navigation and impact analysis.
Example layout
pnpm-workspace.yaml:
packages:
- 'apps/*'
- 'packages/*'
apps/backend and apps/frontend depend on packages/types.
packages/types is exposed as e.g. @workspace/types in its package.json.
Code imports: import type { SomeDto } from '@workspace/types'.
Why this matters
The graph should show dependencies between workspaces (for example app → shared types package), not only a flat set of “external” import names.
Ideally, symbols (types/interfaces) defined in shared packages can be related to consumers in other packages (similar in spirit to cross-file inferred edges for Python).
Desired behavior (high level)
Detect a monorepo when pnpm-workspace.yaml (and optionally other workspace manifests) is present; discover package roots from workspace globs and each package’s package.jsonname.
Resolveimport … from '@scope/pkg' (and reasonable subpaths) to concrete entry files under the repo so edges target existing file nodes (and optionally package-level hub nodes for navigation).
Cache / rebuild correctness when workspace layout or package names change.
(Stretch / Phase 2) Infer edges from named workspace imports to exported types/interfaces so questions like “where is this shared type used in the frontend?” are answerable from the graph.
Data point from a 22-workspace pnpm monorepo, plus a workaround and one sharp edge
Ran graphify 0.9.50 on a pnpm workspace monorepo (~1,700 code files, 22 workspaces, @app-gether-life/* internal packages). Measured each variable independently with a clean graphify-out/ between every run.
This is the sharp edge, and it cost me a wrong conclusion — I had originally written this repo up as "graphify can't resolve pnpm workspaces" off the 104 number.
I'd added **/package.json to .graphifyignore for an unrelated reason: .json is a code extension, so every top-level key becomes a node, and the scripts and test keys shared by 22 workspaces collapsed into god nodes at 51 and 43 edges, outranking real code.
That exclusion destroys resolution, because graphify matches a bare specifier against workspace name fields in the corpus. Minimal repro — two packages, bare tsconfigs, no paths anywhere:
packages/pkg-a/package.json { "name": "@scope/pkg-a" }
packages/pkg-a/src/helpers.ts export function sharedHelper(x) {...}
apps/app-b/src/consumer.ts import { sharedHelper } from "@scope/pkg-a/helpers";
graphify affected "sharedHelper()" finds the consumer. Add a .graphifyignore containing exactly **/package.json, rebuild clean, and the same query returns "No affected nodes found."
Two suggestions, either would have saved the misdiagnosis:
Read workspace manifests for resolution regardless of ignore rules — they're metadata, not corpus.
Or warn: N workspace package.json files are excluded by ignore rules; cross-package imports will not resolve.
The underlying pull is real, though — people will keep excluding package.json as long as its keys pollute the graph. #2523 is the same pressure from the other direction.
2. Wildcard paths mappings are a working workaround
For anyone hitting this before #462 lands: adding wildcard-subpath paths for each workspace package took us from 217 to 1,737 edges. Worth knowing:
TypeScript replaces compilerOptions.paths on extends rather than merging it. A shared base file holding the mappings does nothing for any consumer that has its own paths key. That silently looks like graphify ignoring the mappings when it's TypeScript semantics.
references + composite do nothing for graphify — expected, since it's tree-sitter and never consults tsserver, but worth stating because that's the setup people add for LSP-based tools.
Our typecheck stayed green (37/37 projects) and 809 unit tests passed, so the mappings are additive rather than a resolution rewrite.
3. --force does not invalidate the resolution cache
Filed separately as #3125, but flagging here because it makes this issue much harder to diagnose: after changing paths, graphify extract --force reported zero new edges. Only rm -rf graphify-out/ picked the change up. I nearly reverted a correct fix twice because of it. Anyone testing a workaround for this issue will hit it.
What good looks like
Once resolved, the god-node ranking went from mostly plumbing to an accurate read of the codebase — getAdminClient 218 edges, errMessage() 155, asError() 70, inngest 56, ItemResponse 45. That's the tool doing exactly what it promises. The gap is only in getting the workspace wired up, and most of it is diagnosable from the edge count if you know to look.
Activity
cbartens commentedon Aug 26, 2026
Data point from a 22-workspace pnpm monorepo, plus a workaround and one sharp edge
Ran graphify 0.9.50 on a pnpm workspace monorepo (~1,700 code files, 22 workspaces,
@app-gether-life/*internal packages). Measured each variable independently with a cleangraphify-out/between every run.Cross-package import edges, by configuration
pathsmappings1. Excluding
package.jsonsilently kills workspace resolutionThis is the sharp edge, and it cost me a wrong conclusion — I had originally written this repo up as "graphify can't resolve pnpm workspaces" off the 104 number.
I'd added
**/package.jsonto.graphifyignorefor an unrelated reason:.jsonis a code extension, so every top-level key becomes a node, and thescriptsandtestkeys shared by 22 workspaces collapsed into god nodes at 51 and 43 edges, outranking real code.That exclusion destroys resolution, because graphify matches a bare specifier against workspace
namefields in the corpus. Minimal repro — two packages, bare tsconfigs, nopathsanywhere:graphify affected "sharedHelper()"finds the consumer. Add a.graphifyignorecontaining exactly**/package.json, rebuild clean, and the same query returns "No affected nodes found."Two suggestions, either would have saved the misdiagnosis:
N workspace package.json files are excluded by ignore rules; cross-package imports will not resolve.The underlying pull is real, though — people will keep excluding
package.jsonas long as its keys pollute the graph. #2523 is the same pressure from the other direction.2. Wildcard
pathsmappings are a working workaroundFor anyone hitting this before #462 lands: adding wildcard-subpath
pathsfor each workspace package took us from 217 to 1,737 edges. Worth knowing:compilerOptions.pathsonextendsrather than merging it. A shared base file holding the mappings does nothing for any consumer that has its ownpathskey. That silently looks like graphify ignoring the mappings when it's TypeScript semantics.references+compositedo nothing for graphify — expected, since it's tree-sitter and never consults tsserver, but worth stating because that's the setup people add for LSP-based tools.Our typecheck stayed green (37/37 projects) and 809 unit tests passed, so the mappings are additive rather than a resolution rewrite.
3.
--forcedoes not invalidate the resolution cacheFiled separately as #3125, but flagging here because it makes this issue much harder to diagnose: after changing
paths,graphify extract --forcereported zero new edges. Onlyrm -rf graphify-out/picked the change up. I nearly reverted a correct fix twice because of it. Anyone testing a workaround for this issue will hit it.What good looks like
Once resolved, the god-node ranking went from mostly plumbing to an accurate read of the codebase —
getAdminClient218 edges,errMessage()155,asError()70,inngest56,ItemResponse45. That's the tool doing exactly what it promises. The gap is only in getting the workspace wired up, and most of it is diagnosable from the edge count if you know to look.