Skip to content

Commit bef7481

Browse files
authoredSep 15, 2023
fix: query with workspace descendents (#6782)
Fixes a query bug which omits some dependencies in scenarios where a workspace has a dependency on another workspace in the project.
1 parent 0dc6332 commit bef7481

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎workspaces/arborist/lib/query-selector-all.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,10 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
719719
}
720720

721721
if (node.isTop && node.resolveParent) {
722-
return hasAscendant(node.resolveParent, compareNodes)
722+
/* istanbul ignore if - investigate if linksIn check obviates need for this */
723+
if (hasAscendant(node.resolveParent, compareNodes)) {
724+
return true
725+
}
723726
}
724727
for (const edge of node.edgesIn) {
725728
// TODO Need a test with an infinite loop
@@ -731,6 +734,11 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
731734
return true
732735
}
733736
}
737+
for (const linkNode of node.linksIn) {
738+
if (hasAscendant(linkNode, compareNodes, seen)) {
739+
return true
740+
}
741+
}
734742
return false
735743
}
736744

‎workspaces/arborist/test/query-selector-all.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ t.test('query-selector-all', async t => {
2424
│ └── lorem@1.0.0 (production dep of baz)
2525
├── abbrev@1.1.1 (production dep of query-selector-all-tests)
2626
├─┬ b@1.0.0 -> ./b (workspace)
27+
│ ├── a@2.0.0 (dev dep of b, deduped)
2728
│ └── bar@2.0.0 (production dep of b, deduped)
2829
├─┬ bar@2.0.0 (production dep of query-selector-all-tests)
2930
│ └── moo@3.0.0 (production dep of bar)
@@ -513,7 +514,7 @@ t.test('query-selector-all', async t => {
513514
['*:has(* > #bar:semver(1.4.0))', ['foo@2.2.2']],
514515
['*:has(> #bar:semver(1.4.0))', ['foo@2.2.2']],
515516
['.workspace:has(> * > #lorem)', ['a@1.0.0']],
516-
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0']],
517+
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0', 'b@1.0.0']],
517518

518519
// is pseudo
519520
[':is(#a, #b) > *', ['a@1.0.0', 'bar@2.0.0', 'baz@1.0.0']],
@@ -960,5 +961,6 @@ t.test('query-selector-all', async t => {
960961
[':root #bar:semver(1) ~ *', ['dash-separated-pkg@1.0.0']],
961962
['#bar:semver(2), #foo', ['bar@2.0.0', 'foo@2.2.2']],
962963
['#a, #bar:semver(2), #foo:semver(2.2.2)', ['a@1.0.0', 'bar@2.0.0', 'foo@2.2.2']],
964+
['#b *', ['a@1.0.0', 'bar@2.0.0', 'baz@1.0.0', 'lorem@1.0.0', 'moo@3.0.0']],
963965
])
964966
})

0 commit comments

Comments
 (0)
Please sign in to comment.