@rsdk/depdoc.cli 6.0.0-next.42 → 6.0.0-next.44
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/DEPDOC_MODEL.md +22 -11
- package/__tests__/compatibility.test.ts +74 -15
- package/__tests__/config-validation.test.ts +46 -1
- package/__tests__/engine.test.ts +162 -2
- package/__tests__/fixtures/imports/config/aliases.json +8 -0
- package/__tests__/fixtures/imports/plain-root-file.ts +3 -0
- package/__tests__/fixtures/imports/sidebars.ts +5 -0
- package/__tests__/fixtures/imports/src/aliases.ts +4 -0
- package/__tests__/fixtures/imports/src/virtual.ts +3 -0
- package/__tests__/fixtures/imports/tsconfig.build.json +3 -0
- package/__tests__/fixtures/imports/tsconfig.json +8 -0
- package/__tests__/fixtures/imports/vite.config.ts +3 -0
- package/__tests__/imports.test.ts +72 -0
- package/dist/collectors/tsconfig-aliases.d.ts +1 -0
- package/dist/collectors/tsconfig-aliases.js +40 -0
- package/dist/collectors/tsconfig-aliases.js.map +1 -0
- package/dist/collectors/workspaces.d.ts +2 -2
- package/dist/collectors/workspaces.js +21 -6
- package/dist/collectors/workspaces.js.map +1 -1
- package/dist/lib/imports.d.ts +9 -4
- package/dist/lib/imports.js +62 -9
- package/dist/lib/imports.js.map +1 -1
- package/dist/model/config-validation.d.ts +2 -0
- package/dist/model/config-validation.js +44 -1
- package/dist/model/config-validation.js.map +1 -1
- package/dist/model/diagnostics.d.ts +1 -0
- package/dist/model/diagnostics.js +67 -0
- package/dist/model/diagnostics.js.map +1 -1
- package/dist/model/engine.js +1 -0
- package/dist/model/engine.js.map +1 -1
- package/dist/model/placement.js +12 -1
- package/dist/model/placement.js.map +1 -1
- package/dist/model/types.d.ts +8 -1
- package/dist/model/types.js.map +1 -1
- package/dist/runner.js +1 -1
- package/dist/runner.js.map +1 -1
- package/package.json +2 -2
- package/src/collectors/tsconfig-aliases.ts +45 -0
- package/src/collectors/workspaces.ts +50 -7
- package/src/lib/imports.ts +114 -8
- package/src/model/config-validation.ts +62 -3
- package/src/model/diagnostics.ts +105 -1
- package/src/model/engine.ts +7 -1
- package/src/model/placement.ts +19 -1
- package/src/model/types.ts +16 -0
- package/src/runner.ts +6 -1
package/__tests__/engine.test.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
deriveDependencyModel,
|
|
3
2
|
type DependencyModelFacts,
|
|
4
|
-
|
|
3
|
+
deriveDependencyModel,
|
|
5
4
|
type UsageSummary,
|
|
5
|
+
type WorkspaceFacts,
|
|
6
6
|
} from '../src/dependency-model';
|
|
7
7
|
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
@@ -36,6 +36,7 @@ function makeWorkspace(
|
|
|
36
36
|
hasSrc = false,
|
|
37
37
|
hasDist = false,
|
|
38
38
|
sourceFileCount?: number,
|
|
39
|
+
toolingFiles: Set<string> = new Set(),
|
|
39
40
|
): WorkspaceFacts {
|
|
40
41
|
const basePkg: WorkspaceFacts['pkg'] = { name };
|
|
41
42
|
if (role !== undefined) basePkg.role = role;
|
|
@@ -49,6 +50,7 @@ function makeWorkspace(
|
|
|
49
50
|
dtsImports,
|
|
50
51
|
hasSrc,
|
|
51
52
|
hasDist,
|
|
53
|
+
toolingFiles,
|
|
52
54
|
...(sourceFileCount === undefined ? {} : { sourceFileCount }),
|
|
53
55
|
};
|
|
54
56
|
}
|
|
@@ -88,6 +90,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
88
90
|
const root = makeRoot({ name: '@test/root' }); // no private field
|
|
89
91
|
const facts = emptyFacts([root]);
|
|
90
92
|
const result = deriveDependencyModel(facts);
|
|
93
|
+
|
|
91
94
|
expect(result.violations.some((v) => v.code === 'root-private')).toBe(true);
|
|
92
95
|
});
|
|
93
96
|
|
|
@@ -99,6 +102,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
99
102
|
});
|
|
100
103
|
const facts = emptyFacts([root]);
|
|
101
104
|
const result = deriveDependencyModel(facts);
|
|
105
|
+
|
|
102
106
|
expect(result.violations.some((v) => v.code === 'root-section')).toBe(true);
|
|
103
107
|
});
|
|
104
108
|
|
|
@@ -125,6 +129,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
125
129
|
const ws = makeWorkspace('@test/noop', 'packages/noop', undefined, { name: '@test/noop' });
|
|
126
130
|
const facts = emptyFacts([root, ws]);
|
|
127
131
|
const result = deriveDependencyModel(facts);
|
|
132
|
+
|
|
128
133
|
expect(result.violations.some((v) => v.code === 'role-missing' && v.workspaceLocation === 'packages/noop')).toBe(true);
|
|
129
134
|
});
|
|
130
135
|
|
|
@@ -134,6 +139,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
134
139
|
const ws = makeWorkspace('@test/noop', 'packages/noop', undefined, { name: '@test/noop', role: 'invalid' as any });
|
|
135
140
|
const facts = emptyFacts([root, ws]);
|
|
136
141
|
const result = deriveDependencyModel(facts);
|
|
142
|
+
|
|
137
143
|
expect(result.violations.some((v) => v.code === 'role-invalid')).toBe(true);
|
|
138
144
|
});
|
|
139
145
|
});
|
|
@@ -154,6 +160,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
154
160
|
]);
|
|
155
161
|
const result = deriveDependencyModel(facts);
|
|
156
162
|
const exp = result.expected.get('packages/lib')!;
|
|
163
|
+
|
|
157
164
|
expect(exp.sections.peerDependencies.get('lodash')).toBe('^4.17.21');
|
|
158
165
|
expect(exp.sections.devDependencies.get('lodash')).toBe('^4.17.21'); // mirror
|
|
159
166
|
expect(exp.sections.dependencies.has('lodash')).toBe(false);
|
|
@@ -176,6 +183,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
176
183
|
]);
|
|
177
184
|
const result = deriveDependencyModel(facts);
|
|
178
185
|
const exp = result.expected.get('packages/lib')!;
|
|
186
|
+
|
|
179
187
|
expect(exp.sections.dependencies.get('some-lib')).toBe('1.0.0');
|
|
180
188
|
expect(exp.sections.peerDependencies.has('some-lib')).toBe(false);
|
|
181
189
|
expect(exp.sections.devDependencies.has('some-lib')).toBe(false);
|
|
@@ -227,10 +235,59 @@ describe('deriveDependencyModel engine', () => {
|
|
|
227
235
|
]);
|
|
228
236
|
const result = deriveDependencyModel(facts);
|
|
229
237
|
const exp = result.expected.get('packages/svc')!;
|
|
238
|
+
|
|
230
239
|
expect(exp.sections.dependencies.get('express')).toBe('^4.0.0');
|
|
231
240
|
expect(exp.sections.peerDependencies.has('express')).toBe(false);
|
|
232
241
|
expect(exp.sections.devDependencies.has('express')).toBe(false);
|
|
233
242
|
});
|
|
243
|
+
|
|
244
|
+
it('sends a root config file runtime import to root devDependencies, not the workspace', () => {
|
|
245
|
+
const root = makeRoot();
|
|
246
|
+
const ws = makeWorkspace(
|
|
247
|
+
'@test/svc',
|
|
248
|
+
'packages/svc',
|
|
249
|
+
'service',
|
|
250
|
+
undefined,
|
|
251
|
+
new Map([['vite', runtimeUsage(['vite.config.ts'])]]),
|
|
252
|
+
new Set(),
|
|
253
|
+
false,
|
|
254
|
+
false,
|
|
255
|
+
undefined,
|
|
256
|
+
new Set(['vite.config.ts']),
|
|
257
|
+
);
|
|
258
|
+
const facts = emptyFacts([root, ws], [
|
|
259
|
+
{ match: 'vite', version: '^5.0.0' },
|
|
260
|
+
]);
|
|
261
|
+
const result = deriveDependencyModel(facts);
|
|
262
|
+
const rootExp = result.expected.get('.')!;
|
|
263
|
+
const wsExp = result.expected.get('packages/svc')!;
|
|
264
|
+
|
|
265
|
+
expect(rootExp.sections.devDependencies.get('vite')).toBe('^5.0.0');
|
|
266
|
+
expect(wsExp.sections.dependencies.has('vite')).toBe(false);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('does not misclassify a src/ file that merely looks like a config file by name', () => {
|
|
270
|
+
const root = makeRoot();
|
|
271
|
+
const ws = makeWorkspace(
|
|
272
|
+
'@test/svc',
|
|
273
|
+
'packages/svc',
|
|
274
|
+
'service',
|
|
275
|
+
undefined,
|
|
276
|
+
new Map([['yaml', runtimeUsage(['src/auth.config.ts'])]]),
|
|
277
|
+
new Set(),
|
|
278
|
+
false,
|
|
279
|
+
false,
|
|
280
|
+
undefined,
|
|
281
|
+
new Set(['vite.config.ts']), // unrelated tooling file; src/auth.config.ts is not in it
|
|
282
|
+
);
|
|
283
|
+
const facts = emptyFacts([root, ws], [
|
|
284
|
+
{ match: 'yaml', version: '^2.0.0' },
|
|
285
|
+
]);
|
|
286
|
+
const result = deriveDependencyModel(facts);
|
|
287
|
+
const wsExp = result.expected.get('packages/svc')!;
|
|
288
|
+
|
|
289
|
+
expect(wsExp.sections.dependencies.get('yaml')).toBe('^2.0.0');
|
|
290
|
+
});
|
|
234
291
|
});
|
|
235
292
|
|
|
236
293
|
describe('declaration-independent-expected-graph', () => {
|
|
@@ -390,6 +447,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
390
447
|
const facts = emptyFacts([root, lib, svc]);
|
|
391
448
|
const result = deriveDependencyModel(facts);
|
|
392
449
|
const exp = result.expected.get('packages/svc')!;
|
|
450
|
+
|
|
393
451
|
expect(exp.sections.dependencies.get('@test/shared')).toBe('workspace:*');
|
|
394
452
|
});
|
|
395
453
|
});
|
|
@@ -398,6 +456,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
398
456
|
describe('peer-propagation-local-library', () => {
|
|
399
457
|
it('propagates peerDependencies from local library to consuming service', () => {
|
|
400
458
|
const root = makeRoot();
|
|
459
|
+
|
|
401
460
|
// foo is a library with peerDep on react
|
|
402
461
|
const foo = makeWorkspace(
|
|
403
462
|
'@test/foo',
|
|
@@ -406,6 +465,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
406
465
|
{ name: '@test/foo', role: 'library' },
|
|
407
466
|
new Map([['react', runtimeUsage(['src/index.ts'])]]),
|
|
408
467
|
);
|
|
468
|
+
|
|
409
469
|
// bar is a service that depends on foo at runtime
|
|
410
470
|
const bar = makeWorkspace(
|
|
411
471
|
'@test/bar',
|
|
@@ -422,6 +482,8 @@ describe('deriveDependencyModel engine', () => {
|
|
|
422
482
|
};
|
|
423
483
|
const result = deriveDependencyModel(facts);
|
|
424
484
|
const exp = result.expected.get('packages/bar')!;
|
|
485
|
+
|
|
486
|
+
|
|
425
487
|
// service gets react propagated into dependencies
|
|
426
488
|
expect(exp.sections.dependencies.get('react')).toBeDefined();
|
|
427
489
|
});
|
|
@@ -441,6 +503,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
441
503
|
{ match: 'some-tool', rootOnly: true },
|
|
442
504
|
]);
|
|
443
505
|
const result = deriveDependencyModel(facts);
|
|
506
|
+
|
|
444
507
|
expect(result.violations.some((v) => v.code === 'root-only' && v.dependency === 'some-tool')).toBe(true);
|
|
445
508
|
});
|
|
446
509
|
|
|
@@ -524,6 +587,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
524
587
|
]);
|
|
525
588
|
const result = deriveDependencyModel(facts);
|
|
526
589
|
const exp = result.expected.get('packages/lib')!;
|
|
590
|
+
|
|
527
591
|
expect([...exp.sections.devDependencies.entries()]).toEqual(
|
|
528
592
|
[...exp.sections.peerDependencies.entries()],
|
|
529
593
|
);
|
|
@@ -547,6 +611,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
547
611
|
{ match: 'react', version: '^18.0.0' },
|
|
548
612
|
]);
|
|
549
613
|
const result = deriveDependencyModel(facts);
|
|
614
|
+
|
|
550
615
|
expect(
|
|
551
616
|
result.violations.some((v) => v.code === 'mirror' && v.dependency === 'react'),
|
|
552
617
|
).toBe(true);
|
|
@@ -571,6 +636,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
571
636
|
]);
|
|
572
637
|
const result = deriveDependencyModel(facts);
|
|
573
638
|
const exp = result.expected.get('packages/lib')!;
|
|
639
|
+
|
|
574
640
|
expect(exp.sections.devDependencies.has('extra-dev')).toBe(false);
|
|
575
641
|
expect(exp.sections.devDependencies.get('react')).toBe('^18.0.0');
|
|
576
642
|
});
|
|
@@ -594,6 +660,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
594
660
|
const result = deriveDependencyModel(facts);
|
|
595
661
|
const rootExp = result.expected.get('.')!;
|
|
596
662
|
const wsExp = result.expected.get('packages/lib')!;
|
|
663
|
+
|
|
597
664
|
expect(rootExp.sections.devDependencies.get('some-types')).toBe('^1.0.0');
|
|
598
665
|
expect(wsExp.sections.peerDependencies.has('some-types')).toBe(false);
|
|
599
666
|
expect(wsExp.sections.devDependencies.has('some-types')).toBe(false);
|
|
@@ -617,9 +684,11 @@ describe('deriveDependencyModel engine', () => {
|
|
|
617
684
|
]);
|
|
618
685
|
const result = deriveDependencyModel(facts);
|
|
619
686
|
const wsExp = result.expected.get('packages/lib')!;
|
|
687
|
+
|
|
620
688
|
expect(wsExp.sections.peerDependencies.get('some-types')).toBe('^1.0.0');
|
|
621
689
|
expect(wsExp.sections.devDependencies.get('some-types')).toBe('^1.0.0'); // mirror
|
|
622
690
|
const rootExp = result.expected.get('.')!;
|
|
691
|
+
|
|
623
692
|
expect(rootExp.sections.devDependencies.has('some-types')).toBe(false);
|
|
624
693
|
});
|
|
625
694
|
});
|
|
@@ -640,6 +709,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
640
709
|
]);
|
|
641
710
|
const result = deriveDependencyModel(facts);
|
|
642
711
|
const exp = result.expected.get('packages/cli')!;
|
|
712
|
+
|
|
643
713
|
expect(exp.sections.dependencies.get('commander')).toBe('^12.0.0');
|
|
644
714
|
expect(exp.sections.peerDependencies.size).toBe(0);
|
|
645
715
|
expect(exp.sections.devDependencies.size).toBe(0);
|
|
@@ -655,6 +725,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
655
725
|
);
|
|
656
726
|
const facts = emptyFacts([root, ws]);
|
|
657
727
|
const result = deriveDependencyModel(facts);
|
|
728
|
+
|
|
658
729
|
expect(
|
|
659
730
|
result.violations.some(
|
|
660
731
|
(v) => v.code === 'forbidden-section' && v.workspace === '@test/cli',
|
|
@@ -686,6 +757,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
686
757
|
};
|
|
687
758
|
const result = deriveDependencyModel(facts);
|
|
688
759
|
const exp = result.expected.get('packages/svc')!;
|
|
760
|
+
|
|
689
761
|
expect(exp.sections.dependencies.get('react')).toBe('^18.0.0');
|
|
690
762
|
});
|
|
691
763
|
|
|
@@ -710,6 +782,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
710
782
|
};
|
|
711
783
|
const result = deriveDependencyModel(facts);
|
|
712
784
|
const exp = result.expected.get('packages/lib')!;
|
|
785
|
+
|
|
713
786
|
expect(exp.sections.peerDependencies.get('react')).toBe('^18.0.0');
|
|
714
787
|
expect(exp.sections.devDependencies.get('react')).toBe('^18.0.0'); // mirror
|
|
715
788
|
});
|
|
@@ -726,6 +799,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
726
799
|
undefined,
|
|
727
800
|
new Map([['some-pkg', runtimeUsage(['src/index.ts'])]]),
|
|
728
801
|
);
|
|
802
|
+
|
|
729
803
|
// null = коллектор отфильтровал все optional peers; required peers отсутствуют
|
|
730
804
|
const facts: DependencyModelFacts = {
|
|
731
805
|
workspaces: [root, ws],
|
|
@@ -734,6 +808,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
734
808
|
};
|
|
735
809
|
const result = deriveDependencyModel(facts);
|
|
736
810
|
const exp = result.expected.get('packages/svc')!;
|
|
811
|
+
|
|
737
812
|
expect(exp.sections.dependencies.get('some-pkg')).toBe('^3.0.0');
|
|
738
813
|
expect(exp.sections.dependencies.size).toBe(1); // никакие peers не добавились
|
|
739
814
|
});
|
|
@@ -755,6 +830,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
755
830
|
);
|
|
756
831
|
const facts = emptyFacts([root, ws1, ws2]); // нет правил → нет версионного правила для lodash
|
|
757
832
|
const result = deriveDependencyModel(facts);
|
|
833
|
+
|
|
758
834
|
expect(
|
|
759
835
|
result.violations.some(
|
|
760
836
|
(v) => v.code === 'unconstrained-version' && v.dependency === 'lodash',
|
|
@@ -776,6 +852,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
776
852
|
{ match: 'lodash', version: '^4.17.21' },
|
|
777
853
|
]);
|
|
778
854
|
const result = deriveDependencyModel(facts);
|
|
855
|
+
|
|
779
856
|
expect(
|
|
780
857
|
result.violations.some(
|
|
781
858
|
(v) => v.code === 'unconstrained-version' && v.dependency === 'lodash',
|
|
@@ -801,6 +878,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
801
878
|
]);
|
|
802
879
|
const result = deriveDependencyModel(facts);
|
|
803
880
|
const exp = result.expected.get('packages/lib')!;
|
|
881
|
+
|
|
804
882
|
expect(exp.sections.peerDependencies.get('react')).toBe('^18.0.0');
|
|
805
883
|
});
|
|
806
884
|
|
|
@@ -815,11 +893,13 @@ describe('deriveDependencyModel engine', () => {
|
|
|
815
893
|
);
|
|
816
894
|
const facts = emptyFacts([root, ws], [
|
|
817
895
|
{ match: 'some-pkg', version: '^1.0.0' },
|
|
896
|
+
|
|
818
897
|
// workspace-overrides переводит dep из peerDeps в deps для конкретной библиотеки
|
|
819
898
|
{ match: 'some-pkg', workspace: '@test/lib', section: 'dependencies', version: '^1.0.0' },
|
|
820
899
|
]);
|
|
821
900
|
const result = deriveDependencyModel(facts);
|
|
822
901
|
const exp = result.expected.get('packages/lib')!;
|
|
902
|
+
|
|
823
903
|
expect(exp.sections.dependencies.has('some-pkg')).toBe(true);
|
|
824
904
|
expect(exp.sections.peerDependencies.has('some-pkg')).toBe(false);
|
|
825
905
|
});
|
|
@@ -843,6 +923,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
843
923
|
{ match: '@nestjs/*', version: '^10.0.0' },
|
|
844
924
|
]);
|
|
845
925
|
const result = deriveDependencyModel(facts);
|
|
926
|
+
|
|
846
927
|
expect(
|
|
847
928
|
result.violations.some((v) => v.code === 'unconstrained-version'),
|
|
848
929
|
).toBe(false);
|
|
@@ -860,6 +941,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
860
941
|
]);
|
|
861
942
|
const result = deriveDependencyModel(facts);
|
|
862
943
|
const exp = result.expected.get('packages/svc')!;
|
|
944
|
+
|
|
863
945
|
expect(exp.sections.dependencies.get('@nestjs/core')).toBe('^10.3.0');
|
|
864
946
|
});
|
|
865
947
|
});
|
|
@@ -923,6 +1005,83 @@ describe('deriveDependencyModel engine', () => {
|
|
|
923
1005
|
});
|
|
924
1006
|
});
|
|
925
1007
|
|
|
1008
|
+
describe('stale-depdoc-rules', () => {
|
|
1009
|
+
it('reports stale-rule for unused concrete dependency rules', () => {
|
|
1010
|
+
const root = makeRoot();
|
|
1011
|
+
const ws = makeWorkspace('@test/svc', 'packages/svc', 'service');
|
|
1012
|
+
const result = deriveDependencyModel(emptyFacts([root, ws], [
|
|
1013
|
+
{ match: 'unused-lib', version: '^1.0.0' },
|
|
1014
|
+
]));
|
|
1015
|
+
|
|
1016
|
+
expect(
|
|
1017
|
+
result.violations.some(
|
|
1018
|
+
(v) => v.code === 'stale-rule' && v.dependency === 'unused-lib',
|
|
1019
|
+
),
|
|
1020
|
+
).toBe(true);
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
it('does not report required concrete rules as stale', () => {
|
|
1024
|
+
const root = makeRoot();
|
|
1025
|
+
const ws = makeWorkspace('@test/svc', 'packages/svc', 'service');
|
|
1026
|
+
const result = deriveDependencyModel(emptyFacts([root, ws], [
|
|
1027
|
+
{ match: 'required-lib', version: '^1.0.0', required: true },
|
|
1028
|
+
]));
|
|
1029
|
+
|
|
1030
|
+
expect(
|
|
1031
|
+
result.violations.some(
|
|
1032
|
+
(v) => v.code === 'stale-rule' && v.dependency === 'required-lib',
|
|
1033
|
+
),
|
|
1034
|
+
).toBe(false);
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
it('does not report root dev baseline rules as stale', () => {
|
|
1038
|
+
const root = makeRoot({
|
|
1039
|
+
name: '@test/root',
|
|
1040
|
+
private: true,
|
|
1041
|
+
devDependencies: { eslint: '^10.0.0' },
|
|
1042
|
+
});
|
|
1043
|
+
const ws = makeWorkspace('@test/svc', 'packages/svc', 'service');
|
|
1044
|
+
const result = deriveDependencyModel(emptyFacts([root, ws], [
|
|
1045
|
+
{
|
|
1046
|
+
match: 'eslint',
|
|
1047
|
+
section: 'devDependencies',
|
|
1048
|
+
version: '^10.0.0',
|
|
1049
|
+
rootOnly: true,
|
|
1050
|
+
},
|
|
1051
|
+
]));
|
|
1052
|
+
|
|
1053
|
+
expect(
|
|
1054
|
+
result.violations.some(
|
|
1055
|
+
(v) => v.code === 'stale-rule' && v.dependency === 'eslint',
|
|
1056
|
+
),
|
|
1057
|
+
).toBe(false);
|
|
1058
|
+
});
|
|
1059
|
+
|
|
1060
|
+
it('does not report wildcard rules as stale', () => {
|
|
1061
|
+
const root = makeRoot();
|
|
1062
|
+
const ws = makeWorkspace('@test/svc', 'packages/svc', 'service');
|
|
1063
|
+
const result = deriveDependencyModel(emptyFacts([root, ws], [
|
|
1064
|
+
{ match: '@scope/*', version: '^1.0.0' },
|
|
1065
|
+
]));
|
|
1066
|
+
|
|
1067
|
+
expect(result.violations.some((v) => v.code === 'stale-rule')).toBe(false);
|
|
1068
|
+
});
|
|
1069
|
+
|
|
1070
|
+
it('reports workspace-scoped stale rules against the matching workspace', () => {
|
|
1071
|
+
const root = makeRoot();
|
|
1072
|
+
const ws = makeWorkspace('@test/svc', 'packages/svc', 'service');
|
|
1073
|
+
const result = deriveDependencyModel(emptyFacts([root, ws], [
|
|
1074
|
+
{ match: 'unused-lib', workspace: '@test/svc', version: '^1.0.0' },
|
|
1075
|
+
]));
|
|
1076
|
+
const violation = result.violations.find(
|
|
1077
|
+
(v) => v.code === 'stale-rule' && v.dependency === 'unused-lib',
|
|
1078
|
+
);
|
|
1079
|
+
|
|
1080
|
+
expect(violation?.workspace).toBe('@test/svc');
|
|
1081
|
+
expect(violation?.workspaceLocation).toBe('packages/svc');
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1084
|
+
|
|
926
1085
|
describe('dts-mode', () => {
|
|
927
1086
|
it('does not report missing dist when withDts is disabled', () => {
|
|
928
1087
|
const root = makeRoot();
|
|
@@ -977,6 +1136,7 @@ describe('deriveDependencyModel engine', () => {
|
|
|
977
1136
|
false,
|
|
978
1137
|
);
|
|
979
1138
|
const facts = emptyFacts([root, ws]);
|
|
1139
|
+
|
|
980
1140
|
facts.withDts = true;
|
|
981
1141
|
const result = deriveDependencyModel(facts);
|
|
982
1142
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
|
|
3
|
+
import { collectTsConfigPathAliases } from '../src/collectors/tsconfig-aliases';
|
|
3
4
|
import {
|
|
4
5
|
collectDtsImports,
|
|
5
6
|
collectSourceImports,
|
|
@@ -68,40 +69,68 @@ describe('collectSourceImports', () => {
|
|
|
68
69
|
|
|
69
70
|
it('collects runtime imports', () => {
|
|
70
71
|
const pkgs = names();
|
|
72
|
+
|
|
71
73
|
expect(pkgs.has('lodash')).toBe(true);
|
|
72
74
|
expect(pkgs.has('@scope/pkg')).toBe(true);
|
|
73
75
|
expect(pkgs.has('mixed-dep')).toBe(true);
|
|
74
76
|
expect(pkgs.has('require-dep')).toBe(true);
|
|
75
77
|
expect(pkgs.has('dynamic-dep')).toBe(true);
|
|
76
78
|
expect(pkgs.has('reexport-dep')).toBe(true);
|
|
79
|
+
expect(pkgs.has('@docusaurus/router')).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('ignores configured virtual imports', () => {
|
|
83
|
+
const filteredEntries = collectSourceImports(srcDir, undefined, {
|
|
84
|
+
ignoredSpecifiers: ['@docusaurus/router'],
|
|
85
|
+
});
|
|
86
|
+
const pkgs = new Set(filteredEntries.map((e) => e.packageName));
|
|
87
|
+
|
|
88
|
+
expect(pkgs.has('@docusaurus/router')).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('ignores TS path aliases collected from all workspace tsconfigs', () => {
|
|
92
|
+
const aliases = collectTsConfigPathAliases(FIXTURES);
|
|
93
|
+
const filteredEntries = collectSourceImports(srcDir, undefined, {
|
|
94
|
+
ignoredSpecifiers: aliases,
|
|
95
|
+
});
|
|
96
|
+
const pkgs = new Set(filteredEntries.map((e) => e.packageName));
|
|
97
|
+
|
|
98
|
+
expect(aliases).toEqual(expect.arrayContaining(['~app/*', '~shared/*']));
|
|
99
|
+
expect(pkgs.has('~app')).toBe(false);
|
|
100
|
+
expect(pkgs.has('~shared')).toBe(false);
|
|
77
101
|
});
|
|
78
102
|
|
|
79
103
|
it('marks import type entries as isTypeOnly', () => {
|
|
80
104
|
const typeOnlyEntry = entries.find((e) => e.packageName === 'some-types');
|
|
105
|
+
|
|
81
106
|
expect(typeOnlyEntry).toBeDefined();
|
|
82
107
|
expect(typeOnlyEntry!.isTypeOnly).toBe(true);
|
|
83
108
|
});
|
|
84
109
|
|
|
85
110
|
it('marks export type entries as isTypeOnly', () => {
|
|
86
111
|
const entry = entries.find((e) => e.packageName === 'reexport-type-dep');
|
|
112
|
+
|
|
87
113
|
expect(entry).toBeDefined();
|
|
88
114
|
expect(entry!.isTypeOnly).toBe(true);
|
|
89
115
|
});
|
|
90
116
|
|
|
91
117
|
it('marks import specifiers with only type bindings as isTypeOnly', () => {
|
|
92
118
|
const entry = entries.find((e) => e.packageName === 'only-type-dep');
|
|
119
|
+
|
|
93
120
|
expect(entry).toBeDefined();
|
|
94
121
|
expect(entry!.isTypeOnly).toBe(true);
|
|
95
122
|
});
|
|
96
123
|
|
|
97
124
|
it('treats mixed value and type specifiers as runtime imports', () => {
|
|
98
125
|
const entry = entries.find((e) => e.packageName === 'mixed-dep');
|
|
126
|
+
|
|
99
127
|
expect(entry).toBeDefined();
|
|
100
128
|
expect(entry!.isTypeOnly).toBe(false);
|
|
101
129
|
});
|
|
102
130
|
|
|
103
131
|
it('marks runtime imports as not isTypeOnly', () => {
|
|
104
132
|
const entry = entries.find((e) => e.packageName === 'lodash');
|
|
133
|
+
|
|
105
134
|
expect(entry).toBeDefined();
|
|
106
135
|
expect(entry!.isTypeOnly).toBe(false);
|
|
107
136
|
});
|
|
@@ -122,6 +151,7 @@ describe('collectSourceImports', () => {
|
|
|
122
151
|
|
|
123
152
|
it('includes the file path in each entry', () => {
|
|
124
153
|
const entry = entries.find((e) => e.packageName === 'lodash');
|
|
154
|
+
|
|
125
155
|
expect(entry!.file).toContain('index.ts');
|
|
126
156
|
});
|
|
127
157
|
|
|
@@ -131,6 +161,7 @@ describe('collectSourceImports', () => {
|
|
|
131
161
|
|
|
132
162
|
it('collects supported source extensions', () => {
|
|
133
163
|
const pkgs = names();
|
|
164
|
+
|
|
134
165
|
expect(pkgs.has('tsx-runtime-dep')).toBe(true);
|
|
135
166
|
expect(pkgs.has('tsx-type-dep')).toBe(true);
|
|
136
167
|
expect(pkgs.has('mts-dep')).toBe(true);
|
|
@@ -171,10 +202,43 @@ describe('collectSourceImports', () => {
|
|
|
171
202
|
expect(pkgs.has('external-test-dep')).toBe(true);
|
|
172
203
|
});
|
|
173
204
|
|
|
205
|
+
it('collects imports from *.config.* files at the workspace root', () => {
|
|
206
|
+
const workspaceEntries = collectSourceImports(FIXTURES, {
|
|
207
|
+
name: '@test/imports',
|
|
208
|
+
});
|
|
209
|
+
const pkgs = new Set(workspaceEntries.map((e) => e.packageName));
|
|
210
|
+
|
|
211
|
+
expect(pkgs.has('root-config-dep')).toBe(true);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('does not collect root filenames outside the *.config.* convention by default', () => {
|
|
215
|
+
const workspaceEntries = collectSourceImports(FIXTURES, {
|
|
216
|
+
name: '@test/imports',
|
|
217
|
+
});
|
|
218
|
+
const pkgs = new Set(workspaceEntries.map((e) => e.packageName));
|
|
219
|
+
|
|
220
|
+
expect(pkgs.has('sidebars-config-dep')).toBe(false);
|
|
221
|
+
expect(pkgs.has('non-config-root-dep')).toBe(false);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('collects extra root filenames passed in via toolingFilePatterns', () => {
|
|
225
|
+
const workspaceEntries = collectSourceImports(
|
|
226
|
+
FIXTURES,
|
|
227
|
+
{ name: '@test/imports' },
|
|
228
|
+
{},
|
|
229
|
+
['sidebars.ts'],
|
|
230
|
+
);
|
|
231
|
+
const pkgs = new Set(workspaceEntries.map((e) => e.packageName));
|
|
232
|
+
|
|
233
|
+
expect(pkgs.has('sidebars-config-dep')).toBe(true);
|
|
234
|
+
expect(pkgs.has('non-config-root-dep')).toBe(false);
|
|
235
|
+
});
|
|
236
|
+
|
|
174
237
|
it('does not collect .d.ts files (only .ts source files)', () => {
|
|
175
238
|
// dist/ is a sibling of src/, not inside it — so even if we somehow
|
|
176
239
|
// end up scanning it, .d.ts files are explicitly excluded.
|
|
177
240
|
const dtsEntry = entries.find((e) => e.file.endsWith('.d.ts'));
|
|
241
|
+
|
|
178
242
|
expect(dtsEntry).toBeUndefined();
|
|
179
243
|
});
|
|
180
244
|
});
|
|
@@ -215,4 +279,12 @@ describe('collectDtsImports', () => {
|
|
|
215
279
|
it('returns a set (no duplicates)', () => {
|
|
216
280
|
expect(result).toBeInstanceOf(Set);
|
|
217
281
|
});
|
|
282
|
+
|
|
283
|
+
it('ignores TS path aliases in dts imports', () => {
|
|
284
|
+
const filtered = collectDtsImports(distDir, {
|
|
285
|
+
ignoredSpecifiers: collectTsConfigPathAliases(FIXTURES),
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(filtered.has('~shared')).toBe(false);
|
|
289
|
+
});
|
|
218
290
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function collectTsConfigPathAliases(workspaceDir: string): string[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.collectTsConfigPathAliases = collectTsConfigPathAliases;
|
|
7
|
+
/**
|
|
8
|
+
* TypeScript path alias collector.
|
|
9
|
+
*
|
|
10
|
+
* Depdoc treats `compilerOptions.paths` entries as internal module specifiers:
|
|
11
|
+
* they are resolved by TypeScript/bundlers, not package manager dependencies.
|
|
12
|
+
*/
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const ts = require("typescript");
|
|
16
|
+
const TSCONFIG_RE = /^tsconfig(?:\..*)?\.json$/;
|
|
17
|
+
function collectTsConfigPathAliases(workspaceDir) {
|
|
18
|
+
const aliases = new Set();
|
|
19
|
+
let entries;
|
|
20
|
+
try {
|
|
21
|
+
entries = (0, node_fs_1.readdirSync)(workspaceDir, { withFileTypes: true });
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (!entry.isFile() || !TSCONFIG_RE.test(entry.name))
|
|
28
|
+
continue;
|
|
29
|
+
const configPath = node_path_1.default.join(workspaceDir, entry.name);
|
|
30
|
+
const config = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
31
|
+
if (config.error || !config.config)
|
|
32
|
+
continue;
|
|
33
|
+
const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, node_path_1.default.dirname(configPath), undefined, configPath);
|
|
34
|
+
for (const alias of Object.keys(parsed.options.paths ?? {})) {
|
|
35
|
+
aliases.add(alias);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return [...aliases].sort();
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=tsconfig-aliases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tsconfig-aliases.js","sourceRoot":"","sources":["../../src/collectors/tsconfig-aliases.ts"],"names":[],"mappings":";;;;;AAYA,gEAgCC;AA5CD;;;;;GAKG;AACH,qCAAmD;AACnD,0DAA6B;AAC7B,iCAAkC;AAElC,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD,SAAgB,0BAA0B,CAAC,YAAoB;IAC7D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAElC,IAAI,OAAiB,CAAC;IAEtB,IAAI,CAAC;QACH,OAAO,GAAG,IAAA,qBAAW,EAAC,YAAY,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;YAAE,SAAS;QAE/D,MAAM,UAAU,GAAG,mBAAI,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACvD,MAAM,MAAM,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM;YAAE,SAAS;QAE7C,MAAM,MAAM,GAAG,EAAE,CAAC,0BAA0B,CAC1C,MAAM,CAAC,MAAM,EACb,EAAE,CAAC,GAAG,EACN,mBAAI,CAAC,OAAO,CAAC,UAAU,CAAC,EACxB,SAAS,EACT,UAAU,CACX,CAAC;QAEF,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { WorkspaceContext } from '../model/types';
|
|
2
|
-
export declare function loadWorkspaces(rootDir: string, withDts: boolean): WorkspaceContext[];
|
|
1
|
+
import type { ToolingFileRule, WorkspaceContext } from '../model/types';
|
|
2
|
+
export declare function loadWorkspaces(rootDir: string, withDts: boolean, ignoredImports?: readonly string[], toolingFileRules?: readonly ToolingFileRule[]): WorkspaceContext[];
|