This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoid infinite loops in peer dep replacements
Fix: #325 Fix: npm/cli#3787 Replacing a peerDep and leaving it to buildIdealTree to do the right thing can lead to infinite regress in some cases. For example: ``` project -> (a) a -> (x, y, j@1) x -> PEER(j@1) y -> PEER(j@2) ``` In this case, when we get to the `j` peer dependency, we find that there's nowhere to place it (since it's relied upon by a dependency at the top level, either x or y), so we replace the conflicted version, and expect that buildIdealTree will find a new home for it. However, the next pass does the same thing, and so on. This patch addresses the problem in the following way. 1. Collect all the peerEntrySets containing the dependency to be replaced. 2. If all of them _can_ be placed deeper in the tree, we remove the conflicting peerEntrySet, and mark all incoming edges as needing re-evaluation. In the case described above, this means that `x` will be removed as well as `j`, and eventually placed under `a`, where there is no conflict. 3. If any peerEntrySet _cannot_ be placed deeper in the tree, then we mark the offending edge as overridden, so that it won't be re-evaluated by buildIdealTree. This properly finds the nested tree fully when it is possible, and prints the appropriate ERESOLVE warning when it is not. PR-URL: #326 Credit: @isaacs Close: #326 Reviewed-by: @lukekarrys
- Loading branch information