Skip to content

Commit 9d02e6d

Browse files
authored
Use object instead of string to represent package in Node API (#609)
1 parent dc6a6c8 commit 9d02e6d

File tree

3 files changed

+72
-65
lines changed

3 files changed

+72
-65
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ const result = {
141141
name: 'eslint',
142142
versions: [
143143
{
144-
packages: ['package1', 'package2'],
144+
packages: [{ pathRelative: 'package1' }, { pathRelative: 'package2' }],
145145
version: '^7.0.0',
146146
},
147147
{
148-
packages: ['package3'],
148+
packages: [{ pathRelative: 'package3' }],
149149
version: '^8.0.0',
150150
},
151151
],
@@ -172,7 +172,7 @@ const result = {
172172
| `isFixable` | `true` if the mismatching versions of this dependency are autofixable. |
173173
| `isMismatching` | `true` if there are multiple versions of this dependency. |
174174
| `name` | The dependency's name. |
175-
| `versions` | A list of the versions present of this dependency and the packages each is found in, in the form of: `{ version: string, packages: string[] }`. The `packages` array has relative paths to each package. |
175+
| `versions` | A list of the versions present of this dependency and the packages each is found in, in the form of: `{ version: string, packages: { pathRelative: string }[] }`. |
176176

177177
See [`lib/cli.ts`](./lib/cli.ts) for an example of how to use it.
178178

lib/cdvc.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ type Dependency = {
1212
isMismatching: boolean;
1313
versions: readonly {
1414
version: string;
15-
/** Relative path to each package.*/
16-
packages: readonly string[];
15+
packages: readonly { pathRelative: string }[];
1716
}[];
1817
};
1918

@@ -60,7 +59,9 @@ export class CDVC {
6059
isMismatching: this.dependencies[name].isMismatching,
6160
versions: this.dependencies[name].versions.map((version) => ({
6261
version: version.version,
63-
packages: version.packages.map((package_) => package_.pathRelative),
62+
packages: version.packages.map((package_) => ({
63+
pathRelative: package_.pathRelative,
64+
})),
6465
})),
6566
};
6667
}

test/lib/cdvc-test.ts

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ describe('CDVC', function () {
2929
versions: [
3030
{
3131
packages: [
32-
path.join('@scope1', 'package1'),
33-
path.join('@scope1', 'package2'),
34-
path.join('@scope2', 'deps-only'),
35-
'package1',
32+
{ pathRelative: path.join('@scope1', 'package1') },
33+
{ pathRelative: path.join('@scope1', 'package2') },
34+
{ pathRelative: path.join('@scope2', 'deps-only') },
35+
{ pathRelative: 'package1' },
3636
],
3737
version: '^4.5.6',
3838
},
@@ -45,10 +45,10 @@ describe('CDVC', function () {
4545
versions: [
4646
{
4747
packages: [
48-
path.join('@scope1', 'package1'),
49-
path.join('@scope1', 'package2'),
50-
path.join('@scope2', 'dev-deps-only'),
51-
'package1',
48+
{ pathRelative: path.join('@scope1', 'package1') },
49+
{ pathRelative: path.join('@scope1', 'package2') },
50+
{ pathRelative: path.join('@scope2', 'dev-deps-only') },
51+
{ pathRelative: 'package1' },
5252
],
5353
version: '^7.8.9',
5454
},
@@ -61,11 +61,11 @@ describe('CDVC', function () {
6161
versions: [
6262
{
6363
packages: [
64-
'',
65-
path.join('@scope1', 'package1'),
66-
path.join('@scope1', 'package2'),
67-
path.join('@scope2', 'deps-only'),
68-
'package1',
64+
{ pathRelative: '' },
65+
{ pathRelative: path.join('@scope1', 'package1') },
66+
{ pathRelative: path.join('@scope1', 'package2') },
67+
{ pathRelative: path.join('@scope2', 'deps-only') },
68+
{ pathRelative: 'package1' },
6969
],
7070
version: '1.2.3',
7171
},
@@ -77,7 +77,7 @@ describe('CDVC', function () {
7777
name: 'foo1',
7878
versions: [
7979
{
80-
packages: ['package1'],
80+
packages: [{ pathRelative: 'package1' }],
8181
version: '^1.0.0',
8282
},
8383
],
@@ -91,11 +91,11 @@ describe('CDVC', function () {
9191
versions: [
9292
{
9393
packages: [
94-
'',
95-
path.join('@scope1', 'package1'),
96-
path.join('@scope1', 'package2'),
97-
path.join('@scope2', 'deps-only'),
98-
'package1',
94+
{ pathRelative: '' },
95+
{ pathRelative: path.join('@scope1', 'package1') },
96+
{ pathRelative: path.join('@scope1', 'package2') },
97+
{ pathRelative: path.join('@scope2', 'deps-only') },
98+
{ pathRelative: 'package1' },
9999
],
100100
version: '1.2.3',
101101
},
@@ -120,8 +120,8 @@ describe('CDVC', function () {
120120
versions: [
121121
{
122122
packages: [
123-
path.join('@scope1', 'package1'),
124-
path.join('@scope1', 'package2'),
123+
{ pathRelative: path.join('@scope1', 'package1') },
124+
{ pathRelative: path.join('@scope1', 'package2') },
125125
],
126126
version: '^4.5.6',
127127
},
@@ -133,11 +133,11 @@ describe('CDVC', function () {
133133
name: 'baz',
134134
versions: [
135135
{
136-
packages: [path.join('@scope1', 'package1')],
136+
packages: [{ pathRelative: path.join('@scope1', 'package1') }],
137137
version: '^7.8.9',
138138
},
139139
{
140-
packages: [path.join('@scope1', 'package2')],
140+
packages: [{ pathRelative: path.join('@scope1', 'package2') }],
141141
version: '^8.0.0',
142142
},
143143
],
@@ -149,14 +149,14 @@ describe('CDVC', function () {
149149
versions: [
150150
{
151151
packages: [
152-
'',
153-
path.join('@scope1', 'package2'),
154-
path.join('@scope1', 'package3'),
152+
{ pathRelative: '' },
153+
{ pathRelative: path.join('@scope1', 'package2') },
154+
{ pathRelative: path.join('@scope1', 'package3') },
155155
],
156156
version: '1.2.0',
157157
},
158158
{
159-
packages: [path.join('@scope1', 'package1')],
159+
packages: [{ pathRelative: path.join('@scope1', 'package1') }],
160160
version: '1.3.0',
161161
},
162162
],
@@ -183,11 +183,11 @@ describe('CDVC', function () {
183183
name: 'baz',
184184
versions: [
185185
{
186-
packages: [path.join('@scope1', 'package1')],
186+
packages: [{ pathRelative: path.join('@scope1', 'package1') }],
187187
version: '^7.8.9',
188188
},
189189
{
190-
packages: [path.join('@scope1', 'package2')],
190+
packages: [{ pathRelative: path.join('@scope1', 'package2') }],
191191
version: '^8.0.0',
192192
},
193193
],
@@ -198,7 +198,7 @@ describe('CDVC', function () {
198198
name: 'foo',
199199
versions: [
200200
{
201-
packages: [''],
201+
packages: [{ pathRelative: '' }],
202202
version: '1.2.0',
203203
},
204204
],
@@ -225,8 +225,8 @@ describe('CDVC', function () {
225225
versions: [
226226
{
227227
packages: [
228-
path.join('@scope1', 'package1'),
229-
path.join('@scope1', 'package2'),
228+
{ pathRelative: path.join('@scope1', 'package1') },
229+
{ pathRelative: path.join('@scope1', 'package2') },
230230
],
231231
version: '^4.5.6',
232232
},
@@ -239,13 +239,13 @@ describe('CDVC', function () {
239239
versions: [
240240
{
241241
packages: [
242-
path.join('@scope1', 'package2'),
243-
path.join('@scope1', 'package3'),
242+
{ pathRelative: path.join('@scope1', 'package2') },
243+
{ pathRelative: path.join('@scope1', 'package3') },
244244
],
245245
version: '1.2.0',
246246
},
247247
{
248-
packages: [path.join('@scope1', 'package1')],
248+
packages: [{ pathRelative: path.join('@scope1', 'package1') }],
249249
version: '1.3.0',
250250
},
251251
],
@@ -271,7 +271,7 @@ describe('CDVC', function () {
271271
name: 'bar',
272272
versions: [
273273
{
274-
packages: [''],
274+
packages: [{ pathRelative: '' }],
275275
version: '^1.0.0',
276276
},
277277
],
@@ -282,7 +282,7 @@ describe('CDVC', function () {
282282
name: 'foo',
283283
versions: [
284284
{
285-
packages: [''],
285+
packages: [{ pathRelative: '' }],
286286
version: '^2.0.0',
287287
},
288288
],
@@ -358,7 +358,10 @@ describe('CDVC', function () {
358358
versions: [
359359
{
360360
version: '^1.0.0',
361-
packages: ['', 'package1'],
361+
packages: [
362+
{ pathRelative: '' },
363+
{ pathRelative: 'package1' },
364+
],
362365
},
363366
],
364367
},
@@ -369,15 +372,15 @@ describe('CDVC', function () {
369372
versions: [
370373
{
371374
version: '^1.0.0',
372-
packages: [''],
375+
packages: [{ pathRelative: '' }],
373376
},
374377
{
375378
version: '^1.2.0',
376-
packages: [''],
379+
packages: [{ pathRelative: '' }],
377380
},
378381
{
379382
version: '^2.0.0',
380-
packages: ['package1'],
383+
packages: [{ pathRelative: 'package1' }],
381384
},
382385
],
383386
},
@@ -403,7 +406,7 @@ describe('CDVC', function () {
403406
name: 'bar',
404407
versions: [
405408
{
406-
packages: [''],
409+
packages: [{ pathRelative: '' }],
407410
version: '^1.0.0',
408411
},
409412
],
@@ -414,7 +417,7 @@ describe('CDVC', function () {
414417
name: 'foo',
415418
versions: [
416419
{
417-
packages: [''],
420+
packages: [{ pathRelative: '' }],
418421
version: '^2.0.0',
419422
},
420423
],
@@ -495,7 +498,10 @@ describe('CDVC', function () {
495498
versions: [
496499
{
497500
version: '^1.0.0',
498-
packages: ['', 'package1'],
501+
packages: [
502+
{ pathRelative: '' },
503+
{ pathRelative: 'package1' },
504+
],
499505
},
500506
],
501507
},
@@ -506,15 +512,15 @@ describe('CDVC', function () {
506512
versions: [
507513
{
508514
version: '^1.0.0',
509-
packages: [''],
515+
packages: [{ pathRelative: '' }],
510516
},
511517
{
512518
version: '^1.2.0',
513-
packages: [''],
519+
packages: [{ pathRelative: '' }],
514520
},
515521
{
516522
version: '^2.0.0',
517-
packages: ['package1'],
523+
packages: [{ pathRelative: 'package1' }],
518524
},
519525
],
520526
},
@@ -540,7 +546,7 @@ describe('CDVC', function () {
540546
name: 'bar',
541547
versions: [
542548
{
543-
packages: [''],
549+
packages: [{ pathRelative: '' }],
544550
version: '^1.0.0',
545551
},
546552
],
@@ -551,7 +557,7 @@ describe('CDVC', function () {
551557
name: 'foo',
552558
versions: [
553559
{
554-
packages: [''],
560+
packages: [{ pathRelative: '' }],
555561
version: '^2.0.0',
556562
},
557563
],
@@ -594,8 +600,8 @@ describe('CDVC', function () {
594600
versions: [
595601
{
596602
packages: [
597-
path.join('@scope1', 'package1'),
598-
path.join('@scope1', 'package2'),
603+
{ pathRelative: path.join('@scope1', 'package1') },
604+
{ pathRelative: path.join('@scope1', 'package2') },
599605
],
600606
version: '^4.5.6',
601607
},
@@ -607,11 +613,11 @@ describe('CDVC', function () {
607613
name: 'baz',
608614
versions: [
609615
{
610-
packages: [path.join('@scope1', 'package1')],
616+
packages: [{ pathRelative: path.join('@scope1', 'package1') }],
611617
version: '^7.8.9',
612618
},
613619
{
614-
packages: [path.join('@scope1', 'package2')],
620+
packages: [{ pathRelative: path.join('@scope1', 'package2') }],
615621
version: '^8.0.0',
616622
},
617623
],
@@ -664,11 +670,11 @@ describe('CDVC', function () {
664670
name: 'foo',
665671
versions: [
666672
{
667-
packages: ['package1'],
673+
packages: [{ pathRelative: 'package1' }],
668674
version: '^1.0.0',
669675
},
670676
{
671-
packages: ['package2'],
677+
packages: [{ pathRelative: 'package2' }],
672678
version: '*',
673679
},
674680
],
@@ -740,11 +746,11 @@ describe('CDVC', function () {
740746
name: 'foo',
741747
versions: [
742748
{
743-
packages: ['package1'],
749+
packages: [{ pathRelative: 'package1' }],
744750
version: '^1.0.0',
745751
},
746752
{
747-
packages: ['package2'],
753+
packages: [{ pathRelative: 'package2' }],
748754
version: '1.5.0',
749755
},
750756
],
@@ -812,11 +818,11 @@ describe('CDVC', function () {
812818
name: 'foo',
813819
versions: [
814820
{
815-
packages: ['package1'],
821+
packages: [{ pathRelative: 'package1' }],
816822
version: '^1.0.0',
817823
},
818824
{
819-
packages: ['package2'],
825+
packages: [{ pathRelative: 'package2' }],
820826
version: '1.5.0',
821827
},
822828
],

0 commit comments

Comments
 (0)