@rsdk/depdoc.cli 6.0.0-next.43 → 6.0.0-next.45
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 +42 -6
- package/__tests__/config-validation.test.ts +30 -0
- package/__tests__/engine.test.ts +110 -2
- package/__tests__/fixtures/imports/plain-root-file.ts +3 -0
- package/__tests__/fixtures/imports/sidebars.ts +5 -0
- package/__tests__/fixtures/imports/vite.config.ts +3 -0
- package/__tests__/imports.test.ts +42 -1
- package/__tests__/peer-requirements.test.ts +158 -0
- package/dist/bin/depdoc.js +18 -8
- package/dist/bin/depdoc.js.map +1 -1
- package/dist/collectors/workspaces.d.ts +2 -2
- package/dist/collectors/workspaces.js +12 -4
- package/dist/collectors/workspaces.js.map +1 -1
- package/dist/lib/imports.d.ts +4 -2
- package/dist/lib/imports.js +40 -3
- package/dist/lib/imports.js.map +1 -1
- package/dist/lib/peer-requirements.d.ts +36 -0
- package/dist/lib/peer-requirements.js +85 -0
- package/dist/lib/peer-requirements.js.map +1 -0
- package/dist/model/config-validation.d.ts +1 -0
- package/dist/model/config-validation.js +29 -0
- package/dist/model/config-validation.js.map +1 -1
- package/dist/model/diagnostics.js +4 -1
- package/dist/model/diagnostics.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 +6 -0
- 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/bin/depdoc.ts +36 -8
- package/src/collectors/workspaces.ts +34 -4
- package/src/lib/imports.ts +57 -2
- package/src/lib/peer-requirements.ts +117 -0
- package/src/model/config-validation.ts +45 -2
- package/src/model/diagnostics.ts +6 -1
- package/src/model/placement.ts +19 -1
- package/src/model/types.ts +14 -0
- package/src/runner.ts +1 -0
package/DEPDOC_MODEL.md
CHANGED
|
@@ -6,6 +6,36 @@ This document defines the dependency ownership model for the monorepo. The goal
|
|
|
6
6
|
is to make dependency placement deterministic, checkable, and mostly
|
|
7
7
|
autofixable.
|
|
8
8
|
|
|
9
|
+
## Design Principle: Deterministic, Binary Output
|
|
10
|
+
|
|
11
|
+
`depdoc` exists so a developer does not have to judge severity by hand. In the
|
|
12
|
+
common case, a report must be actionable without reading source or reasoning
|
|
13
|
+
about whether a finding "really" matters.
|
|
14
|
+
|
|
15
|
+
- Every diagnostic is either a **violation** (blocks `check`/`fix`/`doctor`,
|
|
16
|
+
non-zero exit) or a **warning** (printed, does not block). There is no third,
|
|
17
|
+
ambiguous category that leaves the decision to the reader.
|
|
18
|
+
- A check may only become a violation if the engine can derive the expected
|
|
19
|
+
state from facts it already has and the fix is mechanical (apply a rule,
|
|
20
|
+
move a dependency, add a peer, run `fix`). If depdoc cannot compute what
|
|
21
|
+
correct looks like, it must not fail the build over it.
|
|
22
|
+
- Checks must respect ownership boundaries. A failure that cannot be resolved
|
|
23
|
+
by changing anything in this repository — for example, a peer mismatch
|
|
24
|
+
between two external packages with no repo-owned package on either side of
|
|
25
|
+
the edge — is not a dependency-model violation here, even if some
|
|
26
|
+
underlying tool (e.g. `yarn explain peer-requirements`) reports it as an
|
|
27
|
+
error. It gets surfaced (so it is not silently lost) but must not gate
|
|
28
|
+
`doctor`'s exit code.
|
|
29
|
+
- When an external check surfaces something ambiguous, classify it from facts
|
|
30
|
+
depdoc already has (workspace ownership, declared roles, declared entry
|
|
31
|
+
points) instead of asking the developer to decide manually, and instead of
|
|
32
|
+
hard-coding an allowlist of "known-safe" failures that needs upkeep.
|
|
33
|
+
- Prefer deriving a workspace's expectations from what its own manifest
|
|
34
|
+
already declares (`role`, `main`/`types`/`exports`) over introducing new
|
|
35
|
+
manual exception config. `depdoc.yml` overrides exist for cases the model
|
|
36
|
+
truly cannot derive (`V3`), not as a default escape hatch for cases a
|
|
37
|
+
smarter check could resolve on its own.
|
|
38
|
+
|
|
9
39
|
## Terms
|
|
10
40
|
|
|
11
41
|
| Term | Meaning |
|
|
@@ -147,9 +177,11 @@ guess something that an earlier phase can derive.
|
|
|
147
177
|
3. Classify each import as local or external.
|
|
148
178
|
4. Classify each import as runtime, type-only, test-only, or tooling-only.
|
|
149
179
|
5. Scan emitted `dist/**/*.d.ts` imports when `dist/` exists.
|
|
150
|
-
6. In `--with-dts` mode, require `dist/` for workspaces with `src/`;
|
|
151
|
-
`--with-dts`, missing `dist/` is allowed so local source-only
|
|
152
|
-
usable before build.
|
|
180
|
+
6. In `--with-dts` mode, require `dist/` for `library` workspaces with `src/`;
|
|
181
|
+
without `--with-dts`, missing `dist/` is allowed so local source-only
|
|
182
|
+
checks remain usable before build. `service` and `cli` workspaces are never
|
|
183
|
+
required to have `dist/`: they have no public type surface to protect (see
|
|
184
|
+
S2/S3), so there is nothing for the check to guard.
|
|
153
185
|
7. Mark all dependencies found in emitted `.d.ts` as public type surface.
|
|
154
186
|
8. Skip generated entry-point roots such as `dist/`, `build/`, `coverage/`, and
|
|
155
187
|
`node_modules/`.
|
|
@@ -250,7 +282,11 @@ Autofix should write manifests from the derived expected graph:
|
|
|
250
282
|
5. Run the manifest model checker again, because `.d.ts` leaks can change the
|
|
251
283
|
expected graph.
|
|
252
284
|
6. Run package install again if manifests changed.
|
|
253
|
-
7. Assert that package manager peer requirements have no failures
|
|
285
|
+
7. Assert that package manager peer requirements have no failures on any edge
|
|
286
|
+
touching a workspace of this repo. A failure between two external packages,
|
|
287
|
+
with no repo-owned package on either side, cannot be fixed by editing this
|
|
288
|
+
repository's manifests; it is reported as a warning with an example
|
|
289
|
+
`packageExtensions` fix instead of failing `doctor`.
|
|
254
290
|
8. Run the full dependency check task.
|
|
255
291
|
|
|
256
292
|
## Target Tooling Shape
|
|
@@ -442,7 +478,7 @@ focused, because they invoke real tools.
|
|
|
442
478
|
| Test | Proves |
|
|
443
479
|
|---|---|
|
|
444
480
|
| `yarn-install-clean` | After autofix, `yarn install` has no dependency placement warnings. |
|
|
445
|
-
| `yarn-peer-requirements-clean` | `yarn explain peer-requirements` has no failed peer requirements. |
|
|
481
|
+
| `yarn-peer-requirements-clean` | `yarn explain peer-requirements` has no failed peer requirements on any edge touching a workspace; vendor-only failures are warnings, not failures. |
|
|
446
482
|
| `tsc-library-build` | A library with peer + dev mirror compiles. |
|
|
447
483
|
| `tsc-dts-leak` | A public `.d.ts` leak is detected when `dist/` exists and changes expected manifests. |
|
|
448
484
|
| `eslint-extraneous-compatible` | ESLint import/dependency rules do not contradict the model. |
|
|
@@ -464,7 +500,7 @@ Repo smoke tests verify that the model works on the real repository:
|
|
|
464
500
|
3. Build packages.
|
|
465
501
|
4. Run `depdoc check --with-dts`.
|
|
466
502
|
5. Run `yarn install` again if manifests changed.
|
|
467
|
-
6. Assert no failed peer requirements.
|
|
503
|
+
6. Assert no failed peer requirements on any edge touching a workspace.
|
|
468
504
|
7. Run repo lint/typecheck/dependency task.
|
|
469
505
|
|
|
470
506
|
This is the final confidence layer. Most edge cases should still be covered by
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateDependencyRules,
|
|
3
3
|
validateIgnoredImports,
|
|
4
|
+
validateToolingFiles,
|
|
4
5
|
} from '../src/model/config-validation';
|
|
5
6
|
|
|
6
7
|
describe('validateDependencyRules', () => {
|
|
@@ -55,3 +56,32 @@ describe('validateIgnoredImports', () => {
|
|
|
55
56
|
]);
|
|
56
57
|
});
|
|
57
58
|
});
|
|
59
|
+
|
|
60
|
+
describe('validateToolingFiles', () => {
|
|
61
|
+
it('allows a global rule with no workspace scoping', () => {
|
|
62
|
+
expect(validateToolingFiles([{ match: 'sidebars.ts' }])).toEqual([]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('allows a workspace-scoped rule with an array of matches', () => {
|
|
66
|
+
expect(
|
|
67
|
+
validateToolingFiles([
|
|
68
|
+
{
|
|
69
|
+
match: ['sidebars.ts', 'sidebars.js'],
|
|
70
|
+
workspace: 'niisokb.artifactory.docusaurus',
|
|
71
|
+
},
|
|
72
|
+
]),
|
|
73
|
+
).toEqual([]);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it('rejects entries missing match', () => {
|
|
77
|
+
expect(validateToolingFiles([{ workspace: 'foo' }])).toEqual([
|
|
78
|
+
expect.stringContaining('toolingFiles[0].match must be a string'),
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('rejects a non-array value', () => {
|
|
83
|
+
expect(validateToolingFiles('sidebars.ts')).toEqual([
|
|
84
|
+
expect.stringContaining('toolingFiles must be an array'),
|
|
85
|
+
]);
|
|
86
|
+
});
|
|
87
|
+
});
|
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
|
});
|
|
@@ -1054,12 +1136,38 @@ describe('deriveDependencyModel engine', () => {
|
|
|
1054
1136
|
false,
|
|
1055
1137
|
);
|
|
1056
1138
|
const facts = emptyFacts([root, ws]);
|
|
1139
|
+
|
|
1057
1140
|
facts.withDts = true;
|
|
1058
1141
|
const result = deriveDependencyModel(facts);
|
|
1059
1142
|
|
|
1060
1143
|
expect(result.violations.some((v) => v.code === 'dist-missing')).toBe(true);
|
|
1061
1144
|
});
|
|
1062
1145
|
|
|
1146
|
+
it.each(['service', 'cli'] as const)(
|
|
1147
|
+
'does not report missing dist for %s workspaces even when withDts is enabled',
|
|
1148
|
+
(role) => {
|
|
1149
|
+
const root = makeRoot();
|
|
1150
|
+
const ws = makeWorkspace(
|
|
1151
|
+
'@test/app',
|
|
1152
|
+
'packages/app',
|
|
1153
|
+
role,
|
|
1154
|
+
{ name: '@test/app', role },
|
|
1155
|
+
new Map(),
|
|
1156
|
+
new Set(),
|
|
1157
|
+
true,
|
|
1158
|
+
false,
|
|
1159
|
+
);
|
|
1160
|
+
const facts = emptyFacts([root, ws]);
|
|
1161
|
+
|
|
1162
|
+
facts.withDts = true;
|
|
1163
|
+
const result = deriveDependencyModel(facts);
|
|
1164
|
+
|
|
1165
|
+
expect(
|
|
1166
|
+
result.violations.some((v) => v.code === 'dist-missing'),
|
|
1167
|
+
).toBe(false);
|
|
1168
|
+
},
|
|
1169
|
+
);
|
|
1170
|
+
|
|
1063
1171
|
it('promotes matching DefinitelyTyped provider for public dts imports', () => {
|
|
1064
1172
|
const root = makeRoot({
|
|
1065
1173
|
name: '@test/root',
|
|
@@ -1,11 +1,11 @@
|
|
|
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,
|
|
6
7
|
getPackageName,
|
|
7
8
|
} from '../src/lib/imports';
|
|
8
|
-
import { collectTsConfigPathAliases } from '../src/collectors/tsconfig-aliases';
|
|
9
9
|
|
|
10
10
|
const FIXTURES = path.join(__dirname, 'fixtures/imports');
|
|
11
11
|
|
|
@@ -69,6 +69,7 @@ describe('collectSourceImports', () => {
|
|
|
69
69
|
|
|
70
70
|
it('collects runtime imports', () => {
|
|
71
71
|
const pkgs = names();
|
|
72
|
+
|
|
72
73
|
expect(pkgs.has('lodash')).toBe(true);
|
|
73
74
|
expect(pkgs.has('@scope/pkg')).toBe(true);
|
|
74
75
|
expect(pkgs.has('mixed-dep')).toBe(true);
|
|
@@ -101,30 +102,35 @@ describe('collectSourceImports', () => {
|
|
|
101
102
|
|
|
102
103
|
it('marks import type entries as isTypeOnly', () => {
|
|
103
104
|
const typeOnlyEntry = entries.find((e) => e.packageName === 'some-types');
|
|
105
|
+
|
|
104
106
|
expect(typeOnlyEntry).toBeDefined();
|
|
105
107
|
expect(typeOnlyEntry!.isTypeOnly).toBe(true);
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
it('marks export type entries as isTypeOnly', () => {
|
|
109
111
|
const entry = entries.find((e) => e.packageName === 'reexport-type-dep');
|
|
112
|
+
|
|
110
113
|
expect(entry).toBeDefined();
|
|
111
114
|
expect(entry!.isTypeOnly).toBe(true);
|
|
112
115
|
});
|
|
113
116
|
|
|
114
117
|
it('marks import specifiers with only type bindings as isTypeOnly', () => {
|
|
115
118
|
const entry = entries.find((e) => e.packageName === 'only-type-dep');
|
|
119
|
+
|
|
116
120
|
expect(entry).toBeDefined();
|
|
117
121
|
expect(entry!.isTypeOnly).toBe(true);
|
|
118
122
|
});
|
|
119
123
|
|
|
120
124
|
it('treats mixed value and type specifiers as runtime imports', () => {
|
|
121
125
|
const entry = entries.find((e) => e.packageName === 'mixed-dep');
|
|
126
|
+
|
|
122
127
|
expect(entry).toBeDefined();
|
|
123
128
|
expect(entry!.isTypeOnly).toBe(false);
|
|
124
129
|
});
|
|
125
130
|
|
|
126
131
|
it('marks runtime imports as not isTypeOnly', () => {
|
|
127
132
|
const entry = entries.find((e) => e.packageName === 'lodash');
|
|
133
|
+
|
|
128
134
|
expect(entry).toBeDefined();
|
|
129
135
|
expect(entry!.isTypeOnly).toBe(false);
|
|
130
136
|
});
|
|
@@ -145,6 +151,7 @@ describe('collectSourceImports', () => {
|
|
|
145
151
|
|
|
146
152
|
it('includes the file path in each entry', () => {
|
|
147
153
|
const entry = entries.find((e) => e.packageName === 'lodash');
|
|
154
|
+
|
|
148
155
|
expect(entry!.file).toContain('index.ts');
|
|
149
156
|
});
|
|
150
157
|
|
|
@@ -154,6 +161,7 @@ describe('collectSourceImports', () => {
|
|
|
154
161
|
|
|
155
162
|
it('collects supported source extensions', () => {
|
|
156
163
|
const pkgs = names();
|
|
164
|
+
|
|
157
165
|
expect(pkgs.has('tsx-runtime-dep')).toBe(true);
|
|
158
166
|
expect(pkgs.has('tsx-type-dep')).toBe(true);
|
|
159
167
|
expect(pkgs.has('mts-dep')).toBe(true);
|
|
@@ -194,10 +202,43 @@ describe('collectSourceImports', () => {
|
|
|
194
202
|
expect(pkgs.has('external-test-dep')).toBe(true);
|
|
195
203
|
});
|
|
196
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
|
+
|
|
197
237
|
it('does not collect .d.ts files (only .ts source files)', () => {
|
|
198
238
|
// dist/ is a sibling of src/, not inside it — so even if we somehow
|
|
199
239
|
// end up scanning it, .d.ts files are explicitly excluded.
|
|
200
240
|
const dtsEntry = entries.find((e) => e.file.endsWith('.d.ts'));
|
|
241
|
+
|
|
201
242
|
expect(dtsEntry).toBeUndefined();
|
|
202
243
|
});
|
|
203
244
|
});
|