Skip to content

fix: skip intersects() for non-semver specs like catalog: in peer dep checks#1710

Open
terminalchai wants to merge 1 commit intoraineorshine:mainfrom
terminalchai:fix/catalog-ref-in-peer-deps
Open

fix: skip intersects() for non-semver specs like catalog: in peer dep checks#1710
terminalchai wants to merge 1 commit intoraineorshine:mainfrom
terminalchai:fix/catalog-ref-in-peer-deps

Conversation

@terminalchai
Copy link
Copy Markdown
Contributor

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 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 crashes with:

TypeError: Invalid comparator: catalog:

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 call intersects() with a value sourced from the current/upgraded dependency map (getIgnoredUpgradesDueToPeerDeps.ts and upgradePackageDefinitions.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 in test/peer.test.ts.

… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catalog in peerDependencies is not recognized

1 participant