Skip to content

Commit cff9ce9

Browse files
fix: pass _isRoot context where missing (#9237)
Backport of #9206 to `release/v11`
1 parent d249341 commit cff9ce9

3 files changed

Lines changed: 20 additions & 30 deletions

File tree

workspaces/arborist/lib/arborist/build-ideal-tree.js

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ This is a one-time fix-up, please be patient...
950950
tree: pd,
951951
getChildren: pd => pd.children,
952952
visit: pd => {
953-
const { placed, edge, canPlace: cpd } = pd
953+
const { placed, edge, canPlace: cpd, parent } = pd
954954
// if we didn't place anything, nothing to do here
955955
if (!placed) {
956956
return
@@ -1011,25 +1011,22 @@ This is a one-time fix-up, please be patient...
10111011
return
10121012
}
10131013

1014-
// lastly, also check for the missing deps of the node we placed,
1015-
// and any holes created by pruning out conflicted peer sets.
1014+
// lastly, also check for the missing deps of the node we placed, and any holes created by pruning out conflicted peer sets.
10161015
this.#depsQueue.push(placed)
10171016
for (const dep of pd.needEvaluation) {
10181017
this.#depsSeen.delete(dep)
10191018
this.#depsQueue.push(dep)
10201019
}
10211020

10221021
// pre-fetch any problem edges, since we'll need these soon
1023-
// if it fails at this point, though, don't worry because it
1024-
// may well be an optional dep that has gone missing. it'll
1025-
// fail later anyway.
1022+
// if it fails at this point, though, don't worry because it may well be an optional dep that has gone missing
1023+
// it'll fail later anyway
10261024
for (const e of this.#problemEdges(placed)) {
1027-
// XXX This is somehow load bearing. This makes tests that print
1028-
// the ideal tree of a tree with tarball dependencies fail. This
1029-
// can't be changed or removed till we figure out why
1025+
// XXX This is somehow load bearing. This makes tests that print the ideal tree of a tree with tarball dependencies fail
1026+
// This can't be changed or removed till we figure out why
10301027
// The test is named "tarball deps with transitive tarball deps"
10311028
promises.push(() =>
1032-
this.#fetchManifest(npa.resolve(e.name, e.spec, fromPath(placed, e)))
1029+
this.#fetchManifest(npa.resolve(e.name, e.spec, fromPath(placed, e)), parent)
10331030
.catch(() => null)
10341031
)
10351032
}
@@ -1047,26 +1044,18 @@ This is a one-time fix-up, please be patient...
10471044
return this.#buildDepStep()
10481045
}
10491046

1050-
// loads a node from an edge, and then loads its peer deps (and their
1051-
// peer deps, on down the line) into a virtual root parent.
1047+
// loads a node from an edge, and then loads its peer deps (and their peer deps, on down the line) into a virtual root parent.
10521048
async #nodeFromEdge (edge, parent_, secondEdge, required) {
1053-
// create a virtual root node with the same deps as the node that
1054-
// is requesting this one, so that we can get all the peer deps in
1055-
// a context where they're likely to be resolvable.
1056-
// Note that the virtual root will also have virtual copies of the
1057-
// targets of any child Links, so that they resolve appropriately.
1049+
// create a virtual root node with the same deps as the node that is requesting this one, so that we can get all the peer deps in a context where they're likely to be resolvable.
1050+
// Note that the virtual root will also have virtual copies of the targets of any child Links, so that they resolve appropriately.
10581051
const parent = parent_ || this.#virtualRoot(edge.from)
10591052

10601053
const spec = npa.resolve(edge.name, edge.spec, edge.from.path)
10611054
const first = await this.#nodeFromSpec(edge.name, spec, parent, edge)
10621055

1063-
// we might have a case where the parent has a peer dependency on
1064-
// `foo@*` which resolves to v2, but another dep in the set has a
1065-
// peerDependency on `foo@1`. In that case, if we force it to be v2,
1066-
// we're unnecessarily triggering an ERESOLVE.
1067-
// If we have a second edge to worry about, and it's not satisfied
1068-
// by the first node, try a second and see if that satisfies the
1069-
// original edge here.
1056+
// we might have a case where the parent has a peer dependency on `foo@*` which resolves to v2, but another dep in the set has a peerDependency on `foo@1`.
1057+
// In that case, if we force it to be v2, we're unnecessarily triggering an ERESOLVE.
1058+
// If we have a second edge to worry about, and it's not satisfied by the first node, try a second and see if that satisfies the original edge here.
10701059
const spec2 = secondEdge && npa.resolve(
10711060
edge.name,
10721061
secondEdge.spec,
@@ -1210,11 +1199,12 @@ This is a one-time fix-up, please be patient...
12101199
return problems
12111200
}
12121201

1213-
async #fetchManifest (spec) {
1202+
async #fetchManifest (spec, parent) {
12141203
const options = {
12151204
...this.options,
12161205
avoid: this.#avoidRange(spec.name),
12171206
fullMetadata: true,
1207+
_isRoot: parent?.isProjectRoot || parent?.isWorkspace,
12181208
}
12191209
// get the intended spec and stored metadata from yarn.lock file,
12201210
// if available and valid.
@@ -1231,10 +1221,8 @@ This is a one-time fix-up, please be patient...
12311221
}
12321222

12331223
async #nodeFromSpec (name, spec, parent, edge) {
1234-
// pacote will slap integrity on its options, so we have to clone
1235-
// the object so it doesn't get mutated.
1236-
// Don't bother to load the manifest for link deps, because the target
1237-
// might be within another package that doesn't exist yet.
1224+
// pacote will slap integrity on its options, so we have to clone the object so it doesn't get mutated.
1225+
// Don't bother to load the manifest for link deps, because the target might be within another package that doesn't exist yet.
12381226
const { installLinks, legacyPeerDeps } = this
12391227
const isWorkspace = this.idealTree.workspaces && this.idealTree.workspaces.has(spec.name)
12401228

@@ -1287,7 +1275,7 @@ This is a one-time fix-up, please be patient...
12871275

12881276
// spec isn't a directory, and either isn't a workspace or the workspace we have
12891277
// doesn't satisfy the edge. try to fetch a manifest and build a node from that.
1290-
return this.#fetchManifest(spec)
1278+
return this.#fetchManifest(spec, parent)
12911279
.then(pkg => new Node({ name, pkg, parent, installLinks, legacyPeerDeps }), error => {
12921280
error.requiredBy = edge.from.location || '.'
12931281

workspaces/arborist/lib/arborist/isolated-reifier.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ module.exports = cls => class IsolatedReifier extends cls {
157157
...this.options,
158158
resolved: node.resolved,
159159
integrity: node.integrity,
160+
// TODO _isRoot
160161
})
161162
const Arborist = this.constructor
162163
const arb = new Arborist({ ...this.options, path: dir })

workspaces/arborist/lib/arborist/reify.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ module.exports = cls => class Reifier extends cls {
737737
...this.options,
738738
resolved: node.resolved,
739739
integrity: node.integrity,
740+
_isRoot: node.parent?.isProjectRoot || node.parent?.isWorkspace,
740741
})
741742
// store nodes don't use Node class so node.package doesn't get updated
742743
if (node.isInStore) {

0 commit comments

Comments
 (0)