Skip to content

fix(npm-resolver): respect version constraints when falling back to workspace packages#10704

Merged
zkochan merged 2 commits intopnpm:mainfrom
roysandrew:pnpm-module-resolution-fix
Feb 28, 2026
Merged

fix(npm-resolver): respect version constraints when falling back to workspace packages#10704
zkochan merged 2 commits intopnpm:mainfrom
roysandrew:pnpm-module-resolution-fix

Conversation

@roysandrew
Copy link
Copy Markdown
Contributor

Fix regression introduced in 81f441c.

When link-workspace-packages=true, the fallback resolution paths (registry 404
and no matching registry version) pass update: Boolean(opts.update) to
tryResolveFromWorkspacePackages. On fresh installs without a lockfile entry,
opts.update is 'compatible' (truthy), which overrides the version spec to '*'
and matches any workspace package regardless of version.

Change both fallback call sites to pass update: false so version constraints
are always respected for non-workspace-protocol dependencies. The workspace:
protocol path returns before these blocks and correctly continues to use
opts.update.

Closes #10173

…orkspace packages

When link-workspace-packages=true, the fallback resolution paths (registry 404
and no matching registry version) pass update: Boolean(opts.update) to
tryResolveFromWorkspacePackages. On fresh installs without a lockfile entry,
opts.update is 'compatible' (truthy), which overrides the version spec to '*'
and matches any workspace package regardless of version.

Change both fallback call sites to pass update: false so version constraints
are always respected for non-workspace-protocol dependencies. The workspace:
protocol path returns before these blocks and correctly continues to use
opts.update.

Closes pnpm#10173
@roysandrew roysandrew marked this pull request as ready for review February 26, 2026 15:13
@roysandrew roysandrew requested a review from zkochan as a code owner February 26, 2026 15:13
@zkochan zkochan requested a review from Copilot February 26, 2026 15:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in @pnpm/npm-resolver where, with link-workspace-packages=true, fallback-to-workspace resolution could incorrectly ignore the requested version range during fresh installs (when opts.update is truthy), causing mismatched workspace packages to be linked.

Changes:

  • Pass update: false to tryResolveFromWorkspacePackages in both non-workspace fallback paths so workspace fallback always respects the requested version constraint.
  • Add regression tests covering 404 and no-matching-registry-version scenarios to ensure mismatched workspace versions are not linked.
  • Add a changeset for the patch release.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
resolving/npm-resolver/src/index.ts Ensures fallback-to-workspace resolution does not override dependency version constraints via update.
resolving/npm-resolver/test/index.ts Adds tests that fail if a mismatching workspace version is incorrectly linked during fallback resolution.
.changeset/legal-ways-accept.md Declares a patch release and documents the fix for link-workspace-packages=true.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zkochan zkochan merged commit 143ca78 into pnpm:main Feb 28, 2026
@welcome
Copy link
Copy Markdown

welcome bot commented Feb 28, 2026

Congrats on merging your first pull request! 🎉🎉🎉

zkochan added a commit that referenced this pull request Mar 7, 2026
…orkspace packages (#10704)

* fix(npm-resolver): respect version constraints when falling back to workspace packages

When link-workspace-packages=true, the fallback resolution paths (registry 404
and no matching registry version) pass update: Boolean(opts.update) to
tryResolveFromWorkspacePackages. On fresh installs without a lockfile entry,
opts.update is 'compatible' (truthy), which overrides the version spec to '*'
and matches any workspace package regardless of version.

Change both fallback call sites to pass update: false so version constraints
are always respected for non-workspace-protocol dependencies. The workspace:
protocol path returns before these blocks and correctly continues to use
opts.update.

Close #10173

* test: clarify npm-resolver test names for workspace version mismatch scenarios

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
zkochan added a commit that referenced this pull request Mar 7, 2026
…orkspace packages (#10704)

* fix(npm-resolver): respect version constraints when falling back to workspace packages

When link-workspace-packages=true, the fallback resolution paths (registry 404
and no matching registry version) pass update: Boolean(opts.update) to
tryResolveFromWorkspacePackages. On fresh installs without a lockfile entry,
opts.update is 'compatible' (truthy), which overrides the version spec to '*'
and matches any workspace package regardless of version.

Change both fallback call sites to pass update: false so version constraints
are always respected for non-workspace-protocol dependencies. The workspace:
protocol path returns before these blocks and correctly continues to use
opts.update.

Close #10173

* test: clarify npm-resolver test names for workspace version mismatch scenarios

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
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.

Package resolution for dependencies available in workspace is completely broken

3 participants