@angular-modernizer/adapter-mcp 2.0.0 → 2.1.0
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/CHANGELOG.md +26 -0
- package/dist/index.d.ts +1 -0
- package/dist/tools/analyze-project.d.ts +26 -1
- package/dist/tools/analyze-project.js +8 -3
- package/dist/tools/compare-health.d.ts +40 -4
- package/dist/tools/compare-health.js +22 -5
- package/dist/tools/helpers/analysis-output.js +3 -0
- package/dist/tools/helpers/health-delta.d.ts +6 -0
- package/dist/tools/helpers/health-delta.js +4 -1
- package/dist/tools/helpers/library-import-warning.d.ts +33 -0
- package/dist/tools/helpers/library-import-warning.js +38 -0
- package/dist/tools/helpers/library-imports.d.ts +38 -14
- package/dist/tools/helpers/library-imports.js +128 -23
- package/dist/tools/helpers/output-contract.d.ts +22 -0
- package/dist/tools/helpers/output-contract.js +13 -0
- package/dist/tools/helpers/refresh-apply.js +1 -1
- package/dist/tools/helpers/refresh-inventory.d.ts +1 -1
- package/dist/tools/helpers/refresh-inventory.js +24 -3
- package/dist/tools/helpers/scan-cache.d.ts +45 -2
- package/dist/tools/helpers/scan-cache.js +47 -2
- package/dist/tools/helpers/scan-engine.d.ts +13 -0
- package/dist/tools/helpers/scan-engine.js +10 -0
- package/dist/tools/list-imports.d.ts +1 -1
- package/dist/tools/refresh-state.js +1 -1
- package/dist/tools/scan-all.d.ts +7 -1
- package/dist/tools/scan-all.js +8 -13
- package/dist/tools/scan-angular.d.ts +7 -1
- package/dist/tools/scan-angular.js +7 -2
- package/dist/tools/scan-architecture.d.ts +8 -0
- package/dist/tools/scan-architecture.js +25 -14
- package/dist/tools/scan-solid.d.ts +7 -1
- package/dist/tools/scan-solid.js +7 -2
- package/package.json +11 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @angular-modernizer/adapter-mcp
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5306ac3: scan-all, scan-solid, scan-angular, scan-architecture and analyze-project warn about library imports that do not resolve (missing or incomplete node_modules), also on a warm run served from the scan cache: the warning goes into `warnings` and one summary line, the counts into `unresolvedLibraryImports`. Without library types, type-dependent rules report very different numbers. The unresolved packages are part of the scan cache version, so entries written without a complete node_modules are not served once it is complete, and the other way round. The scan cache layout versions move to scan-5, scan-all-6 and scan-architecture-4, so every cache written before this release is stale once (one cold scan per project); refresh-state lists such entries as `outdated-layout`. compare-health records `libraryTypesResolved` in its snapshot (older snapshots count as resolved) and answers `environment-mismatch` without a delta when the current run and the snapshot differ in it; the snapshot is then replaced only with `updateSnapshot: true`.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- a7a2e6a: Suppression comments count wherever they clearly belong to the reported construct. A marker on any line of the contiguous comment block directly above the reported node counts (before, only a comment ending on the line directly above did, so a marker on the first line of a two-line block was ignored); a blank line still ends the block. A finding on a line inside a decorator, such as the `changeDetection` property of `@Component({...})`, is also suppressed by a marker anywhere inside that decorator (above the property or trailing another property) or in the comment block directly above the decorator list; the class body and the decorators of other declarations do not count. Templates are unchanged. The scan cache versions move to `scan-5`, `scan-all-6` and `scan-architecture-4`, because cached findings were filtered with the old placement and are analyzed again once.
|
|
12
|
+
- Updated dependencies [b1ad47b]
|
|
13
|
+
- Updated dependencies [8e55c18]
|
|
14
|
+
- Updated dependencies [a3d2ad1]
|
|
15
|
+
- Updated dependencies [2709195]
|
|
16
|
+
- Updated dependencies [3f77a02]
|
|
17
|
+
- Updated dependencies [a7a2e6a]
|
|
18
|
+
- @angular-modernizer/plugin-angular@2.1.0
|
|
19
|
+
- @angular-modernizer/plugin-solid@2.1.0
|
|
20
|
+
- @angular-modernizer/api@2.1.0
|
|
21
|
+
- @angular-modernizer/core@2.1.0
|
|
22
|
+
- @angular-modernizer/worker@2.1.0
|
|
23
|
+
- @angular-modernizer/orchestration@2.1.0
|
|
24
|
+
- @angular-modernizer/plugin-analyzer@2.1.0
|
|
25
|
+
- @angular-modernizer/plugin-architecture@2.1.0
|
|
26
|
+
- @angular-modernizer/plugin-standalone@2.1.0
|
|
27
|
+
- @angular-modernizer/plugin-system@2.1.0
|
|
28
|
+
|
|
3
29
|
## 2.0.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -169,6 +169,7 @@ export type { IncrementalMetadata as ValidateTransformationIncrementalMetadata }
|
|
|
169
169
|
export type { VerifiedCitation } from './tools/verify-citations.js';
|
|
170
170
|
export type { ScanCounts } from './tools/helpers/analysis-output.js';
|
|
171
171
|
export type { FileDelta, HealthViolation, RuleDelta, } from './tools/helpers/health-delta.js';
|
|
172
|
+
export type { UnresolvedLibraryImports } from './tools/helpers/library-import-warning.js';
|
|
172
173
|
export type { AcquireControl, CachedProjectInfo, EvictionReason, EvictionStats, ProjectCacheLimits, ProjectEviction, } from './tools/helpers/project-cache.js';
|
|
173
174
|
export type { RuleTiming } from './tools/helpers/rule-runner.js';
|
|
174
175
|
export type { Performance, Suggestion } from './tools/helpers/suggestion-generator.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { MCPTool, ToolAnnotations, ToolContext } from '../types.js';
|
|
2
2
|
import { type CancelledExecution } from './helpers/tool-context.js';
|
|
3
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
3
4
|
/**
|
|
4
5
|
* Result from the analyze-project tool.
|
|
5
6
|
*/
|
|
@@ -204,8 +205,13 @@ export interface AnalyzeProjectResult {
|
|
|
204
205
|
};
|
|
205
206
|
/** Set when the client cancelled the analysis; counts cover the analyzed files. */
|
|
206
207
|
execution?: CancelledExecution;
|
|
207
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* Program files that could not be read and were left out of the analysis,
|
|
210
|
+
* and library imports that do not resolve.
|
|
211
|
+
*/
|
|
208
212
|
warnings?: string[];
|
|
213
|
+
/** Library imports of the analyzed files that do not resolve (sequential path); absent when all resolve. */
|
|
214
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
209
215
|
}
|
|
210
216
|
/**
|
|
211
217
|
* MCP tool `analyze-project`: detects the framework (Angular CLI, Nx),
|
|
@@ -342,6 +348,25 @@ export declare class AnalyzeProjectTool implements MCPTool {
|
|
|
342
348
|
summary: {
|
|
343
349
|
type: string;
|
|
344
350
|
};
|
|
351
|
+
unresolvedLibraryImports: {
|
|
352
|
+
readonly type: "object";
|
|
353
|
+
readonly description: "Library imports of the scanned files that do not resolve (node_modules missing or incomplete); rules that need library types can report less. Absent when all resolve.";
|
|
354
|
+
readonly properties: {
|
|
355
|
+
readonly imports: {
|
|
356
|
+
readonly type: "integer";
|
|
357
|
+
};
|
|
358
|
+
readonly packages: {
|
|
359
|
+
readonly type: "integer";
|
|
360
|
+
};
|
|
361
|
+
readonly examples: {
|
|
362
|
+
readonly type: "array";
|
|
363
|
+
readonly items: {
|
|
364
|
+
readonly type: "string";
|
|
365
|
+
};
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
readonly required: readonly ["imports", "packages", "examples"];
|
|
369
|
+
};
|
|
345
370
|
warnings: {
|
|
346
371
|
readonly type: "array";
|
|
347
372
|
readonly items: {
|
|
@@ -11,7 +11,8 @@ import { PAGINATION_SCHEMA, SCAN_EXECUTION_SCHEMA, nameList, pageNote, } from '.
|
|
|
11
11
|
import { cancelledExecution, fileProgressMessage, finalFileProgress, forwardKernelProgress, } from './helpers/tool-context.js';
|
|
12
12
|
import { runScan } from '../scan-host/scan-host.js';
|
|
13
13
|
import { STRING_ARRAY } from './helpers/investigation-schemas.js';
|
|
14
|
-
import { WARNINGS_OUTPUT_SCHEMA, withWarnings } from './helpers/output-contract.js';
|
|
14
|
+
import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, withWarnings, } from './helpers/output-contract.js';
|
|
15
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
15
16
|
/** Application or library entry of `framework.projects`. */
|
|
16
17
|
const NAMED_PROJECT_SCHEMA = {
|
|
17
18
|
type: 'object',
|
|
@@ -352,6 +353,7 @@ export class AnalyzeProjectTool {
|
|
|
352
353
|
execution: SCAN_EXECUTION_SCHEMA,
|
|
353
354
|
progress: { type: 'object' },
|
|
354
355
|
...WARNINGS_OUTPUT_SCHEMA,
|
|
356
|
+
...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
|
|
355
357
|
summary: { type: 'string' },
|
|
356
358
|
},
|
|
357
359
|
required: [
|
|
@@ -414,6 +416,7 @@ export class AnalyzeProjectTool {
|
|
|
414
416
|
let filesAnalyzed = 0;
|
|
415
417
|
let execution;
|
|
416
418
|
const warnings = [];
|
|
419
|
+
let unresolvedLibraryImports;
|
|
417
420
|
let fileCap;
|
|
418
421
|
const maxFiles = parseMaxFiles(mergedParams.maxFiles);
|
|
419
422
|
let lastProgress;
|
|
@@ -539,6 +542,7 @@ export class AnalyzeProjectTool {
|
|
|
539
542
|
rootPath: mergedParams.rootPath,
|
|
540
543
|
files: sequentialFiles,
|
|
541
544
|
mode: 'sequential',
|
|
545
|
+
libraryImports: true,
|
|
542
546
|
}, {
|
|
543
547
|
file: (event) => {
|
|
544
548
|
for (const finding of event.findings) {
|
|
@@ -562,6 +566,7 @@ export class AnalyzeProjectTool {
|
|
|
562
566
|
if (unreadableWarning !== undefined) {
|
|
563
567
|
warnings.push(unreadableWarning);
|
|
564
568
|
}
|
|
569
|
+
unresolvedLibraryImports = engine.unresolvedLibraryImports;
|
|
565
570
|
if (engine.cancelled) {
|
|
566
571
|
execution = cancelledExecution(done, sequentialFiles.length - done);
|
|
567
572
|
}
|
|
@@ -648,10 +653,10 @@ export class AnalyzeProjectTool {
|
|
|
648
653
|
progress: lastProgress,
|
|
649
654
|
...(execution === undefined ? {} : { execution }),
|
|
650
655
|
};
|
|
651
|
-
const result = withWarnings({
|
|
656
|
+
const result = withLibraryImportWarning(withWarnings({
|
|
652
657
|
...analysis,
|
|
653
658
|
summary: describeAnalysis({ ...analysis, fileCap }, totalResults),
|
|
654
|
-
}, warnings);
|
|
659
|
+
}, warnings), unresolvedLibraryImports);
|
|
655
660
|
// Mark operation as completed successfully
|
|
656
661
|
if (opId) {
|
|
657
662
|
const message = paginationMetadata
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type FileSystemAdapter } from '@angular-modernizer/core';
|
|
2
2
|
import { type MCPTool, type ToolAnnotations, type ToolContext } from '../types.js';
|
|
3
3
|
import { type FileDelta, type HealthViolation, type RuleDelta } from './helpers/health-delta.js';
|
|
4
|
+
import { type UnresolvedLibraryImports } from './helpers/library-import-warning.js';
|
|
4
5
|
/** The part of a scan-all result the comparison needs. */
|
|
5
6
|
export interface HealthScanResult {
|
|
6
7
|
/** All violations of the scan. */
|
|
@@ -28,6 +29,8 @@ export interface HealthScanResult {
|
|
|
28
29
|
/** Ids of the rules that ran. */
|
|
29
30
|
rulesExecuted: string[];
|
|
30
31
|
};
|
|
32
|
+
/** Library imports that do not resolve; absent when all resolve. */
|
|
33
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
31
34
|
/** Set by scan-all when the client cancelled the scan. */
|
|
32
35
|
execution?: {
|
|
33
36
|
/** `cancelled` when the client cancelled the scan. */
|
|
@@ -43,9 +46,12 @@ export type HealthScan = (args: Record<string, unknown>, ctx?: ToolContext) => P
|
|
|
43
46
|
* - `no-baseline`: no snapshot existed and `updateSnapshot` was `false`.
|
|
44
47
|
* - `scope-mismatch`: the snapshot used other rules or include/exclude
|
|
45
48
|
* patterns; nothing was compared.
|
|
49
|
+
* - `environment-mismatch`: library imports resolved in one run and not in
|
|
50
|
+
* the other (node_modules missing or incomplete), so rules that need
|
|
51
|
+
* library types are not comparable; nothing was compared.
|
|
46
52
|
* - `invalid-snapshot`: the snapshot could not be read; nothing was compared.
|
|
47
53
|
*/
|
|
48
|
-
export type CompareHealthStatus = 'compared' | 'baseline-created' | 'no-baseline' | 'scope-mismatch' | 'invalid-snapshot';
|
|
54
|
+
export type CompareHealthStatus = 'compared' | 'baseline-created' | 'no-baseline' | 'scope-mismatch' | 'environment-mismatch' | 'invalid-snapshot';
|
|
49
55
|
/** Counts of one run. */
|
|
50
56
|
export interface HealthRunInfo {
|
|
51
57
|
/** Time of the run (ISO 8601). */
|
|
@@ -111,6 +117,10 @@ export interface CompareHealthOutput {
|
|
|
111
117
|
scopeDifferences: string[];
|
|
112
118
|
/** `true` when `maxResults` cut one of the lists. */
|
|
113
119
|
truncated: boolean;
|
|
120
|
+
/** The warning of a run whose library imports do not resolve. */
|
|
121
|
+
warnings?: string[];
|
|
122
|
+
/** Library imports of the current run that do not resolve; absent when all resolve. */
|
|
123
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
114
124
|
/** Human-readable summary for LLM consumption. */
|
|
115
125
|
summary: string;
|
|
116
126
|
}
|
|
@@ -204,6 +214,35 @@ export declare class CompareHealthTool implements MCPTool {
|
|
|
204
214
|
readonly outputSchema: {
|
|
205
215
|
type: string;
|
|
206
216
|
properties: {
|
|
217
|
+
summary: {
|
|
218
|
+
type: string;
|
|
219
|
+
};
|
|
220
|
+
unresolvedLibraryImports: {
|
|
221
|
+
readonly type: "object";
|
|
222
|
+
readonly description: "Library imports of the scanned files that do not resolve (node_modules missing or incomplete); rules that need library types can report less. Absent when all resolve.";
|
|
223
|
+
readonly properties: {
|
|
224
|
+
readonly imports: {
|
|
225
|
+
readonly type: "integer";
|
|
226
|
+
};
|
|
227
|
+
readonly packages: {
|
|
228
|
+
readonly type: "integer";
|
|
229
|
+
};
|
|
230
|
+
readonly examples: {
|
|
231
|
+
readonly type: "array";
|
|
232
|
+
readonly items: {
|
|
233
|
+
readonly type: "string";
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
readonly required: readonly ["imports", "packages", "examples"];
|
|
238
|
+
};
|
|
239
|
+
warnings: {
|
|
240
|
+
readonly type: "array";
|
|
241
|
+
readonly items: {
|
|
242
|
+
readonly type: "string";
|
|
243
|
+
};
|
|
244
|
+
readonly description: "Conditions that can make the result incomplete, e.g. library imports that do not resolve because node_modules is missing.";
|
|
245
|
+
};
|
|
207
246
|
status: {
|
|
208
247
|
type: string;
|
|
209
248
|
enum: string[];
|
|
@@ -400,9 +439,6 @@ export declare class CompareHealthTool implements MCPTool {
|
|
|
400
439
|
truncated: {
|
|
401
440
|
type: string;
|
|
402
441
|
};
|
|
403
|
-
summary: {
|
|
404
|
-
type: string;
|
|
405
|
-
};
|
|
406
442
|
};
|
|
407
443
|
required: string[];
|
|
408
444
|
};
|
|
@@ -2,6 +2,8 @@ import { isAbsolute, relative, resolve } from 'node:path';
|
|
|
2
2
|
import { RealFileSystemAdapter, } from '@angular-modernizer/core';
|
|
3
3
|
import { COMPACT_OUTPUT_SCHEMA, limitList, parseCompactOptions, } from './helpers/compact-output.js';
|
|
4
4
|
import { DEFAULT_HEALTH_SNAPSHOT_PATH, HEALTH_SNAPSHOT_VERSION, compareHealth, compareViolations, parseHealthSnapshot, scopeDifferences, serializeHealthSnapshot, } from './helpers/health-delta.js';
|
|
5
|
+
import { withLibraryImportWarning, } from './helpers/library-import-warning.js';
|
|
6
|
+
import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, } from './helpers/output-contract.js';
|
|
5
7
|
import { ScanAllTool } from './scan-all.js';
|
|
6
8
|
/** Violations spelled out per list in the summary; the rest is in the lists. */
|
|
7
9
|
const SUMMARY_LINES = 15;
|
|
@@ -61,7 +63,9 @@ export class CompareHealthTool {
|
|
|
61
63
|
'with digits ignored, not by line, so code moving up or down stays unchanged. The first run writes the ' +
|
|
62
64
|
'baseline (status baseline-created). After a comparison the snapshot is replaced by the current run ' +
|
|
63
65
|
'unless updateSnapshot is false. A snapshot taken with other rules or include/exclude patterns is not ' +
|
|
64
|
-
'compared (status scope-mismatch) and is only replaced with updateSnapshot: true
|
|
66
|
+
'compared (status scope-mismatch) and is only replaced with updateSnapshot: true; the same for a snapshot ' +
|
|
67
|
+
'whose library imports resolved while the current ones do not, or the other way round (status ' +
|
|
68
|
+
'environment-mismatch, missing node_modules). currentRun.bySeverity ' +
|
|
65
69
|
'and byCategory count all violations. Writes only the snapshot file.';
|
|
66
70
|
annotations = {
|
|
67
71
|
readOnlyHint: false,
|
|
@@ -124,6 +128,7 @@ export class CompareHealthTool {
|
|
|
124
128
|
'baseline-created',
|
|
125
129
|
'no-baseline',
|
|
126
130
|
'scope-mismatch',
|
|
131
|
+
'environment-mismatch',
|
|
127
132
|
'invalid-snapshot',
|
|
128
133
|
],
|
|
129
134
|
},
|
|
@@ -191,6 +196,8 @@ export class CompareHealthTool {
|
|
|
191
196
|
rulesRemoved: STRING_LIST,
|
|
192
197
|
scopeDifferences: STRING_LIST,
|
|
193
198
|
truncated: { type: 'boolean' },
|
|
199
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
200
|
+
...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
|
|
194
201
|
summary: { type: 'string' },
|
|
195
202
|
},
|
|
196
203
|
required: [
|
|
@@ -234,6 +241,7 @@ export class CompareHealthTool {
|
|
|
234
241
|
scope: input.scope,
|
|
235
242
|
rulesExecuted: [...scanResult.metadata.rulesExecuted].sort(),
|
|
236
243
|
analyzedFiles: scanResult.counts.analyzedFiles,
|
|
244
|
+
libraryTypesResolved: (scanResult.unresolvedLibraryImports?.imports ?? 0) === 0,
|
|
237
245
|
violations: scanResult.violations
|
|
238
246
|
.map(toHealthViolation)
|
|
239
247
|
.sort(compareViolations),
|
|
@@ -243,7 +251,7 @@ export class CompareHealthTool {
|
|
|
243
251
|
const differences = previous === undefined
|
|
244
252
|
? []
|
|
245
253
|
: scopeDifferences(previous.scope, current.scope);
|
|
246
|
-
const status = decideStatus(stored, differences);
|
|
254
|
+
const status = decideStatus(stored, differences, current);
|
|
247
255
|
const write = input.updateSnapshot === true ||
|
|
248
256
|
(input.updateSnapshot === undefined &&
|
|
249
257
|
(status === 'compared' || status === 'baseline-created'));
|
|
@@ -260,7 +268,7 @@ export class CompareHealthTool {
|
|
|
260
268
|
differences,
|
|
261
269
|
compact,
|
|
262
270
|
});
|
|
263
|
-
return output;
|
|
271
|
+
return withLibraryImportWarning(output, scanResult.unresolvedLibraryImports);
|
|
264
272
|
}
|
|
265
273
|
async readSnapshot(path) {
|
|
266
274
|
if (!(await this.fileSystem.exists(path))) {
|
|
@@ -334,14 +342,19 @@ function toHealthViolation(v) {
|
|
|
334
342
|
...(v.line === undefined ? {} : { line: v.line }),
|
|
335
343
|
};
|
|
336
344
|
}
|
|
337
|
-
function decideStatus(stored, differences) {
|
|
345
|
+
function decideStatus(stored, differences, current) {
|
|
338
346
|
if (!stored.exists) {
|
|
339
347
|
return 'baseline-created';
|
|
340
348
|
}
|
|
341
349
|
if (stored.snapshot === undefined) {
|
|
342
350
|
return 'invalid-snapshot';
|
|
343
351
|
}
|
|
344
|
-
|
|
352
|
+
if (differences.length > 0) {
|
|
353
|
+
return 'scope-mismatch';
|
|
354
|
+
}
|
|
355
|
+
return stored.snapshot.libraryTypesResolved === current.libraryTypesResolved
|
|
356
|
+
? 'compared'
|
|
357
|
+
: 'environment-mismatch';
|
|
345
358
|
}
|
|
346
359
|
function buildOutput(parts) {
|
|
347
360
|
const { root, snapshotLabel, written, previous, current, differences, compact, } = parts;
|
|
@@ -470,6 +483,10 @@ function describeOther(status, snapshotLabel, previous, current, differences, wr
|
|
|
470
483
|
case 'scope-mismatch':
|
|
471
484
|
return (`The previous run (${previous?.createdAt ?? '?'}) used another scope, so nothing was compared: ` +
|
|
472
485
|
`${differences.join('; ')}.${replaced}`);
|
|
486
|
+
case 'environment-mismatch':
|
|
487
|
+
return (`Library imports ${current.libraryTypesResolved ? 'resolve now but did not' : 'do not resolve now but did'} ` +
|
|
488
|
+
`in the previous run (${previous?.createdAt ?? '?'}), so rules that need library types are not ` +
|
|
489
|
+
`comparable and nothing was compared; is node_modules missing or incomplete in one of the runs?${replaced}`);
|
|
473
490
|
case 'invalid-snapshot':
|
|
474
491
|
return `${snapshotLabel} is not a readable health snapshot (version ${HEALTH_SNAPSHOT_VERSION}); nothing was compared.${replaced}`;
|
|
475
492
|
case 'compared':
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Schema pieces and summary helpers shared by analyze-project and the scans.
|
|
5
5
|
* Objects stay open, see `output-contract.ts`.
|
|
6
6
|
*/
|
|
7
|
+
import { UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA, WARNINGS_OUTPUT_SCHEMA, } from './output-contract.js';
|
|
7
8
|
/** `pagination` of a paged result list. */
|
|
8
9
|
export const PAGINATION_SCHEMA = {
|
|
9
10
|
type: 'object',
|
|
@@ -136,6 +137,8 @@ export function scanOutputSchema(extra = {}) {
|
|
|
136
137
|
},
|
|
137
138
|
pagination: PAGINATION_SCHEMA,
|
|
138
139
|
orchestration: { type: 'object' },
|
|
140
|
+
...WARNINGS_OUTPUT_SCHEMA,
|
|
141
|
+
...UNRESOLVED_LIBRARY_IMPORTS_OUTPUT_SCHEMA,
|
|
139
142
|
...extra,
|
|
140
143
|
summary: { type: 'string' },
|
|
141
144
|
},
|
|
@@ -26,6 +26,12 @@ export interface HealthSnapshot {
|
|
|
26
26
|
scope: HealthScope;
|
|
27
27
|
rulesExecuted: string[];
|
|
28
28
|
analyzedFiles: number;
|
|
29
|
+
/**
|
|
30
|
+
* Whether every library import of the scan resolved (node_modules
|
|
31
|
+
* complete); rules that need library types report differently without
|
|
32
|
+
* them. Absent in snapshots written before the flag: read as `true`.
|
|
33
|
+
*/
|
|
34
|
+
libraryTypesResolved: boolean;
|
|
29
35
|
violations: HealthViolation[];
|
|
30
36
|
}
|
|
31
37
|
/** Counts of one rule in the previous and the current run. */
|
|
@@ -30,6 +30,7 @@ export function serializeHealthSnapshot(snapshot) {
|
|
|
30
30
|
scope: snapshot.scope,
|
|
31
31
|
rulesExecuted: snapshot.rulesExecuted,
|
|
32
32
|
analyzedFiles: snapshot.analyzedFiles,
|
|
33
|
+
libraryTypesResolved: snapshot.libraryTypesResolved,
|
|
33
34
|
totalViolations: snapshot.violations.length,
|
|
34
35
|
});
|
|
35
36
|
const lines = [...files].map(([file, list]) => `${JSON.stringify(file)}:${JSON.stringify(list)}`);
|
|
@@ -52,11 +53,12 @@ export function parseHealthSnapshot(text) {
|
|
|
52
53
|
if (!isRecord(data) || data['version'] !== HEALTH_SNAPSHOT_VERSION) {
|
|
53
54
|
return undefined;
|
|
54
55
|
}
|
|
55
|
-
const { createdAt, scope, rulesExecuted, analyzedFiles, files } = data;
|
|
56
|
+
const { createdAt, scope, rulesExecuted, analyzedFiles, libraryTypesResolved, files } = data;
|
|
56
57
|
const valid = typeof createdAt === 'string' &&
|
|
57
58
|
isScope(scope) &&
|
|
58
59
|
isStringArray(rulesExecuted) &&
|
|
59
60
|
typeof analyzedFiles === 'number' &&
|
|
61
|
+
(libraryTypesResolved === undefined || typeof libraryTypesResolved === 'boolean') &&
|
|
60
62
|
isRecord(files);
|
|
61
63
|
if (!valid) {
|
|
62
64
|
return undefined;
|
|
@@ -83,6 +85,7 @@ export function parseHealthSnapshot(text) {
|
|
|
83
85
|
scope,
|
|
84
86
|
rulesExecuted,
|
|
85
87
|
analyzedFiles,
|
|
88
|
+
libraryTypesResolved: libraryTypesResolved ?? true,
|
|
86
89
|
violations,
|
|
87
90
|
};
|
|
88
91
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Warning about unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts, warning text and the result helper of the library import check
|
|
5
|
+
* (`library-imports.ts`). Kept apart from the check so the scan tools can
|
|
6
|
+
* add the warning without loading ts-morph (their unit tests mock `node:fs`).
|
|
7
|
+
*/
|
|
8
|
+
/** Library imports of a project that do not resolve. */
|
|
9
|
+
export interface UnresolvedLibraryImports {
|
|
10
|
+
/** Import and `export ... from` declarations with an unresolved library specifier. */
|
|
11
|
+
imports: number;
|
|
12
|
+
/** Distinct packages among them (`@scope/name` or `name`). */
|
|
13
|
+
packages: number;
|
|
14
|
+
/** Up to {@link EXAMPLE_PACKAGES} package names, most imported first. */
|
|
15
|
+
examples: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Package names listed in the warning. */
|
|
18
|
+
export declare const EXAMPLE_PACKAGES = 5;
|
|
19
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
20
|
+
export declare function libraryImportWarning(found: UnresolvedLibraryImports): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Adds the library import warning of a scan to its result: one entry in
|
|
23
|
+
* `warnings` (after the existing ones), `unresolvedLibraryImports` and one
|
|
24
|
+
* `Warning:` line in the summary. Returns the result unchanged when every
|
|
25
|
+
* library import resolved or nothing was checked (a cancelled worker run).
|
|
26
|
+
*/
|
|
27
|
+
export declare function withLibraryImportWarning<T extends {
|
|
28
|
+
summary: string;
|
|
29
|
+
warnings?: string[];
|
|
30
|
+
}>(result: T, found: UnresolvedLibraryImports | undefined): T & {
|
|
31
|
+
unresolvedLibraryImports?: UnresolvedLibraryImports;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=library-import-warning.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Warning about unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts, warning text and the result helper of the library import check
|
|
5
|
+
* (`library-imports.ts`). Kept apart from the check so the scan tools can
|
|
6
|
+
* add the warning without loading ts-morph (their unit tests mock `node:fs`).
|
|
7
|
+
*/
|
|
8
|
+
/** Package names listed in the warning. */
|
|
9
|
+
export const EXAMPLE_PACKAGES = 5;
|
|
10
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
11
|
+
export function libraryImportWarning(found) {
|
|
12
|
+
if (found.imports === 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const more = found.packages > found.examples.length ? ', ...' : '';
|
|
16
|
+
return (`${found.imports} library import(s) from ${found.packages} package(s) do not resolve ` +
|
|
17
|
+
`(${found.examples.join(', ')}${more}); is node_modules missing or incomplete? ` +
|
|
18
|
+
'Results that depend on library types (dialogs, subscriptions, injected services) can be incomplete.');
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Adds the library import warning of a scan to its result: one entry in
|
|
22
|
+
* `warnings` (after the existing ones), `unresolvedLibraryImports` and one
|
|
23
|
+
* `Warning:` line in the summary. Returns the result unchanged when every
|
|
24
|
+
* library import resolved or nothing was checked (a cancelled worker run).
|
|
25
|
+
*/
|
|
26
|
+
export function withLibraryImportWarning(result, found) {
|
|
27
|
+
const warning = found === undefined ? undefined : libraryImportWarning(found);
|
|
28
|
+
if (found === undefined || warning === undefined) {
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
...result,
|
|
33
|
+
warnings: [...(result.warnings ?? []), warning],
|
|
34
|
+
unresolvedLibraryImports: found,
|
|
35
|
+
summary: `${result.summary}\nWarning: ${warning}`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=library-import-warning.js.map
|
|
@@ -25,18 +25,9 @@
|
|
|
25
25
|
* JavaScript such as `moment/locale/de-at` have no types to resolve). No
|
|
26
26
|
* program is created.
|
|
27
27
|
*/
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
export
|
|
31
|
-
/** Import and `export ... from` declarations with an unresolved library specifier. */
|
|
32
|
-
imports: number;
|
|
33
|
-
/** Distinct packages among them (`@scope/name` or `name`). */
|
|
34
|
-
packages: number;
|
|
35
|
-
/** Up to {@link EXAMPLE_PACKAGES} package names, most imported first. */
|
|
36
|
-
examples: string[];
|
|
37
|
-
}
|
|
38
|
-
/** Package names listed in the warning. */
|
|
39
|
-
export declare const EXAMPLE_PACKAGES = 5;
|
|
28
|
+
import { Project, type FileSystemHost } from 'ts-morph';
|
|
29
|
+
import { type UnresolvedLibraryImports } from './library-import-warning.js';
|
|
30
|
+
export { EXAMPLE_PACKAGES, libraryImportWarning, withLibraryImportWarning, type UnresolvedLibraryImports, } from './library-import-warning.js';
|
|
40
31
|
/** `@scope/name/sub` -> `@scope/name`, `name/sub` -> `name`. */
|
|
41
32
|
export declare function packageName(specifier: string): string;
|
|
42
33
|
/**
|
|
@@ -52,6 +43,39 @@ export declare function declaredPackages(fs: FileSystemHost, dir: string): Set<s
|
|
|
52
43
|
* declared packages is looked up from its directory upwards.
|
|
53
44
|
*/
|
|
54
45
|
export declare function findUnresolvedLibraryImports(project: Project, tsConfigPath: string): UnresolvedLibraryImports;
|
|
55
|
-
/**
|
|
56
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Like {@link findUnresolvedLibraryImports}, for files that are not (all)
|
|
48
|
+
* in the project: the scans hold only a batch of their scope at a time and
|
|
49
|
+
* none on a warm run. Each file is read and scanned for its imports without
|
|
50
|
+
* a parse; besides import and `export ... from` declarations this also
|
|
51
|
+
* counts `import x = require(...)` and dynamic `import(...)` of a library.
|
|
52
|
+
* Files that cannot be read are skipped; the specifiers of a file are
|
|
53
|
+
* remembered per process until its mtime or size changes.
|
|
54
|
+
*
|
|
55
|
+
* @param project - Gives compiler options, module resolution host and file
|
|
56
|
+
* system of the tsconfig; its source files are not read.
|
|
57
|
+
* @param tsConfigPath - As in {@link findUnresolvedLibraryImports}.
|
|
58
|
+
* @param filePaths - Absolute paths of the files to check.
|
|
59
|
+
*/
|
|
60
|
+
export declare function findUnresolvedLibraryImportsInFiles(project: Project, tsConfigPath: string, filePaths: Iterable<string>): UnresolvedLibraryImports;
|
|
61
|
+
/** Library imports of a scan scope, see {@link checkScanScope}. */
|
|
62
|
+
export interface ScanScopeLibraryImports {
|
|
63
|
+
/** Counts and examples for the warning. */
|
|
64
|
+
unresolved: UnresolvedLibraryImports;
|
|
65
|
+
/** Every package with an unresolved import, sorted; empty when all resolve. */
|
|
66
|
+
packages: string[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Library imports of a scan scope that do not resolve, checked before the
|
|
70
|
+
* scan reads its cache: the packages go into the cache version, so entries
|
|
71
|
+
* written while node_modules was missing or incomplete are not served once
|
|
72
|
+
* it is complete (and the other way round). Runs on the calling thread and
|
|
73
|
+
* yields to the event loop every {@link FILES_PER_TURN} files; repeated
|
|
74
|
+
* calls only stat unchanged files (see {@link findUnresolvedLibraryImportsInFiles}).
|
|
75
|
+
*
|
|
76
|
+
* @param tsConfigPath - tsconfig of the scan; gives compiler options and
|
|
77
|
+
* the `package.json` with the declared packages.
|
|
78
|
+
* @param filePaths - Absolute paths of the scan scope.
|
|
79
|
+
*/
|
|
80
|
+
export declare function checkScanScope(tsConfigPath: string, filePaths: readonly string[]): Promise<ScanScopeLibraryImports>;
|
|
57
81
|
//# sourceMappingURL=library-imports.d.ts.map
|