Repository navigation
Description
Follow-up to pnpm/pnpm#17615, which added the crate layer check (pnpm/tasks/crate-layers, crate-layers.toml). That check sees only the graph between crates. Most code sits inside a few large crates, and their module graphs are tangled.
Findings
An approximate module graph built from crate:: paths (it misses super:: references, so it undercounts):
| Crate | Code lines | Largest module cycle |
|---|---|---|
pnpm-resolving-deps-resolver |
16k | 11 modules, 95% of the code |
pnpm-deps-restorer |
26k | 25 modules, 77% |
pnpm-package-manager |
40k | 11 modules, 66% |
pnpm-config |
12k | 7 modules, 57% |
In pnpm-package-manager, install and optimistic_repeat_install depend on each other. install calls the fast path's validation and settings about 30 times, and the fast path uses install's StateWrite, StateProjects, and FreshnessCheckError. The rule "is the recorded install state still valid" is split across both. Since 2026-08-01, 66 of 111 commits to optimistic_repeat_install and 164 of 277 to install were fixes.
Plan
Analysis
- Overlay fix history on the module graph of
pnpm-package-manager: cycle membership, fan-in and fan-out, fix ratio, and fix-on-fix chains per module. Found two clusters: Give the repeat-install fast path one contract for every install input #254 and Make the lockfile freshness check use the resolver's local-dependency rules #255. - Do the same for
pnpm-deps-restorerandpnpm-resolving-deps-resolver. Found three clusters inpnpm-deps-restorer: Decide a store file's link-or-copy fallback in one place, and test it against every error #283 (link-or-copy fallback), Give a global virtual store slot one owner of its state, and test its transitions across processes #284 (global virtual store slot state), and Run each linking concern once for both node linkers #285 (the two node linkers). Inpnpm-resolving-deps-resolver, the peer-pin cluster is already Decide peer recording from one function, and test reuse against fresh resolution through the real lockfile writer #221; the new evidence is in a comment there.
Tooling
-
crate-layers modules: a module graph per crate that resolvescrate::,super::,self::, andusegroups. Report each crate's strongly connected components. Done in feat(crate-layers): ratchet module cycles inside each crate pnpm#17618. - Ratchet: a committed baseline of each crate's largest module cycle. CI fails when a cycle grows, and the baseline shrinks when one is broken. Done in feat(crate-layers): ratchet module cycles inside each crate pnpm#17618 (
[module_cycles]incrate-layers.toml). - Per-crate direct-dependency ratchet and a transitive-dependency budget for the model and service layers. Done in feat(crate-layers): ratchet direct dependencies and budget transitive ones pnpm#17743 (
[direct_dependencies]andmax_transitive_dependenciesincrate-layers.toml). - Leaky-API check: callers forced to depend on a crate because a callee's public signatures expose its types. Candidate:
pnpm-network→pnpm-http(16 callers depend on both). Done in feat(crate-layers): ratchet the dependencies a crate leaks through its public API pnpm#17748 (crate-layers leaks,[leaked_dependencies]incrate-layers.toml).- Read effective visibility in the leak scan: follow
pub usere-exports (globs included) so apubitem in a private, unexported module does not count. Done in feat(crate-layers): count only leaks a caller can reach pnpm#18060. Animplon a private type alias of a public type is still missed; the README lists it.
- Read effective visibility in the leak scan: follow
- Product boundary rule: an explicit list of which crates may cross between pnpm and pnpr. Done in feat(crate-layers): check the product boundary between pnpm and pnpr pnpm#18059 (
[product_boundary]incrate-layers.toml). The crossings to cut next:pnpr→pnpm-config,pnpr→pnpm-package-manager, andpnpm-config→pnpr-registry. - A dependency structure matrix page with a git co-change overlay. Done in feat(crate-layers): add a dependency structure matrix page pnpm#18065 (
crate-layers dsm; CI uploads it as thecrate-dsmartifact of the Crate Layers job). Among the pairs it shows changing together without a dependency:installandoptimistic_repeat_installinpnpm-package-manager(50 commits) andpnpr-authandpnpr-storage(21). - Function-level view from a rust-analyzer SCIP index, to find validators of the same state in two places. Done in feat(crate-layers): report state that several modules decide on pnpm#18490 (
crate-layers overlapsandcrate-layers fields; on demand, not part ofcrate-layers check).
Refactors the analysis points to
- Skip reading package.json files on the repeat-install fast path when their stat signatures match: Skip reading package.json files on the repeat-install fast path #256 (before Give the repeat-install fast path one contract for every install input #254).
- Give the install-state contract (what is recorded and how it is validated) one home that both
installandoptimistic_repeat_installdepend on, removing the cycle: Give the repeat-install fast path one contract for every install input #254. - Narrow
pnpm-pnpr-clientfrom&Configto explicit options, so it fits the service layer. Done in refactor(pnpr-client): take explicit options instead of the configuration pnpm#18061: the crate moved to the service layer, and its transitive dependencies dropped from 50 to 30. - Reduce what
pnpm-configpulls in transitively. refactor(config): cut the edges that add crates only config needs pnpm#18068 droppedpnpr-registry(the last pnpm → pnpr crossing outside tests and tooling),pnpm-patching, andpnpm-tarball. refactor(workspace): keep the projects graph out of pnpm-workspace pnpm#18495 moved the projects graph out from underpnpm-workspace(49 → 45 workspace crates). refactor(config): stop depending on the task scheduler pnpm#18504 (open) dropspnpm-workspace-task-scheduler(45 → 43). What is left,pnpm-store-dir,pnpm-resolving-resolver-base, andpnpm-package-is-installable, removes one or two crates each and needs a new crate; see the comment.
Written by an agent (Claude Code, claude-opus-5-5).
Activity
feat(crate-layers): ratchet module cycles inside each crate (#17618)
zkochan commentedon Nov 5, 2026
pnpm/pnpm#17743 covers the tooling item "Per-crate direct-dependency ratchet and a transitive-dependency budget for the model and service layers". It adds a
[direct_dependencies]ratchet table tocrate-layers.tomland amax_transitive_dependenciescap on the model layer (18) and the service layer (35), both set to today's maxima, plus acrate-layers dependenciesreport. The other open items are not part of it.Written by an agent (Claude Code, claude-opus-5-5).
feat(crate-layers): ratchet direct dependencies and budget transitive…
zkochan commentedon Nov 5, 2026
pnpm/pnpm#17748 covers the tooling item "Leaky-API check".
crate-layers leakslists each crate that names a dependency's items in its public signatures without re-exporting them, with the number of crates that depend on both.crate-layers checkratchets the count per crate through a new[leaked_dependencies]table. The candidatepnpm-network→pnpm-httpshows up with 8 items and 16 shared dependents. The largest ispnpm-resolving-resolver-base→pnpm-lockfilewith 21. Fixing the leaks themselves is not part of the PR.Written by an agent (Claude Code, claude-opus-5-5).
feat(crate-layers): ratchet the dependencies a crate leaks through it…
feat(crate-layers): check the product boundary between pnpm and pnpr (#…
refactor(pnpr-client): take explicit options instead of the configura…
feat(crate-layers): count only leaks a caller can reach (#18060)
feat(crate-layers): add a dependency structure matrix page (#18065)
refactor(config): cut the edges that add crates only config needs (#1…
zkochan commentedon Nov 13, 2026
On the remaining
pnpm-configitem: after pnpm/pnpm#18068 it has 20 direct and 40 transitive dependencies. The rest comes frompnpm-lockfile(18 transitive),pnpm-workspace(15), andpnpm-resolving-resolver-base(24, mostly throughpnpm-lockfile). Those are the formatspnpm-configexists to read: the workspace manifest and the lockfile settings. The only edges that add crates nothing else adds are now single crates (for examplepnpm-workspace-task-scheduler, which Rust's orphan rule pins topnpm-config). Further cuts would each save one or two crates. I suggest closing this item unless a specific dependency becomes a build-time or layering problem.Written by an agent (Claude Code, claude-opus-5-5).
zkochan commentedon Nov 27, 2026
pnpm/pnpm#18490 covers the tooling item "function-level call graph from a rust-analyzer SCIP index". It adds two reports that read the index:
crate-layers overlapslists the groups of functions in different top-level modules that access the same fields. The call graph drops a pair when one function reaches the other.crate-layers fieldslists the types whose fields two top-level modules both access, and--typelists the functions per module.Checked against the case this issue started from: on the tree before pnpm/pnpm#17686,
fieldslistsWorkspaceStateSettingsthird, with 51 fields accessed inoptimistic_repeat_install(21 functions) and 10 ininstall(4 functions). Onmainthe type is second:install_statereads 60 fields, andinstall(14 fields, 6 functions) andoptimistic_repeat_install(10 fields, 7 functions) still read it directly.overlapsprints 112 groups onmain. Two that look worth a follow-up: four functions build aNodeResolverfrom the same fourConfigfields, and five functions inpnpm-cli,pnpm-package-manager, andpnprderive lockfile settings from the same sixConfigfields.The reports are not part of
crate-layers check, and CI does not run them: making the index takes rust-analyzer about 3 minutes and 13 GB.The
pnpm-configitem is not part of the PR. Its count is now 22 direct and 49 transitive workspace dependencies, up from 20 and 40 after pnpm/pnpm#18068. All nine added crates were created since then:pnpm-ffi-processandpnpm-timeare direct, andpnpm-ffi-fs,pnpm-ffi-security,pnpm-ffi-signal,pnpm-ffi-sqlite,pnpm-ffi-webcontainer,pnpm-signal-registry, andpnpm-webcontainer-syscome through other crates. All nine are in the foundation layer, so the earlier suggestion to close that item still holds.Written by an agent (Claude Code, claude-fable-5-2).
feat(crate-layers): report state that several modules decide on (#18490)
zkochan commentedon Nov 27, 2026
pnpm/pnpm#18495 covers part of the item "Reduce what
pnpm-configpulls in transitively". It takespnpm-configfrom 49 to 45 workspace crates andpnpm-workspacefrom 22 to 17.My earlier comment looked only at the edges out of
pnpm-configitself. Measuring every edge in its dependency graph found one deeper:pnpm-workspace→pnpm-workspace-projects-graph, which existed for a 62-line adapter (GraphPkg) and brought in the graph crate,pnpm-catalogs-resolver,pnpm-catalogs-protocol-parser, andpnpm-workspace-range-resolver. The PR moves the adapter topnpm-package-manager. The crates that rebuild after an edit to the graph crate drop from 25 to 10.After it, no single edge removes more than three crates:
pnpm-config→pnpm-store-dirpnpm-store-dir,pnpm-ffi-sqlite,pnpm-shared-artifact-protocol)StoreDirpath type from the store indexpnpm-config→pnpm-resolving-resolver-basepnpm-registry)pnpm-configtakes from it, mostly setting types, to a lower cratepnpm-config→pnpm-workspace-task-schedulerpnpm-reporter)TaskDeclarationtrait, whichTaskSettingsimplements, with something the callers passpnpm-config→pnpm-package-is-installablepnpm-platform-tags)SupportedArchitecturesAll four together would leave 36. Each needs a new crate or an API change, and none of the crates they remove is a layering problem, so I suggest closing the item when the PR merges. The one with the most rebuild effect is
pnpm-store-dir: it had 57 commits in the last 60 days, and 32 crates rebuild after each.Written by an agent (Claude Code, claude-fable-5-2).
refactor(workspace): keep the projects graph out of pnpm-workspace (#…
zkochan commentedon Nov 27, 2026
pnpm/pnpm#18495 is merged. pnpm/pnpm#18504 takes the next edge from the table above:
pnpm-config→pnpm-workspace-task-scheduler.pnpm-configdepended on the scheduler only to implement itsTaskDeclarationtrait forTaskSettings. The trait becomes a struct thatpnpm-cli, the only caller, fills through a function it passes.pnpm-configgoes from 45 to 43 workspace crates. The crates that rebuild after an edit to the scheduler drop from 21 to 11.I read the code behind the other three edges. Each cut removes fewer crates than the table above says, because the types
pnpm-configuses need a home it still depends on:pnpm-configpnpm-store-dirStoreDir. Its inherent methods sit in eight modules ofpnpm-store-dirand would become extension traits or free functions for 32 dependent crates.pnpm-resolving-resolver-basepnpm-configtakes from it.pnpm-package-is-installableSupportedArchitecturesneedspnpm-platform-tags, so that dependency moves with it.I recommend closing the item when pnpm/pnpm#18504 merges, with
pnpm-configat 43.Written by an agent (Claude Code, claude-fable-5-2).
refactor(config): stop depending on the task scheduler (#18504)