Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query with workspace descendents #6782

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
│ └── [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]']],
wraithgar marked this conversation as resolved.
Show resolved Hide resolved

// 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]']],
])
})