Skip to content

Commit a3c1886

Browse files
committed
fix: workspace query bug
Fixes a query bug which omits some dependencies in scenarios where a workspace has a dependency on another workspace in the project. Signed-off-by: Brian DeHamer <bdehamer@github.com>
1 parent 1c93c44 commit a3c1886

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,20 @@ const hasParent = (node, compareNodes) => {
697697
// All it takes is one so we loop and return on the first hit
698698
for (const compareNode of compareNodes) {
699699
// follows logical parent for link anscestors
700-
if (node.isTop && (node.resolveParent === compareNode)) {
701-
return true
700+
if (node.isTop) {
701+
if (node.resolveParent === compareNode) {
702+
return true
703+
} else {
704+
// Top-level nodes have no edgesIn, so check the edgesOut
705+
// of the parent to see if any of them are links to this node
706+
for (const edge of compareNode.edgesOut.values()) {
707+
if (edge.to === node || edge.to?.target === node) {
708+
return true
709+
}
710+
}
711+
}
702712
}
713+
703714
// follows edges-in to check if they match a possible parent
704715
for (const edge of node.edgesIn) {
705716
if (edge && edge.from === compareNode) {

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

Lines changed: 3 additions & 1 deletion
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)