Support pnpm lockfileVersion 6.0 and 9.0 in parseLockFile#1165
Open
astegmaier wants to merge 15 commits into
Open
Support pnpm lockfileVersion 6.0 and 9.0 in parseLockFile#1165astegmaier wants to merge 15 commits into
astegmaier wants to merge 15 commits into
Conversation
- Regenerate workspace-tools API report (was stale: missing importers, optionalDependencies, name, and the new PnpmImporter types). - Export PnpmImporter and PnpmImporterDependencies from the entry point (referenced by the public PnpmLockFile) to clear an ae-forgotten-export warning, and add concise JSDoc to their members. - Reword two PnpmLockFile comments to avoid TSDoc HTML-parsing warnings. - Align the change-file wording with the lockfileVersion 6.0/9.0 framing. Co-authored-by: Copilot <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
parseLockFile(inworkspace-tools) normalizes yarn, npm, and pnpm lockfiles into one commonParsedLockshape so the rest of the toolchain is package-manager-agnostic. It's used by lage's content hasher (cache-key computation) and by downstream tools such as dependency-graph visualizers.The problem: for pnpm
lockfileVersion6.0 (pnpm 8) and 9.0 (pnpm 9+) the parser silently produces garbage. pnpm 6.0 changed dependency-path keys from/(name)/(version)toname@version(with a leading/and trailing(peer)/(patch_hash=…)suffixes), and 9.0 additionally moved dependency edges out ofpackages:into a newsnapshots:section. The existing code only understood the legacysplit("/")format, so every modern lockfile key mis-parses and the edges are never read at all.This PR teaches
parseLockFileto read pnpm 6.0/9.0 lockfiles, while leaving the legacy (< 6.0) codepath untouched.What it looks like today vs. with the fix
Today —
parseLockFile(...).objecton alockfileVersion: '9.0'lockfile:A consumer then can't resolve a single dependency edge.
With the fix — one snapshot key exercises most of the edge cases at once. The raw key
@testing-library/[email protected](@testing-library/[email protected])([email protected]([email protected]))([email protected])parses to:The remaining cases (each covered by a real fixture + test):
No regression for
< 6.0lockfilesThe entire change is gated behind a single version check, and the pre-existing
< 6branch is byte-for-byte unchanged. Frompackages/workspace-tools/src/lockfile/parsePnpmLock.ts:So pnpm 5.x lockfiles take exactly the same path they did before, and yarn/npm lockfiles are dispatched elsewhere in
parseLockFileand are not touched at all. Reviewers can verify regression-safety by confirming theelse ifblock matchesmain.Testing
describe.each(["basic-pnpm-6", "basic-pnpm-9"])block runs the edge-case assertions against both the 6.0 (packages:) and 9.0 (snapshots:) codepaths; importer assertions run against a monorepo fixture.workspace-tools: 345 passing.parseLockFilewas run against a large real-world pnpm monorepo. Before this change it emitted thousands of… not found in lockfilewarnings and a near-empty graph; after, its graph matches the one produced from the equivalent yarn version of the same repo (same tool) after normalization.Notes for reviewers
PnpmLockFile.packagesis now optional (9.0 lockfiles have nopackagesedges). This is a minor source-level type-narrowing for any TS consumer that readslock.packagesdirectly; no in-repo consumer does.resolveExternalDependenciesuses an O(n²) queue-dedup scan that this fix now exercises at scale on large pnpm monorepos. Not changed here; aSet-based membership check would make it linear.Change type
minor(purely additive: modern pnpm lockfiles that previously failed now work; existing behavior is unchanged).