Skip to content

Commit

Permalink
fix: query with workspace descendents (#6811)
Browse files Browse the repository at this point in the history
Fixes a query bug which omits some dependencies in scenarios where a
workspace has a dependency on another workspace in the project.
  • Loading branch information
bdehamer authored Sep 15, 2023
1 parent fdb8a86 commit da3c0d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 9 additions & 1 deletion workspaces/arborist/lib/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,10 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
}

if (node.isTop && node.resolveParent) {
return hasAscendant(node.resolveParent, compareNodes)
/* istanbul ignore if - investigate if linksIn check obviates need for this */
if (hasAscendant(node.resolveParent, compareNodes)) {
return true
}
}
for (const edge of node.edgesIn) {
// TODO Need a test with an infinite loop
Expand All @@ -731,6 +734,11 @@ const hasAscendant = (node, compareNodes, seen = new Set()) => {
return true
}
}
for (const linkNode of node.linksIn) {
if (hasAscendant(linkNode, compareNodes, seen)) {
return true
}
}
return false
}

Expand Down
4 changes: 3 additions & 1 deletion workspaces/arborist/test/query-selector-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ t.test('query-selector-all', async t => {
│ └── [email protected] (production dep of baz)
├── [email protected] (production dep of query-selector-all-tests)
├─┬ [email protected] -> ./b (workspace)
│ ├── [email protected] (dev dep of b, deduped)
│ └── [email protected] (production dep of b, deduped)
├─┬ [email protected] (production dep of query-selector-all-tests)
│ └── [email protected] (production dep of bar)
Expand Down Expand Up @@ -513,7 +514,7 @@ t.test('query-selector-all', async t => {
['*:has(* > #bar:semver(1.4.0))', ['[email protected]']],
['*:has(> #bar:semver(1.4.0))', ['[email protected]']],
['.workspace:has(> * > #lorem)', ['[email protected]']],
['.workspace:has(* #lorem, ~ #b)', ['[email protected]']],
['.workspace:has(* #lorem, ~ #b)', ['[email protected]', '[email protected]']],

// is pseudo
[':is(#a, #b) > *', ['[email protected]', '[email protected]', '[email protected]']],
Expand Down Expand Up @@ -960,5 +961,6 @@ t.test('query-selector-all', async t => {
[':root #bar:semver(1) ~ *', ['[email protected]']],
['#bar:semver(2), #foo', ['[email protected]', '[email protected]']],
['#a, #bar:semver(2), #foo:semver(2.2.2)', ['[email protected]', '[email protected]', '[email protected]']],
['#b *', ['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]']],
])
})

0 comments on commit da3c0d4

Please sign in to comment.