@monorepolint/rules 0.6.0-alpha.2 → 0.6.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-clean.log +1 -1
- package/.turbo/turbo-compile-typescript.log +1 -1
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +160 -100
- package/.turbo/turbo-transpile-typescript.log +4 -4
- package/CHANGELOG.md +9 -0
- package/build/js/index.js +399 -246
- package/build/js/index.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/__tests__/utils.d.ts +0 -1
- package/build/types/__tests__/utils.d.ts.map +1 -1
- package/build/types/bannedDependencies.d.ts.map +1 -1
- package/build/types/fileContents.d.ts.map +1 -1
- package/build/types/index.d.ts +3 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/mustSatisfyPeerDependencies.d.ts.map +1 -1
- package/build/types/nestedWorkspaces.d.ts.map +1 -1
- package/build/types/packageEntry.d.ts.map +1 -1
- package/build/types/packageOrder.d.ts.map +1 -1
- package/build/types/packageScript.d.ts.map +1 -1
- package/build/types/requireDependency.d.ts +12 -12
- package/build/types/requireDependency.d.ts.map +1 -1
- package/build/types/util/checkAlpha.d.ts.map +1 -1
- package/build/types/util/createRuleFactory.d.ts.map +1 -1
- package/build/types/util/packageDependencyGraphService.d.ts.map +1 -1
- package/coverage/clover.xml +1159 -818
- package/coverage/coverage-final.json +18 -18
- package/coverage/index.html +20 -20
- package/coverage/src/alphabeticalDependencies.ts.html +8 -8
- package/coverage/src/alphabeticalScripts.ts.html +5 -5
- package/coverage/src/bannedDependencies.ts.html +77 -26
- package/coverage/src/consistentDependencies.ts.html +58 -19
- package/coverage/src/consistentVersions.ts.html +169 -58
- package/coverage/src/fileContents.ts.html +47 -23
- package/coverage/src/index.html +67 -67
- package/coverage/src/index.ts.html +32 -32
- package/coverage/src/mustSatisfyPeerDependencies.ts.html +373 -85
- package/coverage/src/nestedWorkspaces.ts.html +59 -20
- package/coverage/src/packageEntry.ts.html +40 -19
- package/coverage/src/packageOrder.ts.html +30 -12
- package/coverage/src/packageScript.ts.html +81 -27
- package/coverage/src/requireDependency.ts.html +83 -32
- package/coverage/src/standardTsconfig.ts.html +81 -18
- package/coverage/src/util/checkAlpha.ts.html +18 -9
- package/coverage/src/util/createRuleFactory.ts.html +16 -4
- package/coverage/src/util/index.html +17 -17
- package/coverage/src/util/makeDirectory.ts.html +5 -5
- package/coverage/src/util/packageDependencyGraphService.ts.html +101 -20
- package/package.json +4 -5
- package/src/__tests__/alphabeticalScripts.spec.ts +12 -4
- package/src/__tests__/bannedDependencies.spec.ts +45 -16
- package/src/__tests__/consistentDependencies.spec.ts +11 -5
- package/src/__tests__/consistentVersions.spec.ts +72 -18
- package/src/__tests__/fileContents.spec.ts +9 -5
- package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +191 -76
- package/src/__tests__/nestedWorkspaces.spec.ts +10 -6
- package/src/__tests__/packageEntry.spec.ts +54 -48
- package/src/__tests__/packageOrder.spec.ts +77 -71
- package/src/__tests__/packageScript.spec.ts +25 -11
- package/src/__tests__/requireDependency.spec.ts +12 -6
- package/src/__tests__/utils.ts +16 -7
- package/src/bannedDependencies.ts +32 -15
- package/src/consistentDependencies.ts +22 -9
- package/src/consistentVersions.ts +84 -47
- package/src/fileContents.ts +19 -11
- package/src/index.ts +3 -3
- package/src/mustSatisfyPeerDependencies.ts +162 -66
- package/src/nestedWorkspaces.ts +23 -10
- package/src/packageEntry.ts +18 -11
- package/src/packageOrder.ts +9 -3
- package/src/packageScript.ts +37 -19
- package/src/requireDependency.ts +28 -11
- package/src/standardTsconfig.ts +31 -10
- package/src/util/checkAlpha.ts +5 -2
- package/src/util/createRuleFactory.ts +6 -2
- package/src/util/packageDependencyGraphService.ts +41 -14
- package/vitest.config.mjs +10 -7
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
<div class='clearfix'>
|
|
24
24
|
|
|
25
25
|
<div class='fl pad1y space-right2'>
|
|
26
|
-
<span class="strong">87.
|
|
26
|
+
<span class="strong">87.17% </span>
|
|
27
27
|
<span class="quiet">Statements</span>
|
|
28
|
-
<span class='fraction'>
|
|
28
|
+
<span class='fraction'>68/78</span>
|
|
29
29
|
</div>
|
|
30
30
|
|
|
31
31
|
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
<div class='fl pad1y space-right2'>
|
|
47
|
-
<span class="strong">87.
|
|
47
|
+
<span class="strong">87.17% </span>
|
|
48
48
|
<span class="quiet">Lines</span>
|
|
49
|
-
<span class='fraction'>
|
|
49
|
+
<span class='fraction'>68/78</span>
|
|
50
50
|
</div>
|
|
51
51
|
|
|
52
52
|
|
|
@@ -177,7 +177,41 @@
|
|
|
177
177
|
<a name='L112'></a><a href='#L112'>112</a>
|
|
178
178
|
<a name='L113'></a><a href='#L113'>113</a>
|
|
179
179
|
<a name='L114'></a><a href='#L114'>114</a>
|
|
180
|
-
<a name='L115'></a><a href='#L115'>115</a
|
|
180
|
+
<a name='L115'></a><a href='#L115'>115</a>
|
|
181
|
+
<a name='L116'></a><a href='#L116'>116</a>
|
|
182
|
+
<a name='L117'></a><a href='#L117'>117</a>
|
|
183
|
+
<a name='L118'></a><a href='#L118'>118</a>
|
|
184
|
+
<a name='L119'></a><a href='#L119'>119</a>
|
|
185
|
+
<a name='L120'></a><a href='#L120'>120</a>
|
|
186
|
+
<a name='L121'></a><a href='#L121'>121</a>
|
|
187
|
+
<a name='L122'></a><a href='#L122'>122</a>
|
|
188
|
+
<a name='L123'></a><a href='#L123'>123</a>
|
|
189
|
+
<a name='L124'></a><a href='#L124'>124</a>
|
|
190
|
+
<a name='L125'></a><a href='#L125'>125</a>
|
|
191
|
+
<a name='L126'></a><a href='#L126'>126</a>
|
|
192
|
+
<a name='L127'></a><a href='#L127'>127</a>
|
|
193
|
+
<a name='L128'></a><a href='#L128'>128</a>
|
|
194
|
+
<a name='L129'></a><a href='#L129'>129</a>
|
|
195
|
+
<a name='L130'></a><a href='#L130'>130</a>
|
|
196
|
+
<a name='L131'></a><a href='#L131'>131</a>
|
|
197
|
+
<a name='L132'></a><a href='#L132'>132</a>
|
|
198
|
+
<a name='L133'></a><a href='#L133'>133</a>
|
|
199
|
+
<a name='L134'></a><a href='#L134'>134</a>
|
|
200
|
+
<a name='L135'></a><a href='#L135'>135</a>
|
|
201
|
+
<a name='L136'></a><a href='#L136'>136</a>
|
|
202
|
+
<a name='L137'></a><a href='#L137'>137</a>
|
|
203
|
+
<a name='L138'></a><a href='#L138'>138</a>
|
|
204
|
+
<a name='L139'></a><a href='#L139'>139</a>
|
|
205
|
+
<a name='L140'></a><a href='#L140'>140</a>
|
|
206
|
+
<a name='L141'></a><a href='#L141'>141</a>
|
|
207
|
+
<a name='L142'></a><a href='#L142'>142</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">1x</span>
|
|
208
|
+
<span class="cline-any cline-neutral"> </span>
|
|
209
|
+
<span class="cline-any cline-neutral"> </span>
|
|
210
|
+
<span class="cline-any cline-neutral"> </span>
|
|
211
|
+
<span class="cline-any cline-neutral"> </span>
|
|
212
|
+
<span class="cline-any cline-yes">1x</span>
|
|
213
|
+
<span class="cline-any cline-yes">1x</span>
|
|
214
|
+
<span class="cline-any cline-neutral"> </span>
|
|
181
215
|
<span class="cline-any cline-neutral"> </span>
|
|
182
216
|
<span class="cline-any cline-neutral"> </span>
|
|
183
217
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -210,6 +244,7 @@
|
|
|
210
244
|
<span class="cline-any cline-neutral"> </span>
|
|
211
245
|
<span class="cline-any cline-neutral"> </span>
|
|
212
246
|
<span class="cline-any cline-neutral"> </span>
|
|
247
|
+
<span class="cline-any cline-yes">1x</span>
|
|
213
248
|
<span class="cline-any cline-neutral"> </span>
|
|
214
249
|
<span class="cline-any cline-yes">1x</span>
|
|
215
250
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -221,6 +256,9 @@
|
|
|
221
256
|
<span class="cline-any cline-yes">1x</span>
|
|
222
257
|
<span class="cline-any cline-yes">1x</span>
|
|
223
258
|
<span class="cline-any cline-yes">5x</span>
|
|
259
|
+
<span class="cline-any cline-yes">5x</span>
|
|
260
|
+
<span class="cline-any cline-yes">5x</span>
|
|
261
|
+
<span class="cline-any cline-yes">5x</span>
|
|
224
262
|
<span class="cline-any cline-no"> </span>
|
|
225
263
|
<span class="cline-any cline-no"> </span>
|
|
226
264
|
<span class="cline-any cline-neutral"> </span>
|
|
@@ -240,14 +278,24 @@
|
|
|
240
278
|
<span class="cline-any cline-yes">5x</span>
|
|
241
279
|
<span class="cline-any cline-yes">5x</span>
|
|
242
280
|
<span class="cline-any cline-yes">5x</span>
|
|
281
|
+
<span class="cline-any cline-yes">3x</span>
|
|
282
|
+
<span class="cline-any cline-yes">2x</span>
|
|
243
283
|
<span class="cline-any cline-yes">5x</span>
|
|
244
284
|
<span class="cline-any cline-yes">4x</span>
|
|
245
285
|
<span class="cline-any cline-yes">4x</span>
|
|
286
|
+
<span class="cline-any cline-yes">4x</span>
|
|
287
|
+
<span class="cline-any cline-yes">4x</span>
|
|
288
|
+
<span class="cline-any cline-yes">4x</span>
|
|
289
|
+
<span class="cline-any cline-no"> </span>
|
|
290
|
+
<span class="cline-any cline-no"> </span>
|
|
246
291
|
<span class="cline-any cline-no"> </span>
|
|
247
292
|
<span class="cline-any cline-no"> </span>
|
|
248
293
|
<span class="cline-any cline-neutral"> </span>
|
|
249
294
|
<span class="cline-any cline-yes">4x</span>
|
|
250
295
|
<span class="cline-any cline-yes">4x</span>
|
|
296
|
+
<span class="cline-any cline-yes">4x</span>
|
|
297
|
+
<span class="cline-any cline-yes">4x</span>
|
|
298
|
+
<span class="cline-any cline-yes">4x</span>
|
|
251
299
|
<span class="cline-any cline-yes">5x</span>
|
|
252
300
|
<span class="cline-any cline-neutral"> </span>
|
|
253
301
|
<span class="cline-any cline-yes">5x</span>
|
|
@@ -260,12 +308,18 @@
|
|
|
260
308
|
<span class="cline-any cline-yes">1x</span>
|
|
261
309
|
<span class="cline-any cline-yes">1x</span>
|
|
262
310
|
<span class="cline-any cline-yes">1x</span>
|
|
311
|
+
<span class="cline-any cline-neutral"> </span>
|
|
312
|
+
<span class="cline-any cline-neutral"> </span>
|
|
263
313
|
<span class="cline-any cline-yes">1x</span>
|
|
264
314
|
<span class="cline-any cline-yes">1x</span>
|
|
265
315
|
<span class="cline-any cline-neutral"> </span>
|
|
266
316
|
<span class="cline-any cline-yes">1x</span>
|
|
267
317
|
<span class="cline-any cline-yes">5x</span>
|
|
268
318
|
<span class="cline-any cline-yes">5x</span>
|
|
319
|
+
<span class="cline-any cline-neutral"> </span>
|
|
320
|
+
<span class="cline-any cline-neutral"> </span>
|
|
321
|
+
<span class="cline-any cline-neutral"> </span>
|
|
322
|
+
<span class="cline-any cline-neutral"> </span>
|
|
269
323
|
<span class="cline-any cline-yes">5x</span>
|
|
270
324
|
<span class="cline-any cline-neutral"> </span>
|
|
271
325
|
<span class="cline-any cline-yes">5x</span>
|
|
@@ -312,7 +366,11 @@ export interface IPackageDependencyGraphNode {
|
|
|
312
366
|
/** Service abstraction for constructing and traversing package dependency graphs. */
|
|
313
367
|
export interface IPackageDependencyGraphService {
|
|
314
368
|
/** Construct a graph of package dependencies. */
|
|
315
|
-
buildDependencyGraph(
|
|
369
|
+
buildDependencyGraph(
|
|
370
|
+
packageJsonPath: string,
|
|
371
|
+
host: Host,
|
|
372
|
+
maxDepth?: number,
|
|
373
|
+
): IPackageDependencyGraphNode;
|
|
316
374
|
|
|
317
375
|
/** Traverse a package dependency graph. */
|
|
318
376
|
traverse(
|
|
@@ -320,20 +378,27 @@ export interface IPackageDependencyGraphService {
|
|
|
320
378
|
opts?: {
|
|
321
379
|
/** Traverse each unique path to a given package (potentially slow). */
|
|
322
380
|
traverseAllPaths?: boolean;
|
|
323
|
-
}
|
|
324
|
-
): IterableIterator<
|
|
381
|
+
},
|
|
382
|
+
): IterableIterator<
|
|
383
|
+
IPackageDependencyGraphNode & { importPath: IPackageDependencyGraphNode[] }
|
|
384
|
+
>;
|
|
325
385
|
}
|
|
326
386
|
|
|
327
387
|
/** Default implementation of the package dependency graph service. */
|
|
328
|
-
export class PackageDependencyGraphService
|
|
388
|
+
export class PackageDependencyGraphService
|
|
389
|
+
implements IPackageDependencyGraphService
|
|
390
|
+
{
|
|
329
391
|
/** Construct a graph of package dependencies and return the root node. */
|
|
330
392
|
public buildDependencyGraph(
|
|
331
393
|
startPackageJsonPath: string,
|
|
332
394
|
host: Host,
|
|
333
|
-
maxDepth?: number
|
|
395
|
+
maxDepth?: number,
|
|
334
396
|
): IPackageDependencyGraphNode {
|
|
335
397
|
const nodes = new Map<string, IPackageDependencyGraphNode>();
|
|
336
|
-
const visit = (
|
|
398
|
+
const visit = (
|
|
399
|
+
packageJsonPath: string,
|
|
400
|
+
currentDepth: number,
|
|
401
|
+
): IPackageDependencyGraphNode => {
|
|
337
402
|
if (nodes.has(packageJsonPath)) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
|
|
338
403
|
<span class="cstat-no" title="statement not covered" > return nodes.get(packageJsonPath)!;</span>
|
|
339
404
|
<span class="cstat-no" title="statement not covered" > }</span>
|
|
@@ -353,14 +418,24 @@ export class PackageDependencyGraphService implements IPackageDependencyGraphSer
|
|
|
353
418
|
|
|
354
419
|
const nextDepth = currentDepth + 1;
|
|
355
420
|
if (maxDepth == <span class="branch-0 cbranch-no" title="branch not covered" >null || nextDepth <= maxDepth) {</span>
|
|
356
|
-
const dependencies = packageJson.dependencies != null
|
|
421
|
+
const dependencies = packageJson.dependencies != null
|
|
422
|
+
? Object.keys(packageJson.dependencies)
|
|
423
|
+
: [];
|
|
357
424
|
for (const dependency of dependencies) {
|
|
358
|
-
const dependencyPackageJsonPath = resolvePackagePath(
|
|
425
|
+
const dependencyPackageJsonPath = resolvePackagePath(
|
|
426
|
+
dependency,
|
|
427
|
+
node.paths.rootDirectory,
|
|
428
|
+
);
|
|
359
429
|
if (dependencyPackageJsonPath == null) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
|
|
360
|
-
<span class="cstat-no" title="statement not covered" > throw new Error(
|
|
430
|
+
<span class="cstat-no" title="statement not covered" > throw new Error(</span>
|
|
431
|
+
<span class="cstat-no" title="statement not covered" > `Could not resolve ${dependency} from ${node.paths.rootDirectory}`,</span>
|
|
432
|
+
<span class="cstat-no" title="statement not covered" > );</span>
|
|
361
433
|
<span class="cstat-no" title="statement not covered" > }</span>
|
|
362
434
|
|
|
363
|
-
node.dependencies.set(
|
|
435
|
+
node.dependencies.set(
|
|
436
|
+
dependency,
|
|
437
|
+
visit(dependencyPackageJsonPath, nextDepth),
|
|
438
|
+
);
|
|
364
439
|
}
|
|
365
440
|
}
|
|
366
441
|
|
|
@@ -373,14 +448,20 @@ export class PackageDependencyGraphService implements IPackageDependencyGraphSer
|
|
|
373
448
|
/** Traverse a package dependency graph with an iterator. */
|
|
374
449
|
public *traverse(
|
|
375
450
|
root: IPackageDependencyGraphNode,
|
|
376
|
-
opts = { traverseAllPaths: false }
|
|
377
|
-
): IterableIterator<
|
|
451
|
+
opts = { traverseAllPaths: false },
|
|
452
|
+
): IterableIterator<
|
|
453
|
+
IPackageDependencyGraphNode & { importPath: IPackageDependencyGraphNode[] }
|
|
454
|
+
> {
|
|
378
455
|
const visited = new Set<IPackageDependencyGraphNode>();
|
|
379
456
|
|
|
380
457
|
function* visit(
|
|
381
458
|
node: IPackageDependencyGraphNode,
|
|
382
|
-
importPath: IPackageDependencyGraphNode[] = []
|
|
383
|
-
): IterableIterator<
|
|
459
|
+
importPath: IPackageDependencyGraphNode[] = [],
|
|
460
|
+
): IterableIterator<
|
|
461
|
+
IPackageDependencyGraphNode & {
|
|
462
|
+
importPath: IPackageDependencyGraphNode[];
|
|
463
|
+
}
|
|
464
|
+
> {
|
|
384
465
|
// Don't visit a package more than once unless explicitly asked to traverse all paths
|
|
385
466
|
if (!opts.traverseAllPaths && visited.has(node)) <span class="branch-0 cbranch-no" title="branch not covered" >{</span>
|
|
386
467
|
<span class="cstat-no" title="statement not covered" > return;</span>
|
|
@@ -412,7 +493,7 @@ export class PackageDependencyGraphService implements IPackageDependencyGraphSer
|
|
|
412
493
|
<div class='footer quiet pad2 space-top1 center small'>
|
|
413
494
|
Code coverage generated by
|
|
414
495
|
<a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
|
|
415
|
-
at 2025-01-
|
|
496
|
+
at 2025-01-22T17:39:11.886Z
|
|
416
497
|
</div>
|
|
417
498
|
<script src="../../prettify.js"></script>
|
|
418
499
|
<script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monorepolint/rules",
|
|
3
|
-
"version": "0.6.0-alpha.
|
|
3
|
+
"version": "0.6.0-alpha.3",
|
|
4
4
|
"author": "Eric L Anderson (https://github.com/ericanderson)",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Mac Lockard (https://github.com/maclockard)"
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"runtypes": "^6.7.0",
|
|
29
29
|
"semver": "^7.6.3",
|
|
30
30
|
"tslib": "^2.8.1",
|
|
31
|
-
"@monorepolint/core": "^0.6.0-alpha.
|
|
32
|
-
"@monorepolint/utils": "^0.6.0-alpha.
|
|
33
|
-
"@monorepolint/config": "^0.6.0-alpha.
|
|
31
|
+
"@monorepolint/core": "^0.6.0-alpha.3",
|
|
32
|
+
"@monorepolint/utils": "^0.6.0-alpha.3",
|
|
33
|
+
"@monorepolint/config": "^0.6.0-alpha.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/semver": "^7.5.8",
|
|
@@ -38,7 +38,6 @@
|
|
|
38
38
|
"@typescript-eslint/eslint-plugin": "^8.20.0",
|
|
39
39
|
"@typescript-eslint/parser": "^8.20.0",
|
|
40
40
|
"eslint": "^9.18.0",
|
|
41
|
-
"prettier": "^3.4.2",
|
|
42
41
|
"tmp": "^0.2.3",
|
|
43
42
|
"tslib": "^2.8.1",
|
|
44
43
|
"tsup": "^8.3.5",
|
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
// tslint:disable:no-console
|
|
9
|
-
import { describe, expect, it, beforeEach, vi } from "vitest";
|
|
10
|
-
import { AddErrorSpy, createTestingWorkspace, HOST_FACTORIES, jsonToString, TestingWorkspace } from "./utils.js";
|
|
11
9
|
import { Context, Failure } from "@monorepolint/config";
|
|
10
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
12
11
|
import { alphabeticalScripts } from "../alphabeticalScripts.js";
|
|
13
12
|
import { createIncorrectOrderErrorMessage } from "../util/checkAlpha.js";
|
|
13
|
+
import {
|
|
14
|
+
AddErrorSpy,
|
|
15
|
+
createTestingWorkspace,
|
|
16
|
+
HOST_FACTORIES,
|
|
17
|
+
jsonToString,
|
|
18
|
+
TestingWorkspace,
|
|
19
|
+
} from "./utils.js";
|
|
14
20
|
|
|
15
21
|
const PACKAGE_SCRIPTS_SORTED = jsonToString({
|
|
16
22
|
name: "foo-lib",
|
|
@@ -59,10 +65,12 @@ describe.each(HOST_FACTORIES)("alphabeticalScripts ($name)", (hostFactory) => {
|
|
|
59
65
|
file: "package.json",
|
|
60
66
|
hasFixer: true,
|
|
61
67
|
message: createIncorrectOrderErrorMessage("scripts", "foo-lib"),
|
|
62
|
-
})
|
|
68
|
+
}),
|
|
63
69
|
);
|
|
64
70
|
|
|
65
|
-
expect(workspace.readFile("package.json")).toEqual(
|
|
71
|
+
expect(workspace.readFile("package.json")).toEqual(
|
|
72
|
+
PACKAGE_SCRIPTS_SORTED,
|
|
73
|
+
);
|
|
66
74
|
});
|
|
67
75
|
|
|
68
76
|
it("does nothing if already sorted", () => {
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Licensed under the MIT license. See LICENSE file in the project root for details.
|
|
5
5
|
*
|
|
6
6
|
*/
|
|
7
|
-
import { describe, expect, it, beforeEach, vi, afterEach } from "vitest";
|
|
8
7
|
import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
9
8
|
import { SimpleHost } from "@monorepolint/utils";
|
|
10
9
|
import { writeFileSync } from "fs";
|
|
11
10
|
import * as path from "path";
|
|
12
11
|
import * as tmp from "tmp";
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
13
13
|
import { bannedDependencies, Options } from "../bannedDependencies.js";
|
|
14
14
|
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
15
15
|
import { jsonToString } from "./utils.js";
|
|
@@ -46,7 +46,7 @@ describe("bannedDependencies", () => {
|
|
|
46
46
|
verbose: false,
|
|
47
47
|
silent: true,
|
|
48
48
|
},
|
|
49
|
-
new SimpleHost()
|
|
49
|
+
new SimpleHost(),
|
|
50
50
|
);
|
|
51
51
|
|
|
52
52
|
function checkAndSpy(options: Options) {
|
|
@@ -77,15 +77,21 @@ describe("bannedDependencies", () => {
|
|
|
77
77
|
});
|
|
78
78
|
addFile("./package.json", rootPackageJson);
|
|
79
79
|
|
|
80
|
-
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
80
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
81
|
+
bannedDependencies: ["ccc"],
|
|
82
|
+
});
|
|
81
83
|
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
82
84
|
addErrorSpy1.mockReset();
|
|
83
85
|
|
|
84
|
-
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
86
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
87
|
+
bannedDependencies: ["ddd"],
|
|
88
|
+
});
|
|
85
89
|
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
86
90
|
addErrorSpy2.mockReset();
|
|
87
91
|
|
|
88
|
-
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
92
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
93
|
+
bannedDependencies: ["ccc", "ddd"],
|
|
94
|
+
});
|
|
89
95
|
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
90
96
|
addErrorSpy3.mockReset();
|
|
91
97
|
});
|
|
@@ -100,15 +106,21 @@ describe("bannedDependencies", () => {
|
|
|
100
106
|
});
|
|
101
107
|
addFile("./package.json", rootPackageJson);
|
|
102
108
|
|
|
103
|
-
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
109
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
110
|
+
bannedDependencies: ["c*c"],
|
|
111
|
+
});
|
|
104
112
|
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
105
113
|
addErrorSpy1.mockReset();
|
|
106
114
|
|
|
107
|
-
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
115
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
116
|
+
bannedDependencies: ["d*d"],
|
|
117
|
+
});
|
|
108
118
|
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
109
119
|
addErrorSpy2.mockReset();
|
|
110
120
|
|
|
111
|
-
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
121
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
122
|
+
bannedDependencies: ["c*c", "d*d"],
|
|
123
|
+
});
|
|
112
124
|
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
113
125
|
addErrorSpy3.mockReset();
|
|
114
126
|
});
|
|
@@ -123,15 +135,21 @@ describe("bannedDependencies", () => {
|
|
|
123
135
|
});
|
|
124
136
|
addFile("./package.json", rootPackageJson);
|
|
125
137
|
|
|
126
|
-
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
138
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
139
|
+
bannedDependencies: { glob: ["c*c"] },
|
|
140
|
+
});
|
|
127
141
|
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
128
142
|
addErrorSpy1.mockReset();
|
|
129
143
|
|
|
130
|
-
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
144
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
145
|
+
bannedDependencies: { glob: ["d*d"] },
|
|
146
|
+
});
|
|
131
147
|
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
132
148
|
addErrorSpy2.mockReset();
|
|
133
149
|
|
|
134
|
-
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
150
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
151
|
+
bannedDependencies: { glob: ["c*c", "d*d"] },
|
|
152
|
+
});
|
|
135
153
|
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
136
154
|
addErrorSpy3.mockReset();
|
|
137
155
|
});
|
|
@@ -146,15 +164,21 @@ describe("bannedDependencies", () => {
|
|
|
146
164
|
});
|
|
147
165
|
addFile("./package.json", rootPackageJson);
|
|
148
166
|
|
|
149
|
-
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
167
|
+
const { addErrorSpy: addErrorSpy1 } = checkAndSpy({
|
|
168
|
+
bannedDependencies: { exact: ["ccc"] },
|
|
169
|
+
});
|
|
150
170
|
expect(addErrorSpy1).toHaveBeenCalledTimes(1);
|
|
151
171
|
addErrorSpy1.mockReset();
|
|
152
172
|
|
|
153
|
-
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
173
|
+
const { addErrorSpy: addErrorSpy2 } = checkAndSpy({
|
|
174
|
+
bannedDependencies: { exact: ["ddd"] },
|
|
175
|
+
});
|
|
154
176
|
expect(addErrorSpy2).toHaveBeenCalledTimes(0);
|
|
155
177
|
addErrorSpy2.mockReset();
|
|
156
178
|
|
|
157
|
-
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
179
|
+
const { addErrorSpy: addErrorSpy3 } = checkAndSpy({
|
|
180
|
+
bannedDependencies: { exact: ["ccc", "ddd"] },
|
|
181
|
+
});
|
|
158
182
|
expect(addErrorSpy3).toHaveBeenCalledTimes(1);
|
|
159
183
|
addErrorSpy3.mockReset();
|
|
160
184
|
});
|
|
@@ -181,9 +205,14 @@ describe("bannedDependencies", () => {
|
|
|
181
205
|
},
|
|
182
206
|
});
|
|
183
207
|
addFile("./node_modules/aaa/node_modules/bbb/package.json", bbbPackageJson);
|
|
184
|
-
addFile(
|
|
208
|
+
addFile(
|
|
209
|
+
"./node_modules/aaa/node_modules/bbb/node_modules/ddd/package.json",
|
|
210
|
+
EMPTY_PACKAGE,
|
|
211
|
+
);
|
|
185
212
|
addFile("./node_modules/aaa/node_modules/ccc/package.json", EMPTY_PACKAGE);
|
|
186
213
|
|
|
187
|
-
expect(
|
|
214
|
+
expect(
|
|
215
|
+
checkAndSpy({ bannedTransitiveDependencies: ["ccc", "ddd"] }).addErrorSpy,
|
|
216
|
+
).toHaveBeenCalledTimes(2);
|
|
188
217
|
});
|
|
189
218
|
});
|
|
@@ -9,10 +9,10 @@ import { SimpleHost } from "@monorepolint/utils";
|
|
|
9
9
|
import { readFileSync, writeFileSync } from "fs";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
13
|
import { consistentDependencies, Options } from "../consistentDependencies.js";
|
|
13
14
|
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
15
|
import { jsonToString } from "./utils.js";
|
|
15
|
-
import { describe, expect, it, afterEach, vi } from "vitest";
|
|
16
16
|
|
|
17
17
|
const PACKAGE_ROOT = jsonToString({
|
|
18
18
|
workspaces: {
|
|
@@ -71,11 +71,13 @@ describe("consistentDependencies", () => {
|
|
|
71
71
|
verbose: false,
|
|
72
72
|
silent: true,
|
|
73
73
|
},
|
|
74
|
-
new SimpleHost()
|
|
74
|
+
new SimpleHost(),
|
|
75
75
|
);
|
|
76
76
|
|
|
77
77
|
function checkAndSpy(q: string, opts?: Options) {
|
|
78
|
-
const context = workspaceContext.createChildContext(
|
|
78
|
+
const context = workspaceContext.createChildContext(
|
|
79
|
+
path.resolve(dir.name, q),
|
|
80
|
+
);
|
|
79
81
|
const addErrorSpy = vi.spyOn(context, "addError");
|
|
80
82
|
consistentDependencies({ options: opts }).check(context);
|
|
81
83
|
return { context, addErrorSpy };
|
|
@@ -97,7 +99,9 @@ describe("consistentDependencies", () => {
|
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
it("checks correctly", () => {
|
|
100
|
-
const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({
|
|
102
|
+
const { addFile, workspaceContext, checkAndSpy } = makeWorkspace({
|
|
103
|
+
fix: false,
|
|
104
|
+
});
|
|
101
105
|
addFile("./package.json", PACKAGE_ROOT);
|
|
102
106
|
addFile("./packages/star/package.json", PACKAGE_CHILD_WITH_STAR);
|
|
103
107
|
addFile("./packages/latest/package.json", PACKAGE_CHILD_WITH_LATEST);
|
|
@@ -136,7 +140,9 @@ describe("consistentDependencies", () => {
|
|
|
136
140
|
addFile("./package.json", PACKAGE_ROOT);
|
|
137
141
|
addFile("./packages/wrong/package.json", PACKAGE_CHILD_WITH_WRONG_VERSION);
|
|
138
142
|
|
|
139
|
-
const ignored = checkAndSpy("./packages/wrong", {
|
|
143
|
+
const ignored = checkAndSpy("./packages/wrong", {
|
|
144
|
+
ignoredDependencies: ["foo"],
|
|
145
|
+
});
|
|
140
146
|
expect(ignored.addErrorSpy).toHaveBeenCalledTimes(0);
|
|
141
147
|
});
|
|
142
148
|
});
|
|
@@ -9,9 +9,9 @@ import { WorkspaceContextImpl } from "@monorepolint/core";
|
|
|
9
9
|
import { Host, PackageJson, SimpleHost } from "@monorepolint/utils";
|
|
10
10
|
import * as path from "path";
|
|
11
11
|
import * as tmp from "tmp";
|
|
12
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
12
13
|
import { consistentVersions, Options } from "../consistentVersions.js";
|
|
13
14
|
import { makeDirectoryRecursively } from "../util/makeDirectory.js";
|
|
14
|
-
import { describe, expect, it, beforeEach, afterEach, vi } from "vitest";
|
|
15
15
|
|
|
16
16
|
describe("consistentVersions", () => {
|
|
17
17
|
tmp.setGracefulCleanup();
|
|
@@ -45,7 +45,7 @@ describe("consistentVersions", () => {
|
|
|
45
45
|
verbose: false,
|
|
46
46
|
silent: true,
|
|
47
47
|
},
|
|
48
|
-
host
|
|
48
|
+
host,
|
|
49
49
|
);
|
|
50
50
|
const addErrorSpy = vi.spyOn(workspaceContext, "addError");
|
|
51
51
|
|
|
@@ -56,7 +56,11 @@ describe("consistentVersions", () => {
|
|
|
56
56
|
return { addErrorSpy, check, host };
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
function addPackageJson(
|
|
59
|
+
function addPackageJson(
|
|
60
|
+
host: Host,
|
|
61
|
+
filePath: string,
|
|
62
|
+
packageJson: PackageJson,
|
|
63
|
+
) {
|
|
60
64
|
const dirPath = path.resolve(cwd!, path.dirname(filePath));
|
|
61
65
|
const resolvedFilePath = path.resolve(cwd!, filePath);
|
|
62
66
|
|
|
@@ -99,15 +103,24 @@ describe("consistentVersions", () => {
|
|
|
99
103
|
|
|
100
104
|
it("Fixes packages that have an incorrect dependency version", async () => {
|
|
101
105
|
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
102
|
-
const readTestPackageJson = addPackageJson(
|
|
106
|
+
const readTestPackageJson = addPackageJson(
|
|
107
|
+
host,
|
|
108
|
+
"./package.json",
|
|
109
|
+
testPackageJson,
|
|
110
|
+
);
|
|
103
111
|
|
|
104
112
|
const requiredGreatLibVersion = "1.2.3";
|
|
105
113
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
106
114
|
check({
|
|
107
|
-
matchDependencyVersions: {
|
|
115
|
+
matchDependencyVersions: {
|
|
116
|
+
both: testPackageJson.dependencies!.both,
|
|
117
|
+
greatLib: requiredGreatLibVersion,
|
|
118
|
+
},
|
|
108
119
|
});
|
|
109
120
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
110
|
-
expect(readTestPackageJson().dependencies!.greatLib).toEqual(
|
|
121
|
+
expect(readTestPackageJson().dependencies!.greatLib).toEqual(
|
|
122
|
+
requiredGreatLibVersion,
|
|
123
|
+
);
|
|
111
124
|
});
|
|
112
125
|
|
|
113
126
|
it("Ignores packages that have a correct dependency version", async () => {
|
|
@@ -126,13 +139,24 @@ describe("consistentVersions", () => {
|
|
|
126
139
|
|
|
127
140
|
it("Fixes packages that have an incorrect devDependency version", async () => {
|
|
128
141
|
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
129
|
-
const readTestPackageJson = addPackageJson(
|
|
142
|
+
const readTestPackageJson = addPackageJson(
|
|
143
|
+
host,
|
|
144
|
+
"./package.json",
|
|
145
|
+
testPackageJson,
|
|
146
|
+
);
|
|
130
147
|
|
|
131
148
|
const requiredElseLibVersion = "1.2.3";
|
|
132
149
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
133
|
-
check({
|
|
150
|
+
check({
|
|
151
|
+
matchDependencyVersions: {
|
|
152
|
+
both: testPackageJson.dependencies!.both,
|
|
153
|
+
else: requiredElseLibVersion,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
134
156
|
expect(addErrorSpy).toHaveBeenCalledTimes(1);
|
|
135
|
-
expect(readTestPackageJson().devDependencies!.else).toEqual(
|
|
157
|
+
expect(readTestPackageJson().devDependencies!.else).toEqual(
|
|
158
|
+
requiredElseLibVersion,
|
|
159
|
+
);
|
|
136
160
|
});
|
|
137
161
|
|
|
138
162
|
it("Ignores packages that have a correct devDependency version", async () => {
|
|
@@ -151,14 +175,22 @@ describe("consistentVersions", () => {
|
|
|
151
175
|
|
|
152
176
|
it("Fixes packages that have an incorrect dependency and devDependency versions", async () => {
|
|
153
177
|
const { addErrorSpy, check, host } = makeWorkspace(true);
|
|
154
|
-
const readTestPackageJson = addPackageJson(
|
|
178
|
+
const readTestPackageJson = addPackageJson(
|
|
179
|
+
host,
|
|
180
|
+
"./package.json",
|
|
181
|
+
testPackageJson,
|
|
182
|
+
);
|
|
155
183
|
|
|
156
184
|
const requiredBothVersion = "1.2.3";
|
|
157
185
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
158
186
|
check({ matchDependencyVersions: { both: requiredBothVersion } });
|
|
159
187
|
expect(addErrorSpy).toHaveBeenCalledTimes(2);
|
|
160
|
-
expect(readTestPackageJson().dependencies!.both).toEqual(
|
|
161
|
-
|
|
188
|
+
expect(readTestPackageJson().dependencies!.both).toEqual(
|
|
189
|
+
requiredBothVersion,
|
|
190
|
+
);
|
|
191
|
+
expect(readTestPackageJson().devDependencies!.both).toEqual(
|
|
192
|
+
requiredBothVersion,
|
|
193
|
+
);
|
|
162
194
|
});
|
|
163
195
|
});
|
|
164
196
|
|
|
@@ -187,13 +219,35 @@ describe("consistentVersions", () => {
|
|
|
187
219
|
addPackageJson(host, "./package.json", testPackageJson);
|
|
188
220
|
|
|
189
221
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
190
|
-
check({
|
|
222
|
+
check({
|
|
223
|
+
matchDependencyVersions: {
|
|
224
|
+
greatLib: [testPackageJson.dependencies!.greatLib],
|
|
225
|
+
},
|
|
226
|
+
});
|
|
191
227
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
192
|
-
check({
|
|
228
|
+
check({
|
|
229
|
+
matchDependencyVersions: {
|
|
230
|
+
greatLib: ["1", "2", testPackageJson.dependencies!.greatLib],
|
|
231
|
+
},
|
|
232
|
+
});
|
|
193
233
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
194
|
-
check({
|
|
234
|
+
check({
|
|
235
|
+
matchDependencyVersions: {
|
|
236
|
+
greatLib: [
|
|
237
|
+
"1",
|
|
238
|
+
"2",
|
|
239
|
+
testPackageJson.dependencies!.greatLib,
|
|
240
|
+
"99",
|
|
241
|
+
"100",
|
|
242
|
+
],
|
|
243
|
+
},
|
|
244
|
+
});
|
|
195
245
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
196
|
-
check({
|
|
246
|
+
check({
|
|
247
|
+
matchDependencyVersions: {
|
|
248
|
+
greatLib: [testPackageJson.dependencies!.greatLib, "99", "100"],
|
|
249
|
+
},
|
|
250
|
+
});
|
|
197
251
|
expect(addErrorSpy).toHaveBeenCalledTimes(0);
|
|
198
252
|
});
|
|
199
253
|
|
|
@@ -212,12 +266,12 @@ describe("consistentVersions", () => {
|
|
|
212
266
|
expect(addErrorSpy.mock.calls[0][0].message).toEqual(
|
|
213
267
|
`Expected dependency on both to match one of '["99","100"]', got '${
|
|
214
268
|
testPackageJson.dependencies!.both
|
|
215
|
-
}' instead
|
|
269
|
+
}' instead.`,
|
|
216
270
|
);
|
|
217
271
|
expect(addErrorSpy.mock.calls[1][0].message).toEqual(
|
|
218
272
|
`Expected devDependency on both to match one of '["99","100"]', got '${
|
|
219
273
|
testPackageJson.devDependencies!.both
|
|
220
|
-
}' instead
|
|
274
|
+
}' instead.`,
|
|
221
275
|
);
|
|
222
276
|
});
|
|
223
277
|
});
|