Skip to content

Conversation

owlstronaut
Copy link
Contributor

@owlstronaut owlstronaut commented Sep 17, 2025

Summary

Fixes peer dependency flag propagation in npm's dependency resolution system by correcting how "peer": true flags are calculated and applied.

Problem

Peer dependency flags were inconsistently and incorrectly calculated, leading to incorrect or missing "peer": true flags in the ideal tree, which could cause dependency resolution issues.

#8431 revealed a number of bugs, the worst of which appears to be that many packages in an ideal tree were marked peer when they shouldn't have been. If they were also optional, they were being removed by this pruning. This is my attempt to make a forward-fix instead of revert the aforementioned correct but also (through no fault of its own) disruptive PR #8431 .

This doesn't solve the problem of legitimate peerOptionals being uninstallable even with npm i <peer-optional-package>. It both makes sense for that to be pruned, but also for people that do it to have it either install or warn them. Right now it silently moves along. We could allow it to not be pruned that 1 time by using explicitRequests, but would subsequently be pruned on further installs.

Related:
#8464
#8431
#8489

@owlstronaut owlstronaut force-pushed the owlstronaut/fix-peer-flag-calc branch 4 times, most recently from 90d9c5e to bcd771f Compare September 17, 2025 21:13
@owlstronaut owlstronaut marked this pull request as ready for review September 17, 2025 21:48
@owlstronaut owlstronaut requested a review from a team as a code owner September 17, 2025 21:48
@owlstronaut
Copy link
Contributor Author

@G-Rath @jenseng Would love your take on this if you find time. I'm attempting to fix-foreward rather than revert, but this stuff is pretty meaty.

@jenseng
Copy link
Contributor

jenseng commented Sep 17, 2025

@owlstronaut I've confirmed that this fixes my simple repro here ... npm install succeeds, and the lockfile no longer marks those deps as "peer": true 🥳

@jenseng
Copy link
Contributor

jenseng commented Sep 17, 2025

The fix also works in our internal repos whose installs failed under npm@11.5.x 🚀

@wraithgar
Copy link
Member

Thank you so much for reviewing this @jenseng it really helps when folks with domain knowledge do this.

@wraithgar wraithgar self-assigned this Sep 18, 2025
@owlstronaut owlstronaut force-pushed the owlstronaut/fix-peer-flag-calc branch from 6623b75 to cb986c5 Compare September 18, 2025 22:10
"integrity": "sha512-UlLAnTPrFdNGoFtbSXwcGFQBtQZJCNjaN6hQNP3UPvuNXT1i82N26KL3dZeIpNalWywr9IuQuncaAfUaS1g6sQ==",
"dev": true,
"license": "MIT",
"peer": true,
Copy link
Member

@wraithgar wraithgar Sep 19, 2025

Choose a reason for hiding this comment

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

Just wanted to double check some of these and the very first one is good. This is being correctly flagged as a peer, from npm explain @babel/core@7.28.0:

peer @babel/core@"^7.0.0" from @babel/helper-module-transforms@7.27.3

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.

3 participants