Skip to content

Commit

Permalink
fix: query with workspace descendents (#6782)
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 0dc6332 commit bef7481
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 => {
│ └── lorem@1.0.0 (production dep of baz)
├── abbrev@1.1.1 (production dep of query-selector-all-tests)
├─┬ b@1.0.0 -> ./b (workspace)
│ ├── a@2.0.0 (dev dep of b, deduped)
│ └── bar@2.0.0 (production dep of b, deduped)
├─┬ bar@2.0.0 (production dep of query-selector-all-tests)
│ └── moo@3.0.0 (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))', ['foo@2.2.2']],
['*:has(> #bar:semver(1.4.0))', ['foo@2.2.2']],
['.workspace:has(> * > #lorem)', ['a@1.0.0']],
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0']],
['.workspace:has(* #lorem, ~ #b)', ['a@1.0.0', 'b@1.0.0']],

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

0 comments on commit bef7481

Please sign in to comment.