fix(arborist): don't fetch packuments for uninstallable optional peer deps - #9877
Open
danielroe wants to merge 2 commits into
Open
fix(arborist): don't fetch packuments for uninstallable optional peer deps#9877danielroe wants to merge 2 commits into
danielroe wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
this is a PR aimed to skip fetching packuments for optional peers that won't be installed. this can be extremely costly.
for example, with an empty cache,
npm install viteinto an empty project installs 10 packages but fetches full packuments forplaywright(16.6MB),@types/node(11MB),webdriverio,jsdom,sass,less,terser, and (viavite's optional peer onvitest) all of vitest's optional peers too:loadPeerSetresolves unmet optional peer edges into the virtual root, even though they won't be used and in fact be pruned later onthe fix is very simple; we just skip
peerOptionaledges if they have no current resolution and no parent edge. if something else ends up installing the package, the edge is still validated at placement time.having said all of that, I'm a relative newcomer to the npm cli, so do let me know if there's a reason for this fetching that I'm missing 🙏
Note
the
nest when peerOptional conflictssnapshot did change shape.imo it was a bug before - the unmet optional peer was eagerly placed and 'won' the top-level slot, forcing the required peer chain to nest, but now the required chain wins and the optional subtree nests instead.
both before/after were valid trees (two copies of the conflicted peer, all edges valid, etc). I've added assertions for this, but it's worth noting that installs with conflicting optional peers can produce a differently shaped
node_modulesthan before.(ht to @pi0, who spotted this)
References
Fixes #9876