Skip to content

Commit 0860159

Browse files
authored
fix: ensure workspace links query parents correctly (#6829)
1 parent 7c459d2 commit 0860159

File tree

2 files changed

+56
-14
lines changed

2 files changed

+56
-14
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,11 @@ const depTypes = {
695695
// the compare nodes array
696696
const hasParent = (node, compareNodes) => {
697697
// All it takes is one so we loop and return on the first hit
698-
for (const compareNode of compareNodes) {
698+
for (let compareNode of compareNodes) {
699+
if (compareNode.isLink) {
700+
compareNode = compareNode.target
701+
}
702+
699703
// follows logical parent for link anscestors
700704
if (node.isTop && (node.resolveParent === compareNode)) {
701705
return true

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

+51-13
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ t.test('query-selector-all', async t => {
2828
│ └── [email protected] (production dep of b, deduped)
2929
├─┬ [email protected] (production dep of query-selector-all-tests)
3030
│ └── [email protected] (production dep of bar)
31+
|-┬ [email protected] -> ./c (workspace)
32+
│ └── [email protected] (production dep of c, deduped)
3133
├─┬ [email protected] (dev dep of query-selector-all-tests)
3234
│ ├─┬ [email protected] (production dep of foo, deduped)
3335
│ │ └── [email protected] (overridden peer dep of bar)
@@ -65,6 +67,9 @@ t.test('query-selector-all', async t => {
6567
'1.0.0': undefined,
6668
'1.0.1': yesterday,
6769
},
70+
c: {
71+
'1.0.0': today,
72+
},
6873
'dash-separated-pkg': {
6974
'1.0.0': dayBeforeYesterday,
7075
'2.0.0': yesterday,
@@ -173,6 +178,7 @@ t.test('query-selector-all', async t => {
173178
},
174179
}),
175180
},
181+
c: t.fixture('symlink', '../c'),
176182
foo: {
177183
node_modules: {
178184
bar: {
@@ -275,10 +281,19 @@ t.test('query-selector-all', async t => {
275281
bar: '^2.0.0',
276282
},
277283
}) },
284+
c: {
285+
'package.json': JSON.stringify({
286+
name: 'c',
287+
version: '1.0.0',
288+
dependencies: {
289+
b: '^1.0.0',
290+
},
291+
}),
292+
},
278293
'package.json': JSON.stringify({
279294
name: 'query-selector-all-tests',
280295
version: '1.0.0',
281-
workspaces: ['a', 'b'],
296+
workspaces: ['a', 'b', 'c'],
282297
dependencies: {
283298
a: '^1.0.0',
284299
abbrev: '^1.1.1',
@@ -387,6 +402,7 @@ t.test('query-selector-all', async t => {
387402
388403
389404
405+
390406
'@npmcli/[email protected]',
391407
392408
@@ -404,6 +420,7 @@ t.test('query-selector-all', async t => {
404420
['* > *', [
405421
406422
423+
407424
408425
409426
@@ -425,18 +442,19 @@ t.test('query-selector-all', async t => {
425442
[':root > *', [
426443
427444
445+
428446
429447
430448
431449
'ipsum@npm:[email protected]',
432450
433451
434452
]],
435-
[':root > .workspace', ['[email protected]', '[email protected]']],
436-
[':root > *.workspace', ['[email protected]', '[email protected]']],
453+
[':root > .workspace', ['[email protected]', '[email protected]', '[email protected]']],
454+
[':root > *.workspace', ['[email protected]', '[email protected]', '[email protected]']],
437455
[':root > .workspace[name=a]', ['[email protected]']],
438456
[':root > [name=bar]', ['[email protected]']],
439-
[':root > .workspace[version=1.0.0]', ['[email protected]', '[email protected]']],
457+
[':root > .workspace[version=1.0.0]', ['[email protected]', '[email protected]', '[email protected]']],
440458
[':root > .workspace[name=a][version=1.0.0]', ['[email protected]']],
441459
[':root > :root', []],
442460
['* > :root', []],
@@ -452,6 +470,7 @@ t.test('query-selector-all', async t => {
452470
453471
454472
473+
455474
456475
457476
@@ -461,12 +480,12 @@ t.test('query-selector-all', async t => {
461480
462481
463482
483+
464484
465485
]],
466486
[':extraneous', ['@npmcli/[email protected]']],
467487
[':invalid', ['[email protected]']],
468-
469-
488+
470489
[':deduped', [
471490
472491
@@ -481,6 +500,7 @@ t.test('query-selector-all', async t => {
481500
482501
483502
503+
484504
'@npmcli/[email protected]',
485505
486506
@@ -494,34 +514,36 @@ t.test('query-selector-all', async t => {
494514
495515
496516
]],
497-
[':root > .workspace:not(#b)', ['[email protected]']],
498-
[':root > .workspace > *:not(#bar)', ['[email protected]', '[email protected]']],
517+
[':root > .workspace:not(#b)', ['[email protected]', '[email protected]']],
518+
[':root > .workspace > *:not(#bar)', ['[email protected]', '[email protected]', '[email protected]']],
499519
['.bundled ~ :not(.workspace)', [
500520
501521
502522
'ipsum@npm:[email protected]',
503523
504524
505525
]],
506-
['*:root > *:empty:not(*[name^=a], #b)', ['[email protected]']],
526+
['*:root > *:empty:not(*[name^=a], #b, #c)', ['[email protected]']],
507527
[':not(:not(:link))', [
508528
509529
530+
510531
]],
511532

512533
// has pseudo
513534
[':root > *:has(* > #bar:semver(1.4.0))', ['[email protected]']],
514535
['*:has(* > #bar:semver(1.4.0))', ['[email protected]']],
515536
['*:has(> #bar:semver(1.4.0))', ['[email protected]']],
516537
['.workspace:has(> * > #lorem)', ['[email protected]']],
517-
['.workspace:has(* #lorem, ~ #b)', ['[email protected]', '[email protected]']],
538+
['.workspace:has(* #lorem, ~ #b)', ['[email protected]', '[email protected]', '[email protected]']],
518539

519540
// is pseudo
520541
521542
// TODO: ipsum is not empty but its child is missing so it doesn't return a
522543
// result here
523544
[':root > *:is(.prod:not(:empty), .dev > [name=bar]) > *', [
524545
546+
525547
526548
527549
@@ -538,6 +560,7 @@ t.test('query-selector-all', async t => {
538560
539561
540562
563+
541564
'@npmcli/[email protected]',
542565
543566
@@ -557,6 +580,7 @@ t.test('query-selector-all', async t => {
557580
[':type(range)', [
558581
559582
583+
560584
561585
562586
@@ -584,11 +608,12 @@ t.test('query-selector-all', async t => {
584608
[':path(./node_modules/bar)', ['[email protected]']],
585609
[':path(node_modules/foo/node_modules/bar)', ['[email protected]']],
586610
[':path(**/bar)', ['[email protected]', '[email protected]']],
587-
[':path(*)', ['[email protected]', '[email protected]']],
611+
588612
[':path()', [
589613
590614
591615
616+
592617
'@npmcli/[email protected]',
593618
594619
@@ -609,6 +634,7 @@ t.test('query-selector-all', async t => {
609634
610635
611636
637+
612638
'@npmcli/[email protected]',
613639
614640
@@ -627,6 +653,7 @@ t.test('query-selector-all', async t => {
627653
628654
629655
656+
630657
631658
632659
@@ -690,6 +717,7 @@ t.test('query-selector-all', async t => {
690717
691718
692719
720+
693721
694722
695723
'ipsum@npm:[email protected]',
@@ -702,6 +730,7 @@ t.test('query-selector-all', async t => {
702730
703731
704732
733+
705734
706735
707736
@@ -720,6 +749,7 @@ t.test('query-selector-all', async t => {
720749
721750
722751
752+
723753
724754
725755
'ipsum@npm:[email protected]',
@@ -731,6 +761,7 @@ t.test('query-selector-all', async t => {
731761
732762
733763
764+
734765
735766
736767
'ipsum@npm:[email protected]',
@@ -832,6 +863,7 @@ t.test('query-selector-all', async t => {
832863
833864
834865
866+
835867
'@npmcli/[email protected]',
836868
837869
@@ -882,15 +914,18 @@ t.test('query-selector-all', async t => {
882914
883915
884916
917+
885918
886919
887920
888921
'ipsum@npm:[email protected]',
889922
890923
891924
]],
892-
['.workspace', ['[email protected]', '[email protected]']],
893-
925+
926+
927+
['.workspace .workspace', ['[email protected]', '[email protected]']],
928+
['.workspace .workspace .workspace', ['[email protected]']],
894929
['.workspace ~ *', [
895930
896931
@@ -911,9 +946,11 @@ t.test('query-selector-all', async t => {
911946
912947
]],
913948
['.dev *', [
949+
914950
915951
916952
953+
917954
918955
919956
]],
@@ -923,6 +960,7 @@ t.test('query-selector-all', async t => {
923960
['.bundled ~ *', [
924961
925962
963+
926964
927965
928966
'ipsum@npm:[email protected]',

0 commit comments

Comments
 (0)