Skip to content

Commit bef7481

Browse files
authored
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
│ └── [email protected] (production dep of baz)
2525
├── [email protected] (production dep of query-selector-all-tests)
2626
├─┬ [email protected] -> ./b (workspace)
27+
│ ├── [email protected] (dev dep of b, deduped)
2728
│ └── [email protected] (production dep of b, deduped)
2829
├─┬ [email protected] (production dep of query-selector-all-tests)
2930
│ └── [email protected] (production dep of bar)
@@ -513,7 +514,7 @@ t.test('query-selector-all', async t => {
513514
['*:has(* > #bar:semver(1.4.0))', ['[email protected]']],
514515
['*:has(> #bar:semver(1.4.0))', ['[email protected]']],
515516
['.workspace:has(> * > #lorem)', ['[email protected]']],
516-
['.workspace:has(* #lorem, ~ #b)', ['[email protected]']],
517+
['.workspace:has(* #lorem, ~ #b)', ['[email protected]', '[email protected]']],
517518

518519
// is pseudo
519520
@@ -960,5 +961,6 @@ t.test('query-selector-all', async t => {
960961
[':root #bar:semver(1) ~ *', ['[email protected]']],
961962
['#bar:semver(2), #foo', ['[email protected]', '[email protected]']],
962963
['#a, #bar:semver(2), #foo:semver(2.2.2)', ['[email protected]', '[email protected]', '[email protected]']],
964+
963965
])
964966
})

0 commit comments

Comments
 (0)