Skip to content

Fix handling of virtual packages in Yarn2#11208

Merged
mnonnenmacher merged 2 commits into
mainfrom
fix-yarn2
May 5, 2026
Merged

Fix handling of virtual packages in Yarn2#11208
mnonnenmacher merged 2 commits into
mainfrom
fix-yarn2

Conversation

@mnonnenmacher
Copy link
Copy Markdown
Member

Adapt a Yarn2 test project to demonstrate the issue described in #8058 (and #11073) and a fix for the problem.

The PR is currently kept a draft because it triggers the issue demonstrated in #11207 for some projects.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.29%. Comparing base (5a6ffa6) to head (af6c54e).

Files with missing lines Patch % Lines
...managers/node/src/main/kotlin/yarn2/PackageInfo.kt 0.00% 2 Missing ⚠️
...ckage-managers/node/src/main/kotlin/yarn2/Yarn2.kt 0.00% 1 Missing ⚠️
...de/src/main/kotlin/yarn2/Yarn2DependencyHandler.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11208      +/-   ##
============================================
- Coverage     58.31%   58.29%   -0.03%     
+ Complexity     1760     1759       -1     
============================================
  Files           356      356              
  Lines         13259    13261       +2     
  Branches       1314     1314              
============================================
- Hits           7732     7730       -2     
- Misses         5039     5043       +4     
  Partials        488      488              
Flag Coverage Δ
funTest-no-external-tools 30.67% <0.00%> (-0.01%) ⬇️
test-ubuntu-24.04 41.84% <0.00%> (-0.01%) ⬇️
test-windows-2025 41.82% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread plugins/package-managers/node/src/main/kotlin/yarn2/Yarn2.kt Outdated
} ?: dependency.locator

packageInfoForLocator.getValue(locator)
}
Copy link
Copy Markdown
Member

@fviernau fviernau Dec 11, 2025

Choose a reason for hiding this comment

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

IIUC This change only works for "direct" dependencies.
A similar logic needs to be put into Yarn2DependencyHandler.dependenciesFor().

How about taking in my above comment mentioned function, and define it as extension property PackageInfo.realLocator next to the other ones in Yarn2DependencyHandler ?

Ideally, the test should be enhanced to have such virtual package as non-direct dependency too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

...Maybe there is a chance, that the cycle issue goes away with this..

Copy link
Copy Markdown
Member Author

@mnonnenmacher mnonnenmacher Apr 25, 2026

Choose a reason for hiding this comment

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

Ideally, the test should be enhanced to have such virtual package as non-direct dependency too.

Having such a dependency would be a requirement for me to be able to test if Yarn2DependencyHandler.dependenciesFor() was changed correctly. However, I spent a while looking for such a package and could not find one. All dependents of @csstools/css-color-parser have direct dependencies to the peer dependencies of @csstools/css-color-parser and it seems that in this case Yarn does not create a dependency to a virtual package in the tree.

The only idea I have is to create a workspace to simulate the scenario where a transitive dependency points to a virtual package.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have added the same dependency to the workspaces test project to verify that the fix now also works for transitive dependencies.

@mnonnenmacher mnonnenmacher force-pushed the fix-yarn2 branch 2 times, most recently from ae77f99 to 8f7493e Compare May 3, 2026 22:18
@mnonnenmacher mnonnenmacher marked this pull request as ready for review May 3, 2026 22:21
@mnonnenmacher mnonnenmacher requested a review from a team as a code owner May 3, 2026 22:21
@mnonnenmacher mnonnenmacher requested a review from fviernau May 3, 2026 22:23
@mnonnenmacher mnonnenmacher linked an issue May 3, 2026 that may be closed by this pull request
Comment thread plugins/package-managers/node/src/main/kotlin/yarn2/PackageInfo.kt Outdated
Comment thread plugins/package-managers/node/src/main/kotlin/yarn2/PackageInfo.kt Outdated
`@react-native-community:netinfo:11.2.1` was used to test the handling
of virtual packages which Yarn2+ creates when a package has peer
dependencies.

Replace it with `@csstools:css-color-parser:3.0.8` which in addition to
peer dependencies has also normal dependencies to demonstrate the bug
that `Yarn2` currently misses the transitive dependencies of such
dependencies.

Add the same dependency to the workspaces test project to showcase that
the bug also occurs if such a package is not a direct but a transitive
dependency.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@doubleopen.io>
When a package has peer dependencies, Yarn2+ creates a virtual package
for it that is used also in the output of `yarn info`. This virtual
package only contains the peer dependencies, while only the non-virtual
package contains the transitive dependencies.

Fix the issue that transitive dependencies of such packages are ignored
by mapping locators that point to virtual packages to locators that
point to the non-virtual packages.

Fixes #8058.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@doubleopen.io>
@mnonnenmacher mnonnenmacher requested a review from sschuberth May 4, 2026 12:21
@mnonnenmacher mnonnenmacher enabled auto-merge (rebase) May 4, 2026 12:21
@mnonnenmacher mnonnenmacher disabled auto-merge May 5, 2026 12:27
@mnonnenmacher mnonnenmacher merged commit 110413f into main May 5, 2026
30 of 32 checks passed
@mnonnenmacher mnonnenmacher deleted the fix-yarn2 branch May 5, 2026 12:27
@mnonnenmacher
Copy link
Copy Markdown
Member Author

Merged despite unrelated test failures.

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.

Analyzer cannot handle Yarn2+ virtual packages

3 participants