Skip to content

Fix handling of virtual packages in Yarn2#11208

Draft
mnonnenmacher wants to merge 2 commits intomainfrom
fix-yarn2
Draft

Fix handling of virtual packages in Yarn2#11208
mnonnenmacher wants to merge 2 commits intomainfrom
fix-yarn2

Conversation

@mnonnenmacher
Copy link
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.

`@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
packages.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
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.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 57.48%. Comparing base (1190661) to head (59ebde2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ckage-managers/node/src/main/kotlin/yarn2/Yarn2.kt 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               main   #11208   +/-   ##
=========================================
  Coverage     57.47%   57.48%           
- Complexity     1704     1705    +1     
=========================================
  Files           346      346           
  Lines         12855    12860    +5     
  Branches       1222     1223    +1     
=========================================
+ Hits           7389     7393    +4     
  Misses         4992     4992           
- Partials        474      475    +1     
Flag Coverage Δ
funTest-external-tools 13.75% <83.33%> (+0.04%) ⬆️
funTest-no-external-tools 31.00% <0.00%> (-0.03%) ⬇️
test-ubuntu-24.04 42.43% <0.00%> (-0.03%) ⬇️

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.

.map { dependency ->
// Map virtual package locators to their corresponding real package locators as only their
// package infos contain the transitive dependencies.
val locator = virtualPackageRegex.find(dependency.locator)?.let {
Copy link
Member

Choose a reason for hiding this comment

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

This new code could be moved into a function (next to the regex) to keep this block more readable. E.g. fun getRealPackageLocator(locator: String): String

} ?: dependency.locator

packageInfoForLocator.getValue(locator)
}
Copy link
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
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..

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.

2 participants