fix: skip intersects() for non-semver specs like catalog: in peer dep checks#1710
Open
terminalchai wants to merge 1 commit intoraineorshine:mainfrom
Open
fix: skip intersects() for non-semver specs like catalog: in peer dep checks#1710terminalchai wants to merge 1 commit intoraineorshine:mainfrom
terminalchai wants to merge 1 commit intoraineorshine:mainfrom
Conversation
… checks When a pnpm workspace package lists a dependency using the catalog protocol (e.g. 'catalog:' or 'catalog:default'), that string is not a valid semver range. The peer dependency constraint checking code called: intersects(upgradedDependencies[peer], peerSpec) without first verifying that upgradedDependencies[peer] is a valid semver range. Since semver.intersects() internally calls semver.parse() which throws on invalid input, running ncu --peer -w on a workspace containing catalog: references in peerDependencies would crash with: TypeError: Invalid comparator: catalog: Fix: add !validRange(upgradedDependencies[peer]) guard in both places that call intersects() with a value sourced from the current/upgraded dependency map. When the installed version spec is not valid semver (catalog:, file:, git+, etc.) the constraint is treated as compatible (cannot be checked), which matches the existing !validRange(peerSpec) convention in the same code. Fixes raineorshine#1604
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.
Problem
When a pnpm workspace lists a dependency using the catalog protocol (e.g.
"catalog:"or"catalog:default"), that string is not a valid semver range.The peer dependency constraint checking code called
intersects(upgradedDependencies[peer], peerSpec)without first verifying thatupgradedDependencies[peer]is a valid semver range. Sincesemver.intersects()internally callssemver.parse()which throws on invalid input, runningncu --peer -won a workspace containingcatalog:references inpeerDependenciescrashes with:The same guard (
!validRange(peerSpec)) already exists for the right-hand operand — it was just missing for the left-hand one.Fixes #1604.
Fix
Add a
!validRange(upgradedDependencies[peer])guard in both places that callintersects()with a value sourced from the current/upgraded dependency map (getIgnoredUpgradesDueToPeerDeps.tsandupgradePackageDefinitions.ts).When the installed/upgraded version spec is not a valid semver range (
catalog:,file:,git+https://…, etc.) the constraint check is skipped and treated as compatible — matching the existing convention already applied to the peer spec side.A regression test covering the
catalog:case is included intest/peer.test.ts.