Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created April 27, 2021 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/cd279acf2c8b8c728c7a89127ac1e292 to your computer and use it in GitHub Desktop.
Save isaacs/cd279acf2c8b8c728c7a89127ac1e292 to your computer and use it in GitHub Desktop.
diff --git a/lib/arborist/build-ideal-tree.js b/lib/arborist/build-ideal-tree.js
index 78192cdd..49b21ca2 100644
--- a/lib/arborist/build-ideal-tree.js
+++ b/lib/arborist/build-ideal-tree.js
@@ -1647,12 +1647,34 @@ This is a one-time fix-up, please be patient...
// to get the conflict here so that we can decide whether to
// accept the current dep node, clobber it, or fail the install.
if (edge.from === target && edge.valid) {
+ // replacement from virtual root
const rep = dep.parent.children.get(edge.name)
- const override = rep && ([...rep.edgesIn].some(e => !e.valid))
- if (!rep || !rep.satisfies(edge) || override) {
- canReplace = false
- break OUTER
+ // not going to replace it, so make sure it won't cause problems
+ // if the things we ARE replacing are going to break the edges
+ // for the thing that has to be here, then it's a conflict.
+ if (!rep) {
+ const current = edge.to
+ for (const repEdge of current.edgesOut.values()) {
+ const newRepDep = dep.parent.children.get(repEdge.name)
+ if (repEdge.valid && newRepDep && !newRepDep.satisfies(repEdge)) {
+ canReplace = false
+ break OUTER
+ }
+ }
+ continue
}
+
+ // was said replacement an override already?
+ const override = [...rep.edgesIn].some(e => !e.valid)
+ // if we have a rep, and it's ok to put in this location, and
+ // it's not already part of an override in the peerSet, then
+ // we can continue with it.
+ if (rep.satisfies(edge) && !override)
+ continue
+
+ // Otherwise, we cannot replace.
+ canReplace = false
+ break OUTER
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment