@angular-modernizer/adapter-mcp 0.3.0 → 1.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/README.md +181 -282
- package/dist/cli.js +21 -13
- package/dist/core/project-analyzer.d.ts +3 -12
- package/dist/core/project-analyzer.js +3 -12
- package/dist/index.d.ts +122 -6
- package/dist/index.js +49 -5
- package/dist/mcp-watcher.d.ts +32 -7
- package/dist/mcp-watcher.js +16 -15
- package/dist/scan-host/scan-host.d.ts +119 -0
- package/dist/scan-host/scan-host.js +376 -0
- package/dist/scan-host/scan-protocol.d.ts +35 -0
- package/dist/scan-host/scan-protocol.js +6 -0
- package/dist/scan-host/scan-worker.d.ts +14 -0
- package/dist/scan-host/scan-worker.js +48 -0
- package/dist/server/limited-stdio-transport.d.ts +75 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +20 -18
- package/dist/server/mcp-server.js +42 -79
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +71 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/tool-registry.d.ts +6 -9
- package/dist/server/tool-registry.js +6 -12
- package/dist/streaming/progress-store.d.ts +22 -5
- package/dist/streaming/progress-store.js +9 -5
- package/dist/tools/analyze-build-impact.d.ts +276 -35
- package/dist/tools/analyze-build-impact.js +175 -28
- package/dist/tools/analyze-core-to-shared.d.ts +176 -16
- package/dist/tools/analyze-core-to-shared.js +124 -19
- package/dist/tools/analyze-parser-performance.d.ts +209 -15
- package/dist/tools/analyze-parser-performance.js +119 -56
- package/dist/tools/analyze-project.d.ts +349 -17
- package/dist/tools/analyze-project.js +282 -97
- package/dist/tools/check-incremental-compatibility.d.ts +74 -12
- package/dist/tools/check-incremental-compatibility.js +69 -10
- package/dist/tools/collect-feedback.d.ts +225 -21
- package/dist/tools/collect-feedback.js +199 -118
- package/dist/tools/compare-health.d.ts +413 -0
- package/dist/tools/compare-health.js +479 -0
- package/dist/tools/extract-libraries.d.ts +200 -24
- package/dist/tools/extract-libraries.js +131 -27
- package/dist/tools/find-angular-symbol.d.ts +92 -24
- package/dist/tools/find-angular-symbol.js +70 -20
- package/dist/tools/find-component-hosts.d.ts +603 -27
- package/dist/tools/find-component-hosts.js +223 -19
- package/dist/tools/find-usages.d.ts +102 -22
- package/dist/tools/find-usages.js +81 -21
- package/dist/tools/get-bootstrap-execution.d.ts +183 -25
- package/dist/tools/get-bootstrap-execution.js +109 -25
- package/dist/tools/get-call-graph.d.ts +127 -12
- package/dist/tools/get-call-graph.js +84 -19
- package/dist/tools/get-operation-progress-tool.d.ts +126 -8
- package/dist/tools/get-operation-progress-tool.js +124 -12
- package/dist/tools/get-operation-progress.d.ts +27 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +182 -0
- package/dist/tools/helpers/analysis-output.js +165 -0
- package/dist/tools/helpers/batch-kernel.d.ts +14 -0
- package/dist/tools/helpers/batch-kernel.js +12 -0
- package/dist/tools/helpers/build-schemas.d.ts +36 -0
- package/dist/tools/helpers/build-schemas.js +23 -0
- package/dist/tools/helpers/citation-file-source.d.ts +10 -0
- package/dist/tools/helpers/citation-file-source.js +82 -0
- package/dist/tools/helpers/compact-output.d.ts +2 -1
- package/dist/tools/helpers/compact-output.js +2 -1
- package/dist/tools/helpers/finding-window.d.ts +43 -0
- package/dist/tools/helpers/finding-window.js +64 -0
- package/dist/tools/helpers/health-delta.d.ts +99 -0
- package/dist/tools/helpers/health-delta.js +236 -0
- package/dist/tools/helpers/investigation-schemas.d.ts +93 -0
- package/dist/tools/helpers/investigation-schemas.js +48 -0
- package/dist/tools/helpers/library-imports.d.ts +57 -0
- package/dist/tools/helpers/library-imports.js +151 -0
- package/dist/tools/helpers/load-source-files.d.ts +30 -0
- package/dist/tools/helpers/load-source-files.js +34 -0
- package/dist/tools/helpers/output-contract.d.ts +32 -0
- package/dist/tools/helpers/output-contract.js +32 -0
- package/dist/tools/helpers/platform-root-resolver.d.ts +55 -25
- package/dist/tools/helpers/platform-root-resolver.js +75 -48
- package/dist/tools/helpers/process-output.d.ts +19 -0
- package/dist/tools/helpers/process-output.js +31 -0
- package/dist/tools/helpers/project-cache.d.ts +60 -37
- package/dist/tools/helpers/project-cache.js +54 -37
- package/dist/tools/helpers/project-decorators.d.ts +14 -0
- package/dist/tools/helpers/project-decorators.js +22 -0
- package/dist/tools/helpers/rule-matcher.js +5 -0
- package/dist/tools/helpers/rule-runner.d.ts +25 -13
- package/dist/tools/helpers/rule-runner.js +45 -24
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-engine.d.ts +107 -0
- package/dist/tools/helpers/scan-engine.js +197 -0
- package/dist/tools/helpers/scan-plan.d.ts +5 -2
- package/dist/tools/helpers/scan-plan.js +18 -3
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/suggestion-generator.d.ts +9 -13
- package/dist/tools/helpers/suggestion-generator.js +0 -12
- package/dist/tools/helpers/tool-cache.d.ts +11 -0
- package/dist/tools/helpers/tool-cache.js +15 -0
- package/dist/tools/helpers/tool-context.d.ts +63 -0
- package/dist/tools/helpers/tool-context.js +79 -0
- package/dist/tools/helpers/transform-safety.d.ts +40 -0
- package/dist/tools/helpers/transform-safety.js +87 -0
- package/dist/tools/helpers/validation-output.d.ts +53 -0
- package/dist/tools/helpers/validation-output.js +48 -0
- package/dist/tools/inspect-form-group.d.ts +262 -24
- package/dist/tools/inspect-form-group.js +134 -13
- package/dist/tools/inspect-i18n.d.ts +410 -23
- package/dist/tools/inspect-i18n.js +213 -13
- package/dist/tools/inspect-template.d.ts +260 -22
- package/dist/tools/inspect-template.js +174 -13
- package/dist/tools/learn-patterns.d.ts +210 -13
- package/dist/tools/learn-patterns.js +113 -12
- package/dist/tools/list-imports.d.ts +152 -34
- package/dist/tools/list-imports.js +124 -18
- package/dist/tools/orchestrate-migration.d.ts +159 -14
- package/dist/tools/orchestrate-migration.js +147 -20
- package/dist/tools/parse-stack-trace.d.ts +78 -21
- package/dist/tools/parse-stack-trace.js +44 -7
- package/dist/tools/plan-migration.d.ts +395 -26
- package/dist/tools/plan-migration.js +173 -22
- package/dist/tools/resolve-type.d.ts +57 -9
- package/dist/tools/resolve-type.js +49 -12
- package/dist/tools/review-feedback.d.ts +214 -16
- package/dist/tools/review-feedback.js +142 -57
- package/dist/tools/rollback-changes.d.ts +88 -7
- package/dist/tools/rollback-changes.js +74 -19
- package/dist/tools/run-angular-cli.d.ts +57 -12
- package/dist/tools/run-angular-cli.js +76 -13
- package/dist/tools/run-build.d.ts +127 -13
- package/dist/tools/run-build.js +128 -16
- package/dist/tools/run-schematic.d.ts +82 -12
- package/dist/tools/run-schematic.js +115 -18
- package/dist/tools/scan-all.d.ts +88 -23
- package/dist/tools/scan-all.js +161 -220
- package/dist/tools/scan-angular.d.ts +60 -19
- package/dist/tools/scan-angular.js +100 -141
- package/dist/tools/scan-architecture.d.ts +92 -24
- package/dist/tools/scan-architecture.js +268 -211
- package/dist/tools/scan-solid.d.ts +59 -19
- package/dist/tools/scan-solid.js +98 -139
- package/dist/tools/search-codebase.d.ts +110 -23
- package/dist/tools/search-codebase.js +67 -11
- package/dist/tools/server-status.d.ts +392 -26
- package/dist/tools/server-status.js +260 -27
- package/dist/tools/suggest-improvements.d.ts +105 -10
- package/dist/tools/suggest-improvements.js +91 -51
- package/dist/tools/trace-output-flow.d.ts +713 -26
- package/dist/tools/trace-output-flow.js +396 -33
- package/dist/tools/transform-code-batch.d.ts +3 -0
- package/dist/tools/transform-code-batch.js +10 -5
- package/dist/tools/transform-code.d.ts +402 -18
- package/dist/tools/transform-code.js +708 -649
- package/dist/tools/validate-before-transform.d.ts +136 -7
- package/dist/tools/validate-before-transform.js +65 -9
- package/dist/tools/validate-project-compatibility.d.ts +82 -15
- package/dist/tools/validate-project-compatibility.js +84 -15
- package/dist/tools/validate-transformation.d.ts +243 -8
- package/dist/tools/validate-transformation.js +127 -23
- package/dist/tools/verify-citations.d.ts +202 -0
- package/dist/tools/verify-citations.js +221 -0
- package/dist/types.d.ts +78 -11
- package/dist/types.js +0 -5
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +31 -20
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/core/project-analyzer.d.ts.map +0 -1
- package/dist/core/project-analyzer.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mcp-watcher.d.ts.map +0 -1
- package/dist/mcp-watcher.js.map +0 -1
- package/dist/server/json-rpc-handler.d.ts +0 -98
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -301
- package/dist/server/json-rpc-handler.js.map +0 -1
- package/dist/server/mcp-server.d.ts.map +0 -1
- package/dist/server/mcp-server.js.map +0 -1
- package/dist/server/stdio-guard.d.ts.map +0 -1
- package/dist/server/stdio-guard.js.map +0 -1
- package/dist/server/tool-registry.d.ts.map +0 -1
- package/dist/server/tool-registry.js.map +0 -1
- package/dist/streaming/progress-store.d.ts.map +0 -1
- package/dist/streaming/progress-store.js.map +0 -1
- package/dist/tools/analyze-build-impact.d.ts.map +0 -1
- package/dist/tools/analyze-build-impact.js.map +0 -1
- package/dist/tools/analyze-core-to-shared.d.ts.map +0 -1
- package/dist/tools/analyze-core-to-shared.js.map +0 -1
- package/dist/tools/analyze-parser-performance.d.ts.map +0 -1
- package/dist/tools/analyze-parser-performance.js.map +0 -1
- package/dist/tools/analyze-project.d.ts.map +0 -1
- package/dist/tools/analyze-project.js.map +0 -1
- package/dist/tools/check-incremental-compatibility.d.ts.map +0 -1
- package/dist/tools/check-incremental-compatibility.js.map +0 -1
- package/dist/tools/collect-feedback.d.ts.map +0 -1
- package/dist/tools/collect-feedback.js.map +0 -1
- package/dist/tools/extract-libraries.d.ts.map +0 -1
- package/dist/tools/extract-libraries.js.map +0 -1
- package/dist/tools/find-angular-symbol.d.ts.map +0 -1
- package/dist/tools/find-angular-symbol.js.map +0 -1
- package/dist/tools/find-component-hosts.d.ts.map +0 -1
- package/dist/tools/find-component-hosts.js.map +0 -1
- package/dist/tools/find-usages.d.ts.map +0 -1
- package/dist/tools/find-usages.js.map +0 -1
- package/dist/tools/get-bootstrap-execution.d.ts.map +0 -1
- package/dist/tools/get-bootstrap-execution.js.map +0 -1
- package/dist/tools/get-call-graph.d.ts.map +0 -1
- package/dist/tools/get-call-graph.js.map +0 -1
- package/dist/tools/get-operation-progress-tool.d.ts.map +0 -1
- package/dist/tools/get-operation-progress-tool.js.map +0 -1
- package/dist/tools/get-operation-progress.d.ts.map +0 -1
- package/dist/tools/get-operation-progress.js.map +0 -1
- package/dist/tools/helpers/compact-output.d.ts.map +0 -1
- package/dist/tools/helpers/compact-output.js.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.d.ts.map +0 -1
- package/dist/tools/helpers/feedback-analyzer.js.map +0 -1
- package/dist/tools/helpers/find-ts-config.d.ts.map +0 -1
- package/dist/tools/helpers/find-ts-config.js.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.d.ts.map +0 -1
- package/dist/tools/helpers/platform-root-resolver.js.map +0 -1
- package/dist/tools/helpers/project-cache.d.ts.map +0 -1
- package/dist/tools/helpers/project-cache.js.map +0 -1
- package/dist/tools/helpers/rule-matcher.d.ts.map +0 -1
- package/dist/tools/helpers/rule-matcher.js.map +0 -1
- package/dist/tools/helpers/rule-runner.d.ts.map +0 -1
- package/dist/tools/helpers/rule-runner.js.map +0 -1
- package/dist/tools/helpers/scan-plan.d.ts.map +0 -1
- package/dist/tools/helpers/scan-plan.js.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.d.ts.map +0 -1
- package/dist/tools/helpers/stack-frame-file-index.js.map +0 -1
- package/dist/tools/helpers/suggestion-generator.d.ts.map +0 -1
- package/dist/tools/helpers/suggestion-generator.js.map +0 -1
- package/dist/tools/inspect-form-group.d.ts.map +0 -1
- package/dist/tools/inspect-form-group.js.map +0 -1
- package/dist/tools/inspect-i18n.d.ts.map +0 -1
- package/dist/tools/inspect-i18n.js.map +0 -1
- package/dist/tools/inspect-template.d.ts.map +0 -1
- package/dist/tools/inspect-template.js.map +0 -1
- package/dist/tools/learn-patterns.d.ts.map +0 -1
- package/dist/tools/learn-patterns.js.map +0 -1
- package/dist/tools/list-imports.d.ts.map +0 -1
- package/dist/tools/list-imports.js.map +0 -1
- package/dist/tools/orchestrate-migration.d.ts.map +0 -1
- package/dist/tools/orchestrate-migration.js.map +0 -1
- package/dist/tools/parse-stack-trace.d.ts.map +0 -1
- package/dist/tools/parse-stack-trace.js.map +0 -1
- package/dist/tools/plan-migration.d.ts.map +0 -1
- package/dist/tools/plan-migration.js.map +0 -1
- package/dist/tools/resolve-type.d.ts.map +0 -1
- package/dist/tools/resolve-type.js.map +0 -1
- package/dist/tools/review-feedback.d.ts.map +0 -1
- package/dist/tools/review-feedback.js.map +0 -1
- package/dist/tools/rollback-changes.d.ts.map +0 -1
- package/dist/tools/rollback-changes.js.map +0 -1
- package/dist/tools/run-angular-cli.d.ts.map +0 -1
- package/dist/tools/run-angular-cli.js.map +0 -1
- package/dist/tools/run-build.d.ts.map +0 -1
- package/dist/tools/run-build.js.map +0 -1
- package/dist/tools/run-schematic.d.ts.map +0 -1
- package/dist/tools/run-schematic.js.map +0 -1
- package/dist/tools/scan-all.d.ts.map +0 -1
- package/dist/tools/scan-all.js.map +0 -1
- package/dist/tools/scan-angular.d.ts.map +0 -1
- package/dist/tools/scan-angular.js.map +0 -1
- package/dist/tools/scan-architecture.d.ts.map +0 -1
- package/dist/tools/scan-architecture.js.map +0 -1
- package/dist/tools/scan-solid.d.ts.map +0 -1
- package/dist/tools/scan-solid.js.map +0 -1
- package/dist/tools/search-codebase.d.ts.map +0 -1
- package/dist/tools/search-codebase.js.map +0 -1
- package/dist/tools/server-status.d.ts.map +0 -1
- package/dist/tools/server-status.js.map +0 -1
- package/dist/tools/shared/scan-types.d.ts +0 -200
- package/dist/tools/shared/scan-types.d.ts.map +0 -1
- package/dist/tools/shared/scan-types.js +0 -7
- package/dist/tools/shared/scan-types.js.map +0 -1
- package/dist/tools/suggest-improvements.d.ts.map +0 -1
- package/dist/tools/suggest-improvements.js.map +0 -1
- package/dist/tools/trace-output-flow.d.ts.map +0 -1
- package/dist/tools/trace-output-flow.js.map +0 -1
- package/dist/tools/transform-code-batch.d.ts.map +0 -1
- package/dist/tools/transform-code-batch.js.map +0 -1
- package/dist/tools/transform-code.d.ts.map +0 -1
- package/dist/tools/transform-code.js.map +0 -1
- package/dist/tools/validate-before-transform.d.ts.map +0 -1
- package/dist/tools/validate-before-transform.js.map +0 -1
- package/dist/tools/validate-project-compatibility.d.ts.map +0 -1
- package/dist/tools/validate-project-compatibility.js.map +0 -1
- package/dist/tools/validate-transformation.d.ts.map +0 -1
- package/dist/tools/validate-transformation.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/format-tool-response.d.ts.map +0 -1
- package/dist/utils/format-tool-response.js.map +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/** One violation as stored in a snapshot and reported in a delta. */
|
|
2
|
+
export interface HealthViolation {
|
|
3
|
+
/** Rule that reported the violation. */
|
|
4
|
+
ruleId: string;
|
|
5
|
+
/** Relative to the project root. */
|
|
6
|
+
filePath: string;
|
|
7
|
+
/** Rule message. */
|
|
8
|
+
message: string;
|
|
9
|
+
/** Severity of the violation. */
|
|
10
|
+
severity: string;
|
|
11
|
+
/** Rule category. */
|
|
12
|
+
category: string;
|
|
13
|
+
/** 1-based line, when the rule reports one. */
|
|
14
|
+
line?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Scan arguments that change which violations a run can find. */
|
|
17
|
+
export interface HealthScope {
|
|
18
|
+
rules: string[] | null;
|
|
19
|
+
includePatterns: string[] | null;
|
|
20
|
+
excludePatterns: string[] | null;
|
|
21
|
+
}
|
|
22
|
+
/** Content of the snapshot file. */
|
|
23
|
+
export interface HealthSnapshot {
|
|
24
|
+
version: typeof HEALTH_SNAPSHOT_VERSION;
|
|
25
|
+
createdAt: string;
|
|
26
|
+
scope: HealthScope;
|
|
27
|
+
rulesExecuted: string[];
|
|
28
|
+
analyzedFiles: number;
|
|
29
|
+
violations: HealthViolation[];
|
|
30
|
+
}
|
|
31
|
+
/** Counts of one rule in the previous and the current run. */
|
|
32
|
+
export interface RuleDelta {
|
|
33
|
+
/** Rule id. */
|
|
34
|
+
ruleId: string;
|
|
35
|
+
/** Violations of the rule in the previous run. */
|
|
36
|
+
previous: number;
|
|
37
|
+
/** Violations of the rule in the current run. */
|
|
38
|
+
current: number;
|
|
39
|
+
/** Violations only in the current run. */
|
|
40
|
+
new: number;
|
|
41
|
+
/** Violations only in the previous run. */
|
|
42
|
+
fixed: number;
|
|
43
|
+
/** Violations in both runs. */
|
|
44
|
+
unchanged: number;
|
|
45
|
+
}
|
|
46
|
+
/** Counts of one file whose violations changed. */
|
|
47
|
+
export interface FileDelta {
|
|
48
|
+
/** Relative to the project root. */
|
|
49
|
+
filePath: string;
|
|
50
|
+
/** Violations in the file in the previous run. */
|
|
51
|
+
previous: number;
|
|
52
|
+
/** Violations in the file in the current run. */
|
|
53
|
+
current: number;
|
|
54
|
+
/** Violations only in the current run. */
|
|
55
|
+
new: number;
|
|
56
|
+
/** Violations only in the previous run. */
|
|
57
|
+
fixed: number;
|
|
58
|
+
}
|
|
59
|
+
/** Result of comparing two runs. */
|
|
60
|
+
export interface HealthDelta {
|
|
61
|
+
newViolations: HealthViolation[];
|
|
62
|
+
fixedViolations: HealthViolation[];
|
|
63
|
+
unchanged: number;
|
|
64
|
+
/** Every rule with violations in either run. */
|
|
65
|
+
byRule: RuleDelta[];
|
|
66
|
+
/** Only files with new or fixed violations. */
|
|
67
|
+
byFile: FileDelta[];
|
|
68
|
+
}
|
|
69
|
+
export declare const HEALTH_SNAPSHOT_VERSION = 1;
|
|
70
|
+
/** Snapshot location relative to the project root, next to the scan cache. */
|
|
71
|
+
export declare const DEFAULT_HEALTH_SNAPSHOT_PATH = ".angular-modernizer-cache/health/last-run.json";
|
|
72
|
+
/** Message without digits and repeated whitespace, used as matching key. */
|
|
73
|
+
export declare function normalizeMessage(message: string): string;
|
|
74
|
+
/** Orders violations by file, line and rule. */
|
|
75
|
+
export declare function compareViolations(a: HealthViolation, b: HealthViolation): number;
|
|
76
|
+
/** Snapshot file content: one line per file with violations. */
|
|
77
|
+
export declare function serializeHealthSnapshot(snapshot: HealthSnapshot): string;
|
|
78
|
+
/**
|
|
79
|
+
* Reads snapshot file content.
|
|
80
|
+
*
|
|
81
|
+
* @returns the snapshot, or `undefined` when the text is not JSON, has another
|
|
82
|
+
* version or misses required fields.
|
|
83
|
+
*/
|
|
84
|
+
export declare function parseHealthSnapshot(text: string): HealthSnapshot | undefined;
|
|
85
|
+
/** Readable differences between two scopes; empty when they match. */
|
|
86
|
+
export declare function scopeDifferences(previous: HealthScope, current: HealthScope): string[];
|
|
87
|
+
/**
|
|
88
|
+
* Compares the violations of the previous run with the current one: which
|
|
89
|
+
* violations are new, fixed or unchanged.
|
|
90
|
+
*
|
|
91
|
+
* @remarks
|
|
92
|
+
* Line numbers shift with every edit above a finding, so they are not part of
|
|
93
|
+
* the key. Within one rule and file, violations are matched first by their
|
|
94
|
+
* message with digits removed (counts inside messages change too), the rest
|
|
95
|
+
* by number: three findings before and two now means one fixed. Which of the
|
|
96
|
+
* unmatched ones is reported as fixed or new follows the line order.
|
|
97
|
+
*/
|
|
98
|
+
export declare function compareHealth(previous: readonly HealthViolation[], current: readonly HealthViolation[]): HealthDelta;
|
|
99
|
+
//# sourceMappingURL=health-delta.d.ts.map
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
export const HEALTH_SNAPSHOT_VERSION = 1;
|
|
2
|
+
/** Snapshot location relative to the project root, next to the scan cache. */
|
|
3
|
+
export const DEFAULT_HEALTH_SNAPSHOT_PATH = '.angular-modernizer-cache/health/last-run.json';
|
|
4
|
+
/** Message without digits and repeated whitespace, used as matching key. */
|
|
5
|
+
export function normalizeMessage(message) {
|
|
6
|
+
return message.replace(/\d+/g, '#').replace(/\s+/g, ' ').trim();
|
|
7
|
+
}
|
|
8
|
+
/** Orders violations by file, line and rule. */
|
|
9
|
+
export function compareViolations(a, b) {
|
|
10
|
+
return (a.filePath.localeCompare(b.filePath) ||
|
|
11
|
+
(a.line ?? 0) - (b.line ?? 0) ||
|
|
12
|
+
a.ruleId.localeCompare(b.ruleId));
|
|
13
|
+
}
|
|
14
|
+
/** Snapshot file content: one line per file with violations. */
|
|
15
|
+
export function serializeHealthSnapshot(snapshot) {
|
|
16
|
+
const files = new Map();
|
|
17
|
+
for (const v of snapshot.violations) {
|
|
18
|
+
const stored = [
|
|
19
|
+
v.ruleId,
|
|
20
|
+
v.line ?? null,
|
|
21
|
+
v.severity,
|
|
22
|
+
v.category,
|
|
23
|
+
v.message,
|
|
24
|
+
];
|
|
25
|
+
pushTo(files, v.filePath, stored);
|
|
26
|
+
}
|
|
27
|
+
const header = JSON.stringify({
|
|
28
|
+
version: snapshot.version,
|
|
29
|
+
createdAt: snapshot.createdAt,
|
|
30
|
+
scope: snapshot.scope,
|
|
31
|
+
rulesExecuted: snapshot.rulesExecuted,
|
|
32
|
+
analyzedFiles: snapshot.analyzedFiles,
|
|
33
|
+
totalViolations: snapshot.violations.length,
|
|
34
|
+
});
|
|
35
|
+
const lines = [...files].map(([file, list]) => `${JSON.stringify(file)}:${JSON.stringify(list)}`);
|
|
36
|
+
return `${header.slice(0, -1)},"files":{\n${lines.join(',\n')}\n}}\n`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Reads snapshot file content.
|
|
40
|
+
*
|
|
41
|
+
* @returns the snapshot, or `undefined` when the text is not JSON, has another
|
|
42
|
+
* version or misses required fields.
|
|
43
|
+
*/
|
|
44
|
+
export function parseHealthSnapshot(text) {
|
|
45
|
+
let data;
|
|
46
|
+
try {
|
|
47
|
+
data = JSON.parse(text);
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
if (!isRecord(data) || data['version'] !== HEALTH_SNAPSHOT_VERSION) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const { createdAt, scope, rulesExecuted, analyzedFiles, files } = data;
|
|
56
|
+
const valid = typeof createdAt === 'string' &&
|
|
57
|
+
isScope(scope) &&
|
|
58
|
+
isStringArray(rulesExecuted) &&
|
|
59
|
+
typeof analyzedFiles === 'number' &&
|
|
60
|
+
isRecord(files);
|
|
61
|
+
if (!valid) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const violations = [];
|
|
65
|
+
for (const [filePath, list] of Object.entries(files)) {
|
|
66
|
+
if (!Array.isArray(list) || !list.every(isStoredViolation)) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
for (const [ruleId, line, severity, category, message] of list) {
|
|
70
|
+
violations.push({
|
|
71
|
+
ruleId,
|
|
72
|
+
filePath,
|
|
73
|
+
message,
|
|
74
|
+
severity,
|
|
75
|
+
category,
|
|
76
|
+
...(line === null ? {} : { line }),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
version: HEALTH_SNAPSHOT_VERSION,
|
|
82
|
+
createdAt,
|
|
83
|
+
scope,
|
|
84
|
+
rulesExecuted,
|
|
85
|
+
analyzedFiles,
|
|
86
|
+
violations,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Readable differences between two scopes; empty when they match. */
|
|
90
|
+
export function scopeDifferences(previous, current) {
|
|
91
|
+
const keys = ['rules', 'includePatterns', 'excludePatterns'];
|
|
92
|
+
return keys
|
|
93
|
+
.filter((key) => !sameList(previous[key], current[key]))
|
|
94
|
+
.map((key) => `${key}: ${describeList(previous[key])} -> ${describeList(current[key])}`);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Compares the violations of the previous run with the current one: which
|
|
98
|
+
* violations are new, fixed or unchanged.
|
|
99
|
+
*
|
|
100
|
+
* @remarks
|
|
101
|
+
* Line numbers shift with every edit above a finding, so they are not part of
|
|
102
|
+
* the key. Within one rule and file, violations are matched first by their
|
|
103
|
+
* message with digits removed (counts inside messages change too), the rest
|
|
104
|
+
* by number: three findings before and two now means one fixed. Which of the
|
|
105
|
+
* unmatched ones is reported as fixed or new follows the line order.
|
|
106
|
+
*/
|
|
107
|
+
export function compareHealth(previous, current) {
|
|
108
|
+
const previousGroups = groupByRuleAndFile(previous);
|
|
109
|
+
const currentGroups = groupByRuleAndFile(current);
|
|
110
|
+
const keys = new Set([...previousGroups.keys(), ...currentGroups.keys()]);
|
|
111
|
+
const newViolations = [];
|
|
112
|
+
const fixedViolations = [];
|
|
113
|
+
const rules = new Map();
|
|
114
|
+
const files = new Map();
|
|
115
|
+
let unchanged = 0;
|
|
116
|
+
for (const key of keys) {
|
|
117
|
+
const before = previousGroups.get(key) ?? [];
|
|
118
|
+
const after = currentGroups.get(key) ?? [];
|
|
119
|
+
const match = matchGroup(before, after);
|
|
120
|
+
newViolations.push(...match.added);
|
|
121
|
+
fixedViolations.push(...match.removed);
|
|
122
|
+
unchanged += match.unchanged;
|
|
123
|
+
const sample = after[0] ?? before[0];
|
|
124
|
+
if (sample === undefined) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const rule = rules.get(sample.ruleId) ?? emptyRule(sample.ruleId);
|
|
128
|
+
rule.previous += before.length;
|
|
129
|
+
rule.current += after.length;
|
|
130
|
+
rule.new += match.added.length;
|
|
131
|
+
rule.fixed += match.removed.length;
|
|
132
|
+
rule.unchanged += match.unchanged;
|
|
133
|
+
rules.set(sample.ruleId, rule);
|
|
134
|
+
const file = files.get(sample.filePath) ?? emptyFile(sample.filePath);
|
|
135
|
+
file.previous += before.length;
|
|
136
|
+
file.current += after.length;
|
|
137
|
+
file.new += match.added.length;
|
|
138
|
+
file.fixed += match.removed.length;
|
|
139
|
+
files.set(sample.filePath, file);
|
|
140
|
+
}
|
|
141
|
+
const changes = (d) => d.new + d.fixed;
|
|
142
|
+
return {
|
|
143
|
+
newViolations: newViolations.sort(compareViolations),
|
|
144
|
+
fixedViolations: fixedViolations.sort(compareViolations),
|
|
145
|
+
unchanged,
|
|
146
|
+
byRule: [...rules.values()].sort((a, b) => changes(b) - changes(a) ||
|
|
147
|
+
b.current - a.current ||
|
|
148
|
+
a.ruleId.localeCompare(b.ruleId)),
|
|
149
|
+
byFile: [...files.values()]
|
|
150
|
+
.filter((f) => changes(f) > 0)
|
|
151
|
+
.sort((a, b) => changes(b) - changes(a) || a.filePath.localeCompare(b.filePath)),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function matchGroup(before, after) {
|
|
155
|
+
const byMessage = new Map();
|
|
156
|
+
for (const v of [...before].sort(compareViolations)) {
|
|
157
|
+
pushTo(byMessage, normalizeMessage(v.message), v);
|
|
158
|
+
}
|
|
159
|
+
const unmatchedAfter = [];
|
|
160
|
+
for (const v of [...after].sort(compareViolations)) {
|
|
161
|
+
const candidates = byMessage.get(normalizeMessage(v.message));
|
|
162
|
+
if (candidates === undefined || candidates.length === 0) {
|
|
163
|
+
unmatchedAfter.push(v);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
candidates.shift();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const unmatchedBefore = [...byMessage.values()]
|
|
170
|
+
.flat()
|
|
171
|
+
.sort(compareViolations);
|
|
172
|
+
const paired = Math.min(unmatchedBefore.length, unmatchedAfter.length);
|
|
173
|
+
return {
|
|
174
|
+
added: unmatchedAfter.slice(paired),
|
|
175
|
+
removed: unmatchedBefore.slice(paired),
|
|
176
|
+
unchanged: after.length - (unmatchedAfter.length - paired),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function groupByRuleAndFile(violations) {
|
|
180
|
+
const groups = new Map();
|
|
181
|
+
for (const v of violations) {
|
|
182
|
+
pushTo(groups, `${v.ruleId}\u0000${v.filePath}`, v);
|
|
183
|
+
}
|
|
184
|
+
return groups;
|
|
185
|
+
}
|
|
186
|
+
function pushTo(map, key, value) {
|
|
187
|
+
const list = map.get(key);
|
|
188
|
+
if (list === undefined) {
|
|
189
|
+
map.set(key, [value]);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
list.push(value);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function emptyRule(ruleId) {
|
|
196
|
+
return { ruleId, previous: 0, current: 0, new: 0, fixed: 0, unchanged: 0 };
|
|
197
|
+
}
|
|
198
|
+
function emptyFile(filePath) {
|
|
199
|
+
return { filePath, previous: 0, current: 0, new: 0, fixed: 0 };
|
|
200
|
+
}
|
|
201
|
+
function sameList(a, b) {
|
|
202
|
+
if (a === null || b === null) {
|
|
203
|
+
return a === b;
|
|
204
|
+
}
|
|
205
|
+
const left = [...a].sort();
|
|
206
|
+
const right = [...b].sort();
|
|
207
|
+
return left.length === right.length && left.every((x, i) => x === right[i]);
|
|
208
|
+
}
|
|
209
|
+
function describeList(list) {
|
|
210
|
+
return list === null ? 'default' : `[${list.join(', ')}]`;
|
|
211
|
+
}
|
|
212
|
+
function isRecord(value) {
|
|
213
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
214
|
+
}
|
|
215
|
+
function isStringArray(value) {
|
|
216
|
+
return Array.isArray(value) && value.every((x) => typeof x === 'string');
|
|
217
|
+
}
|
|
218
|
+
function isListOrNull(value) {
|
|
219
|
+
return value === null || isStringArray(value);
|
|
220
|
+
}
|
|
221
|
+
function isScope(value) {
|
|
222
|
+
return (isRecord(value) &&
|
|
223
|
+
isListOrNull(value['rules']) &&
|
|
224
|
+
isListOrNull(value['includePatterns']) &&
|
|
225
|
+
isListOrNull(value['excludePatterns']));
|
|
226
|
+
}
|
|
227
|
+
function isStoredViolation(value) {
|
|
228
|
+
return (Array.isArray(value) &&
|
|
229
|
+
value.length === 5 &&
|
|
230
|
+
typeof value[0] === 'string' &&
|
|
231
|
+
(value[1] === null || typeof value[1] === 'number') &&
|
|
232
|
+
typeof value[2] === 'string' &&
|
|
233
|
+
typeof value[3] === 'string' &&
|
|
234
|
+
typeof value[4] === 'string');
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=health-delta.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Output schema parts of the investigation tools
|
|
3
|
+
*
|
|
4
|
+
* JSON Schema pieces for api result types that more than one tool returns
|
|
5
|
+
* (find-component-hosts and trace-output-flow share the dynamic host types).
|
|
6
|
+
* Objects stay open, see `output-contract.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const STRING_ARRAY: {
|
|
9
|
+
readonly type: "array";
|
|
10
|
+
readonly items: {
|
|
11
|
+
readonly type: "string";
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
/** `Record<string, number>`. */
|
|
15
|
+
export declare const COUNT_OBJECT: {
|
|
16
|
+
readonly type: "object";
|
|
17
|
+
readonly additionalProperties: {
|
|
18
|
+
readonly type: "integer";
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
/** Same-name classes the query also matched. */
|
|
22
|
+
export declare const ALTERNATIVES_SCHEMA: {
|
|
23
|
+
readonly type: "array";
|
|
24
|
+
readonly items: {
|
|
25
|
+
readonly type: "object";
|
|
26
|
+
readonly properties: {
|
|
27
|
+
readonly className: {
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
};
|
|
30
|
+
readonly file: {
|
|
31
|
+
readonly type: "string";
|
|
32
|
+
};
|
|
33
|
+
readonly selector: {
|
|
34
|
+
readonly type: "string";
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly required: readonly ["className", "file", "selector"];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
/** api `DynamicRoute`: a route entry that loads the component. */
|
|
41
|
+
export declare const DYNAMIC_ROUTE_SCHEMA: {
|
|
42
|
+
readonly type: "object";
|
|
43
|
+
readonly properties: {
|
|
44
|
+
readonly path: {
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
};
|
|
47
|
+
readonly lazy: {
|
|
48
|
+
readonly type: "boolean";
|
|
49
|
+
};
|
|
50
|
+
readonly guards: {
|
|
51
|
+
readonly type: "array";
|
|
52
|
+
readonly items: {
|
|
53
|
+
readonly type: "string";
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly data: {
|
|
57
|
+
readonly type: "string";
|
|
58
|
+
};
|
|
59
|
+
readonly resolve: {
|
|
60
|
+
readonly type: "array";
|
|
61
|
+
readonly items: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
readonly required: readonly ["path", "lazy", "guards"];
|
|
67
|
+
};
|
|
68
|
+
/** api `DynamicResultUse`: what the creating code does with the result. */
|
|
69
|
+
export declare const DYNAMIC_RESULT_USE_SCHEMA: {
|
|
70
|
+
readonly type: "object";
|
|
71
|
+
readonly properties: {
|
|
72
|
+
readonly use: {
|
|
73
|
+
readonly type: "string";
|
|
74
|
+
};
|
|
75
|
+
readonly chain: {
|
|
76
|
+
readonly type: "array";
|
|
77
|
+
readonly items: {
|
|
78
|
+
readonly type: "string";
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
readonly target: {
|
|
82
|
+
readonly type: "string";
|
|
83
|
+
};
|
|
84
|
+
readonly text: {
|
|
85
|
+
readonly type: "string";
|
|
86
|
+
};
|
|
87
|
+
readonly note: {
|
|
88
|
+
readonly type: "string";
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
readonly required: readonly ["use", "chain"];
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=investigation-schemas.d.ts.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Output schema parts of the investigation tools
|
|
3
|
+
*
|
|
4
|
+
* JSON Schema pieces for api result types that more than one tool returns
|
|
5
|
+
* (find-component-hosts and trace-output-flow share the dynamic host types).
|
|
6
|
+
* Objects stay open, see `output-contract.ts`.
|
|
7
|
+
*/
|
|
8
|
+
export const STRING_ARRAY = { type: 'array', items: { type: 'string' } };
|
|
9
|
+
/** `Record<string, number>`. */
|
|
10
|
+
export const COUNT_OBJECT = { type: 'object', additionalProperties: { type: 'integer' } };
|
|
11
|
+
/** Same-name classes the query also matched. */
|
|
12
|
+
export const ALTERNATIVES_SCHEMA = {
|
|
13
|
+
type: 'array',
|
|
14
|
+
items: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
className: { type: 'string' },
|
|
18
|
+
file: { type: 'string' },
|
|
19
|
+
selector: { type: 'string' },
|
|
20
|
+
},
|
|
21
|
+
required: ['className', 'file', 'selector'],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/** api `DynamicRoute`: a route entry that loads the component. */
|
|
25
|
+
export const DYNAMIC_ROUTE_SCHEMA = {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
path: { type: 'string' },
|
|
29
|
+
lazy: { type: 'boolean' },
|
|
30
|
+
guards: STRING_ARRAY,
|
|
31
|
+
data: { type: 'string' },
|
|
32
|
+
resolve: STRING_ARRAY,
|
|
33
|
+
},
|
|
34
|
+
required: ['path', 'lazy', 'guards'],
|
|
35
|
+
};
|
|
36
|
+
/** api `DynamicResultUse`: what the creating code does with the result. */
|
|
37
|
+
export const DYNAMIC_RESULT_USE_SCHEMA = {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
use: { type: 'string' },
|
|
41
|
+
chain: STRING_ARRAY,
|
|
42
|
+
target: { type: 'string' },
|
|
43
|
+
text: { type: 'string' },
|
|
44
|
+
note: { type: 'string' },
|
|
45
|
+
},
|
|
46
|
+
required: ['use', 'chain'],
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=investigation-schemas.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts the library imports of a ts-morph Project that do not resolve, so
|
|
5
|
+
* investigation tools can say when their answer may be incomplete.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Without a resolvable `node_modules` the program still loads, but every
|
|
9
|
+
* library type is `any`: dialogs opened through `MatDialog`, subscriptions on
|
|
10
|
+
* `EventEmitter`, injected framework services and the like are no longer
|
|
11
|
+
* recognised, and the tools return fewer results without any error. This
|
|
12
|
+
* check makes that visible.
|
|
13
|
+
*
|
|
14
|
+
* A library import is a bare module specifier whose package is declared in
|
|
15
|
+
* the nearest `package.json` above the tsconfig (dependencies,
|
|
16
|
+
* devDependencies, peerDependencies, optionalDependencies) and that does not
|
|
17
|
+
* match a tsconfig `paths` alias. Relative imports, broken aliases, aliases of
|
|
18
|
+
* other tsconfigs (`@testing/*` from a spec config) and Node builtins
|
|
19
|
+
* (ambient modules of `@types/node`, which the resolver does not find as
|
|
20
|
+
* files) are not a missing install and are not counted. Each distinct
|
|
21
|
+
* specifier is resolved once with the TypeScript module resolver against the
|
|
22
|
+
* project's compiler options and file system host, so in-memory projects work
|
|
23
|
+
* the same way; when that fails, a package folder in a `node_modules` above
|
|
24
|
+
* the importing file still counts as installed (side-effect imports of plain
|
|
25
|
+
* JavaScript such as `moment/locale/de-at` have no types to resolve). No
|
|
26
|
+
* program is created.
|
|
27
|
+
*/
|
|
28
|
+
import { type FileSystemHost, type Project } from 'ts-morph';
|
|
29
|
+
/** Library imports of a project that do not resolve. */
|
|
30
|
+
export interface UnresolvedLibraryImports {
|
|
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;
|
|
40
|
+
/** `@scope/name/sub` -> `@scope/name`, `name/sub` -> `name`. */
|
|
41
|
+
export declare function packageName(specifier: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Package names declared in the nearest `package.json` at or above `dir`;
|
|
44
|
+
* empty when there is none or it cannot be read.
|
|
45
|
+
*/
|
|
46
|
+
export declare function declaredPackages(fs: FileSystemHost, dir: string): Set<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Resolves every distinct library specifier of `project` once and counts the
|
|
49
|
+
* declarations whose specifier does not resolve.
|
|
50
|
+
*
|
|
51
|
+
* @param tsConfigPath - The project's tsconfig; the `package.json` with the
|
|
52
|
+
* declared packages is looked up from its directory upwards.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findUnresolvedLibraryImports(project: Project, tsConfigPath: string): UnresolvedLibraryImports;
|
|
55
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
56
|
+
export declare function libraryImportWarning(found: UnresolvedLibraryImports): string | undefined;
|
|
57
|
+
//# sourceMappingURL=library-imports.d.ts.map
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Unresolved library imports
|
|
3
|
+
*
|
|
4
|
+
* Counts the library imports of a ts-morph Project that do not resolve, so
|
|
5
|
+
* investigation tools can say when their answer may be incomplete.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Without a resolvable `node_modules` the program still loads, but every
|
|
9
|
+
* library type is `any`: dialogs opened through `MatDialog`, subscriptions on
|
|
10
|
+
* `EventEmitter`, injected framework services and the like are no longer
|
|
11
|
+
* recognised, and the tools return fewer results without any error. This
|
|
12
|
+
* check makes that visible.
|
|
13
|
+
*
|
|
14
|
+
* A library import is a bare module specifier whose package is declared in
|
|
15
|
+
* the nearest `package.json` above the tsconfig (dependencies,
|
|
16
|
+
* devDependencies, peerDependencies, optionalDependencies) and that does not
|
|
17
|
+
* match a tsconfig `paths` alias. Relative imports, broken aliases, aliases of
|
|
18
|
+
* other tsconfigs (`@testing/*` from a spec config) and Node builtins
|
|
19
|
+
* (ambient modules of `@types/node`, which the resolver does not find as
|
|
20
|
+
* files) are not a missing install and are not counted. Each distinct
|
|
21
|
+
* specifier is resolved once with the TypeScript module resolver against the
|
|
22
|
+
* project's compiler options and file system host, so in-memory projects work
|
|
23
|
+
* the same way; when that fails, a package folder in a `node_modules` above
|
|
24
|
+
* the importing file still counts as installed (side-effect imports of plain
|
|
25
|
+
* JavaScript such as `moment/locale/de-at` have no types to resolve). No
|
|
26
|
+
* program is created.
|
|
27
|
+
*/
|
|
28
|
+
import { isRelativeSpecifier, matchPathPattern, } from '@angular-modernizer/core';
|
|
29
|
+
import { dirname, join } from 'node:path';
|
|
30
|
+
import { ts } from 'ts-morph';
|
|
31
|
+
/** Package names listed in the warning. */
|
|
32
|
+
export const EXAMPLE_PACKAGES = 5;
|
|
33
|
+
/** Module specifiers of the import and re-export declarations of one file. */
|
|
34
|
+
function moduleSpecifiers(sourceFile) {
|
|
35
|
+
const specifiers = [];
|
|
36
|
+
for (const statement of sourceFile.statements) {
|
|
37
|
+
const isEdge = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement);
|
|
38
|
+
const specifier = isEdge ? statement.moduleSpecifier : undefined;
|
|
39
|
+
if (specifier !== undefined && ts.isStringLiteral(specifier)) {
|
|
40
|
+
specifiers.push(specifier.text);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return specifiers;
|
|
44
|
+
}
|
|
45
|
+
/** `@scope/name/sub` -> `@scope/name`, `name/sub` -> `name`. */
|
|
46
|
+
export function packageName(specifier) {
|
|
47
|
+
const parts = specifier.split('/');
|
|
48
|
+
return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : (parts[0] ?? specifier);
|
|
49
|
+
}
|
|
50
|
+
const DEPENDENCY_FIELDS = [
|
|
51
|
+
'dependencies',
|
|
52
|
+
'devDependencies',
|
|
53
|
+
'peerDependencies',
|
|
54
|
+
'optionalDependencies',
|
|
55
|
+
];
|
|
56
|
+
/**
|
|
57
|
+
* Package names declared in the nearest `package.json` at or above `dir`;
|
|
58
|
+
* empty when there is none or it cannot be read.
|
|
59
|
+
*/
|
|
60
|
+
export function declaredPackages(fs, dir) {
|
|
61
|
+
for (let current = dir;; current = dirname(current)) {
|
|
62
|
+
const file = join(current, 'package.json');
|
|
63
|
+
if (fs.fileExistsSync(file)) {
|
|
64
|
+
try {
|
|
65
|
+
const manifest = JSON.parse(fs.readFileSync(file));
|
|
66
|
+
return new Set(DEPENDENCY_FIELDS.flatMap((field) => {
|
|
67
|
+
const deps = manifest[field];
|
|
68
|
+
return typeof deps === 'object' && deps !== null ? Object.keys(deps) : [];
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return new Set();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (dirname(current) === current) {
|
|
76
|
+
return new Set();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** `true` when `node_modules/<pkg>` exists in the directory of `fromFile` or above it. */
|
|
81
|
+
function packageFolderExists(host, fromFile, pkg) {
|
|
82
|
+
for (let dir = dirname(fromFile);; dir = dirname(dir)) {
|
|
83
|
+
if (host.directoryExists?.(join(dir, 'node_modules', pkg)) === true) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (dirname(dir) === dir) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Resolves every distinct library specifier of `project` once and counts the
|
|
93
|
+
* declarations whose specifier does not resolve.
|
|
94
|
+
*
|
|
95
|
+
* @param tsConfigPath - The project's tsconfig; the `package.json` with the
|
|
96
|
+
* declared packages is looked up from its directory upwards.
|
|
97
|
+
*/
|
|
98
|
+
export function findUnresolvedLibraryImports(project, tsConfigPath) {
|
|
99
|
+
const declared = declaredPackages(project.getFileSystem(), dirname(tsConfigPath));
|
|
100
|
+
const options = project.getCompilerOptions();
|
|
101
|
+
const host = project.getModuleResolutionHost();
|
|
102
|
+
const aliases = Object.keys(options.paths ?? {});
|
|
103
|
+
const isAlias = (specifier) => aliases.some((pattern) => matchPathPattern(pattern, specifier) !== undefined);
|
|
104
|
+
const cache = ts.createModuleResolutionCache(project.getFileSystem().getCurrentDirectory(), (fileName) => fileName, options);
|
|
105
|
+
const resolved = new Map();
|
|
106
|
+
const unresolvedPerPackage = new Map();
|
|
107
|
+
let imports = 0;
|
|
108
|
+
for (const sourceFile of project.getSourceFiles()) {
|
|
109
|
+
if (sourceFile.isInNodeModules()) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const containingFile = sourceFile.getFilePath();
|
|
113
|
+
for (const specifier of moduleSpecifiers(sourceFile.compilerNode)) {
|
|
114
|
+
const isLibrary = !isRelativeSpecifier(specifier) &&
|
|
115
|
+
declared.has(packageName(specifier)) &&
|
|
116
|
+
!isAlias(specifier);
|
|
117
|
+
if (!isLibrary) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
let ok = resolved.get(specifier);
|
|
121
|
+
if (ok === undefined) {
|
|
122
|
+
ok =
|
|
123
|
+
ts.resolveModuleName(specifier, containingFile, options, host, cache)
|
|
124
|
+
.resolvedModule !== undefined ||
|
|
125
|
+
packageFolderExists(host, containingFile, packageName(specifier));
|
|
126
|
+
resolved.set(specifier, ok);
|
|
127
|
+
}
|
|
128
|
+
if (!ok) {
|
|
129
|
+
imports++;
|
|
130
|
+
const name = packageName(specifier);
|
|
131
|
+
unresolvedPerPackage.set(name, (unresolvedPerPackage.get(name) ?? 0) + 1);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const examples = [...unresolvedPerPackage]
|
|
136
|
+
.sort(([a, countA], [b, countB]) => countB - countA || a.localeCompare(b))
|
|
137
|
+
.slice(0, EXAMPLE_PACKAGES)
|
|
138
|
+
.map(([name]) => name);
|
|
139
|
+
return { imports, packages: unresolvedPerPackage.size, examples };
|
|
140
|
+
}
|
|
141
|
+
/** Warning text for `warnings` and the summary, or `undefined` when all resolve. */
|
|
142
|
+
export function libraryImportWarning(found) {
|
|
143
|
+
if (found.imports === 0) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
const more = found.packages > found.examples.length ? ', ...' : '';
|
|
147
|
+
return (`${found.imports} library import(s) from ${found.packages} package(s) do not resolve ` +
|
|
148
|
+
`(${found.examples.join(', ')}${more}); is node_modules missing or incomplete? ` +
|
|
149
|
+
'Results that depend on library types (dialogs, subscriptions, injected services) can be incomplete.');
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=library-imports.js.map
|