@angular-modernizer/adapter-mcp 0.2.0 → 1.0.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 +188 -235
- package/dist/cli.js +77 -27
- package/dist/index.d.ts +11 -3
- package/dist/index.js +10 -2
- package/dist/mcp-watcher.d.ts +6 -1
- package/dist/mcp-watcher.js +14 -10
- package/dist/server/limited-stdio-transport.d.ts +68 -0
- package/dist/server/limited-stdio-transport.js +115 -0
- package/dist/server/mcp-server.d.ts +41 -12
- package/dist/server/mcp-server.js +113 -94
- package/dist/server/package-version.d.ts +16 -0
- package/dist/server/package-version.js +37 -0
- package/dist/server/sdk-server.d.ts +70 -0
- package/dist/server/sdk-server.js +113 -0
- package/dist/server/stdio-guard.d.ts +20 -0
- package/dist/server/stdio-guard.js +48 -0
- package/dist/server/tool-registry.d.ts +3 -2
- package/dist/server/tool-registry.js +5 -5
- package/dist/tools/analyze-build-impact.d.ts +346 -14
- package/dist/tools/analyze-build-impact.js +315 -31
- package/dist/tools/analyze-core-to-shared.d.ts +134 -4
- package/dist/tools/analyze-core-to-shared.js +113 -9
- package/dist/tools/analyze-parser-performance.d.ts +200 -7
- package/dist/tools/analyze-parser-performance.js +108 -47
- package/dist/tools/analyze-project.d.ts +267 -5
- package/dist/tools/analyze-project.js +196 -8
- package/dist/tools/check-incremental-compatibility.d.ts +61 -1
- package/dist/tools/check-incremental-compatibility.js +58 -2
- package/dist/tools/collect-feedback.d.ts +199 -10
- package/dist/tools/collect-feedback.js +171 -99
- package/dist/tools/compare-health.d.ts +356 -0
- package/dist/tools/compare-health.js +472 -0
- package/dist/tools/extract-libraries.d.ts +156 -4
- package/dist/tools/extract-libraries.js +115 -10
- package/dist/tools/find-angular-symbol.d.ts +98 -9
- package/dist/tools/find-angular-symbol.js +104 -12
- package/dist/tools/find-component-hosts.d.ts +684 -0
- package/dist/tools/find-component-hosts.js +441 -0
- package/dist/tools/find-usages.d.ts +99 -4
- package/dist/tools/find-usages.js +131 -11
- package/dist/tools/get-bootstrap-execution.d.ts +258 -0
- package/dist/tools/get-bootstrap-execution.js +324 -0
- package/dist/tools/get-call-graph.d.ts +139 -4
- package/dist/tools/get-call-graph.js +123 -13
- package/dist/tools/get-operation-progress-tool.d.ts +114 -2
- package/dist/tools/get-operation-progress-tool.js +114 -7
- package/dist/tools/get-operation-progress.d.ts +1 -1
- package/dist/tools/get-operation-progress.js +5 -5
- package/dist/tools/helpers/analysis-output.d.ts +177 -0
- package/dist/tools/helpers/analysis-output.js +165 -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 +61 -0
- package/dist/tools/helpers/compact-output.js +83 -0
- 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 +86 -0
- package/dist/tools/helpers/health-delta.js +239 -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 +184 -0
- package/dist/tools/helpers/project-cache.js +331 -0
- 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 +72 -0
- package/dist/tools/helpers/rule-runner.js +131 -0
- package/dist/tools/helpers/scan-cache.d.ts +22 -0
- package/dist/tools/helpers/scan-cache.js +34 -0
- package/dist/tools/helpers/scan-plan.d.ts +48 -0
- package/dist/tools/helpers/scan-plan.js +166 -0
- package/dist/tools/helpers/scope-paths.d.ts +17 -0
- package/dist/tools/helpers/scope-paths.js +32 -0
- package/dist/tools/helpers/stack-frame-file-index.d.ts +10 -0
- package/dist/tools/helpers/stack-frame-file-index.js +71 -0
- package/dist/tools/helpers/tool-context.d.ts +60 -0
- package/dist/tools/helpers/tool-context.js +82 -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 +324 -0
- package/dist/tools/inspect-form-group.js +279 -0
- package/dist/tools/inspect-i18n.d.ts +466 -0
- package/dist/tools/inspect-i18n.js +400 -0
- package/dist/tools/inspect-template.d.ts +320 -0
- package/dist/tools/inspect-template.js +324 -0
- package/dist/tools/learn-patterns.d.ts +122 -1
- package/dist/tools/learn-patterns.js +97 -2
- package/dist/tools/list-imports.d.ts +128 -11
- package/dist/tools/list-imports.js +128 -8
- package/dist/tools/orchestrate-migration.d.ts +129 -5
- package/dist/tools/orchestrate-migration.js +166 -12
- package/dist/tools/parse-stack-trace.d.ts +59 -2
- package/dist/tools/parse-stack-trace.js +52 -4
- package/dist/tools/plan-migration.d.ts +418 -1
- package/dist/tools/plan-migration.js +355 -8
- package/dist/tools/resolve-type.d.ts +42 -1
- package/dist/tools/resolve-type.js +37 -4
- package/dist/tools/review-feedback.d.ts +206 -11
- package/dist/tools/review-feedback.js +132 -51
- package/dist/tools/rollback-changes.d.ts +79 -2
- package/dist/tools/rollback-changes.js +66 -14
- package/dist/tools/run-angular-cli.d.ts +45 -2
- package/dist/tools/run-angular-cli.js +67 -7
- package/dist/tools/run-build.d.ts +114 -2
- package/dist/tools/run-build.js +117 -8
- package/dist/tools/run-schematic.d.ts +70 -2
- package/dist/tools/run-schematic.js +104 -10
- package/dist/tools/scan-all.d.ts +24 -16
- package/dist/tools/scan-all.js +145 -137
- package/dist/tools/scan-angular.d.ts +20 -11
- package/dist/tools/scan-angular.js +52 -24
- package/dist/tools/scan-architecture.d.ts +42 -14
- package/dist/tools/scan-architecture.js +206 -163
- package/dist/tools/scan-solid.d.ts +20 -11
- package/dist/tools/scan-solid.js +52 -24
- package/dist/tools/search-codebase.d.ts +85 -1
- package/dist/tools/search-codebase.js +61 -4
- package/dist/tools/server-status.d.ts +370 -0
- package/dist/tools/server-status.js +369 -0
- package/dist/tools/suggest-improvements.d.ts +97 -5
- package/dist/tools/suggest-improvements.js +80 -44
- package/dist/tools/trace-output-flow.d.ts +791 -0
- package/dist/tools/trace-output-flow.js +668 -0
- 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 +335 -12
- package/dist/tools/transform-code.js +649 -608
- package/dist/tools/validate-before-transform.d.ts +116 -2
- package/dist/tools/validate-before-transform.js +55 -2
- package/dist/tools/validate-project-compatibility.d.ts +64 -2
- package/dist/tools/validate-project-compatibility.js +67 -4
- package/dist/tools/validate-transformation.d.ts +220 -2
- package/dist/tools/validate-transformation.js +113 -15
- package/dist/tools/verify-citations.d.ts +181 -0
- package/dist/tools/verify-citations.js +218 -0
- package/dist/types.d.ts +45 -1
- package/dist/utils/format-tool-response.d.ts +22 -59
- package/dist/utils/format-tool-response.js +25 -134
- package/package.json +30 -13
- 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 -57
- package/dist/server/json-rpc-handler.d.ts.map +0 -1
- package/dist/server/json-rpc-handler.js +0 -222
- 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/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-usages.d.ts.map +0 -1
- package/dist/tools/find-usages.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/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/rule-matcher.d.ts.map +0 -1
- package/dist/tools/helpers/rule-matcher.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/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/shared/scan-types.d.ts.map +0 -1
- 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/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,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result window of scan-all.
|
|
3
|
+
*
|
|
4
|
+
* Every finding, from the cache or newly analyzed, passes through the same
|
|
5
|
+
* steps: the rule filter, then the totals of the summary, then the page
|
|
6
|
+
* [offset, offset + limit). The window holds at most `limit` findings, so a
|
|
7
|
+
* large project does not keep all findings in memory for one page.
|
|
8
|
+
*/
|
|
9
|
+
export class FindingWindow {
|
|
10
|
+
offset;
|
|
11
|
+
limit;
|
|
12
|
+
rules;
|
|
13
|
+
page = [];
|
|
14
|
+
totals = {
|
|
15
|
+
totalViolations: 0,
|
|
16
|
+
bySeverity: {},
|
|
17
|
+
byCategory: {},
|
|
18
|
+
byRule: {},
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @param rules - Rule IDs to keep; empty or undefined keeps every rule
|
|
22
|
+
* @param offset - Index of the first finding of the page
|
|
23
|
+
* @param limit - Maximum number of findings on the page
|
|
24
|
+
*/
|
|
25
|
+
constructor(rules, offset, limit) {
|
|
26
|
+
this.offset = offset;
|
|
27
|
+
this.limit = limit;
|
|
28
|
+
this.rules = rules?.length ? new Set(rules) : undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Count the finding and keep it when it falls on the page. */
|
|
31
|
+
add(finding) {
|
|
32
|
+
if (typeof finding.ruleId !== 'string' || !finding.filePath) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (this.rules && !this.rules.has(finding.ruleId)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const index = this.totals.totalViolations++;
|
|
39
|
+
increment(this.totals.byRule, finding.ruleId);
|
|
40
|
+
increment(this.totals.bySeverity, String(finding.severity));
|
|
41
|
+
increment(this.totals.byCategory, typeof finding.category === 'string' && finding.category
|
|
42
|
+
? finding.category
|
|
43
|
+
: 'General');
|
|
44
|
+
if (index >= this.offset && index < this.offset + this.limit) {
|
|
45
|
+
this.page.push(finding);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Findings of the page, in the order they were added. */
|
|
49
|
+
getPage() {
|
|
50
|
+
return this.page;
|
|
51
|
+
}
|
|
52
|
+
/** Totals over every finding that passed the rule filter. */
|
|
53
|
+
getTotals() {
|
|
54
|
+
return this.totals;
|
|
55
|
+
}
|
|
56
|
+
/** Whether findings follow after the page. */
|
|
57
|
+
hasMore() {
|
|
58
|
+
return this.offset + this.limit < this.totals.totalViolations;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function increment(counts, key) {
|
|
62
|
+
counts[key] = (counts[key] ?? 0) + 1;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=finding-window.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Health delta
|
|
3
|
+
*
|
|
4
|
+
* Snapshot format and comparison behind the compare-health tool: which
|
|
5
|
+
* violations are new, fixed or unchanged since the last scan.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Line numbers shift with every edit above a finding, so they are not part of
|
|
9
|
+
* the key. Within one rule and file, violations are matched first by their
|
|
10
|
+
* message with digits removed (counts inside messages change too), the rest
|
|
11
|
+
* by number: three findings before and two now means one fixed. Which of the
|
|
12
|
+
* unmatched ones is reported as fixed or new follows the line order.
|
|
13
|
+
*/
|
|
14
|
+
/** One violation as stored in a snapshot and reported in a delta. */
|
|
15
|
+
export interface HealthViolation {
|
|
16
|
+
ruleId: string;
|
|
17
|
+
/** Relative to the project root. */
|
|
18
|
+
filePath: string;
|
|
19
|
+
message: string;
|
|
20
|
+
severity: string;
|
|
21
|
+
category: string;
|
|
22
|
+
line?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Scan arguments that change which violations a run can find. */
|
|
25
|
+
export interface HealthScope {
|
|
26
|
+
rules: string[] | null;
|
|
27
|
+
includePatterns: string[] | null;
|
|
28
|
+
excludePatterns: string[] | null;
|
|
29
|
+
}
|
|
30
|
+
/** Content of the snapshot file. */
|
|
31
|
+
export interface HealthSnapshot {
|
|
32
|
+
version: typeof HEALTH_SNAPSHOT_VERSION;
|
|
33
|
+
createdAt: string;
|
|
34
|
+
scope: HealthScope;
|
|
35
|
+
rulesExecuted: string[];
|
|
36
|
+
analyzedFiles: number;
|
|
37
|
+
violations: HealthViolation[];
|
|
38
|
+
}
|
|
39
|
+
/** Counts of one rule in the previous and the current run. */
|
|
40
|
+
export interface RuleDelta {
|
|
41
|
+
ruleId: string;
|
|
42
|
+
previous: number;
|
|
43
|
+
current: number;
|
|
44
|
+
new: number;
|
|
45
|
+
fixed: number;
|
|
46
|
+
unchanged: number;
|
|
47
|
+
}
|
|
48
|
+
/** Counts of one file whose violations changed. */
|
|
49
|
+
export interface FileDelta {
|
|
50
|
+
filePath: string;
|
|
51
|
+
previous: number;
|
|
52
|
+
current: number;
|
|
53
|
+
new: number;
|
|
54
|
+
fixed: number;
|
|
55
|
+
}
|
|
56
|
+
/** Result of comparing two runs. */
|
|
57
|
+
export interface HealthDelta {
|
|
58
|
+
newViolations: HealthViolation[];
|
|
59
|
+
fixedViolations: HealthViolation[];
|
|
60
|
+
unchanged: number;
|
|
61
|
+
/** Every rule with violations in either run. */
|
|
62
|
+
byRule: RuleDelta[];
|
|
63
|
+
/** Only files with new or fixed violations. */
|
|
64
|
+
byFile: FileDelta[];
|
|
65
|
+
}
|
|
66
|
+
export declare const HEALTH_SNAPSHOT_VERSION = 1;
|
|
67
|
+
/** Snapshot location relative to the project root, next to the scan cache. */
|
|
68
|
+
export declare const DEFAULT_HEALTH_SNAPSHOT_PATH = ".angular-modernizer-cache/health/last-run.json";
|
|
69
|
+
/** Message without digits and repeated whitespace, used as matching key. */
|
|
70
|
+
export declare function normalizeMessage(message: string): string;
|
|
71
|
+
/** Orders violations by file, line and rule. */
|
|
72
|
+
export declare function compareViolations(a: HealthViolation, b: HealthViolation): number;
|
|
73
|
+
/** Snapshot file content: one line per file with violations. */
|
|
74
|
+
export declare function serializeHealthSnapshot(snapshot: HealthSnapshot): string;
|
|
75
|
+
/**
|
|
76
|
+
* Reads snapshot file content.
|
|
77
|
+
*
|
|
78
|
+
* @returns the snapshot, or `undefined` when the text is not JSON, has another
|
|
79
|
+
* version or misses required fields.
|
|
80
|
+
*/
|
|
81
|
+
export declare function parseHealthSnapshot(text: string): HealthSnapshot | undefined;
|
|
82
|
+
/** Readable differences between two scopes; empty when they match. */
|
|
83
|
+
export declare function scopeDifferences(previous: HealthScope, current: HealthScope): string[];
|
|
84
|
+
/** Compares the violations of the previous run with the current one. */
|
|
85
|
+
export declare function compareHealth(previous: readonly HealthViolation[], current: readonly HealthViolation[]): HealthDelta;
|
|
86
|
+
//# sourceMappingURL=health-delta.d.ts.map
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Health delta
|
|
3
|
+
*
|
|
4
|
+
* Snapshot format and comparison behind the compare-health tool: which
|
|
5
|
+
* violations are new, fixed or unchanged since the last scan.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Line numbers shift with every edit above a finding, so they are not part of
|
|
9
|
+
* the key. Within one rule and file, violations are matched first by their
|
|
10
|
+
* message with digits removed (counts inside messages change too), the rest
|
|
11
|
+
* by number: three findings before and two now means one fixed. Which of the
|
|
12
|
+
* unmatched ones is reported as fixed or new follows the line order.
|
|
13
|
+
*/
|
|
14
|
+
export const HEALTH_SNAPSHOT_VERSION = 1;
|
|
15
|
+
/** Snapshot location relative to the project root, next to the scan cache. */
|
|
16
|
+
export const DEFAULT_HEALTH_SNAPSHOT_PATH = '.angular-modernizer-cache/health/last-run.json';
|
|
17
|
+
/** Message without digits and repeated whitespace, used as matching key. */
|
|
18
|
+
export function normalizeMessage(message) {
|
|
19
|
+
return message.replace(/\d+/g, '#').replace(/\s+/g, ' ').trim();
|
|
20
|
+
}
|
|
21
|
+
/** Orders violations by file, line and rule. */
|
|
22
|
+
export function compareViolations(a, b) {
|
|
23
|
+
return (a.filePath.localeCompare(b.filePath) ||
|
|
24
|
+
(a.line ?? 0) - (b.line ?? 0) ||
|
|
25
|
+
a.ruleId.localeCompare(b.ruleId));
|
|
26
|
+
}
|
|
27
|
+
/** Snapshot file content: one line per file with violations. */
|
|
28
|
+
export function serializeHealthSnapshot(snapshot) {
|
|
29
|
+
const files = new Map();
|
|
30
|
+
for (const v of snapshot.violations) {
|
|
31
|
+
const stored = [
|
|
32
|
+
v.ruleId,
|
|
33
|
+
v.line ?? null,
|
|
34
|
+
v.severity,
|
|
35
|
+
v.category,
|
|
36
|
+
v.message,
|
|
37
|
+
];
|
|
38
|
+
pushTo(files, v.filePath, stored);
|
|
39
|
+
}
|
|
40
|
+
const header = JSON.stringify({
|
|
41
|
+
version: snapshot.version,
|
|
42
|
+
createdAt: snapshot.createdAt,
|
|
43
|
+
scope: snapshot.scope,
|
|
44
|
+
rulesExecuted: snapshot.rulesExecuted,
|
|
45
|
+
analyzedFiles: snapshot.analyzedFiles,
|
|
46
|
+
totalViolations: snapshot.violations.length,
|
|
47
|
+
});
|
|
48
|
+
const lines = [...files].map(([file, list]) => `${JSON.stringify(file)}:${JSON.stringify(list)}`);
|
|
49
|
+
return `${header.slice(0, -1)},"files":{\n${lines.join(',\n')}\n}}\n`;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reads snapshot file content.
|
|
53
|
+
*
|
|
54
|
+
* @returns the snapshot, or `undefined` when the text is not JSON, has another
|
|
55
|
+
* version or misses required fields.
|
|
56
|
+
*/
|
|
57
|
+
export function parseHealthSnapshot(text) {
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
data = JSON.parse(text);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
if (!isRecord(data) || data['version'] !== HEALTH_SNAPSHOT_VERSION) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
const { createdAt, scope, rulesExecuted, analyzedFiles, files } = data;
|
|
69
|
+
const valid = typeof createdAt === 'string' &&
|
|
70
|
+
isScope(scope) &&
|
|
71
|
+
isStringArray(rulesExecuted) &&
|
|
72
|
+
typeof analyzedFiles === 'number' &&
|
|
73
|
+
isRecord(files);
|
|
74
|
+
if (!valid) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const violations = [];
|
|
78
|
+
for (const [filePath, list] of Object.entries(files)) {
|
|
79
|
+
if (!Array.isArray(list) || !list.every(isStoredViolation)) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
for (const [ruleId, line, severity, category, message] of list) {
|
|
83
|
+
violations.push({
|
|
84
|
+
ruleId,
|
|
85
|
+
filePath,
|
|
86
|
+
message,
|
|
87
|
+
severity,
|
|
88
|
+
category,
|
|
89
|
+
...(line === null ? {} : { line }),
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
version: HEALTH_SNAPSHOT_VERSION,
|
|
95
|
+
createdAt,
|
|
96
|
+
scope,
|
|
97
|
+
rulesExecuted,
|
|
98
|
+
analyzedFiles,
|
|
99
|
+
violations,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Readable differences between two scopes; empty when they match. */
|
|
103
|
+
export function scopeDifferences(previous, current) {
|
|
104
|
+
const keys = ['rules', 'includePatterns', 'excludePatterns'];
|
|
105
|
+
return keys
|
|
106
|
+
.filter((key) => !sameList(previous[key], current[key]))
|
|
107
|
+
.map((key) => `${key}: ${describeList(previous[key])} -> ${describeList(current[key])}`);
|
|
108
|
+
}
|
|
109
|
+
/** Compares the violations of the previous run with the current one. */
|
|
110
|
+
export function compareHealth(previous, current) {
|
|
111
|
+
const previousGroups = groupByRuleAndFile(previous);
|
|
112
|
+
const currentGroups = groupByRuleAndFile(current);
|
|
113
|
+
const keys = new Set([...previousGroups.keys(), ...currentGroups.keys()]);
|
|
114
|
+
const newViolations = [];
|
|
115
|
+
const fixedViolations = [];
|
|
116
|
+
const rules = new Map();
|
|
117
|
+
const files = new Map();
|
|
118
|
+
let unchanged = 0;
|
|
119
|
+
for (const key of keys) {
|
|
120
|
+
const before = previousGroups.get(key) ?? [];
|
|
121
|
+
const after = currentGroups.get(key) ?? [];
|
|
122
|
+
const match = matchGroup(before, after);
|
|
123
|
+
newViolations.push(...match.added);
|
|
124
|
+
fixedViolations.push(...match.removed);
|
|
125
|
+
unchanged += match.unchanged;
|
|
126
|
+
const sample = after[0] ?? before[0];
|
|
127
|
+
if (sample === undefined) {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const rule = rules.get(sample.ruleId) ?? emptyRule(sample.ruleId);
|
|
131
|
+
rule.previous += before.length;
|
|
132
|
+
rule.current += after.length;
|
|
133
|
+
rule.new += match.added.length;
|
|
134
|
+
rule.fixed += match.removed.length;
|
|
135
|
+
rule.unchanged += match.unchanged;
|
|
136
|
+
rules.set(sample.ruleId, rule);
|
|
137
|
+
const file = files.get(sample.filePath) ?? emptyFile(sample.filePath);
|
|
138
|
+
file.previous += before.length;
|
|
139
|
+
file.current += after.length;
|
|
140
|
+
file.new += match.added.length;
|
|
141
|
+
file.fixed += match.removed.length;
|
|
142
|
+
files.set(sample.filePath, file);
|
|
143
|
+
}
|
|
144
|
+
const changes = (d) => d.new + d.fixed;
|
|
145
|
+
return {
|
|
146
|
+
newViolations: newViolations.sort(compareViolations),
|
|
147
|
+
fixedViolations: fixedViolations.sort(compareViolations),
|
|
148
|
+
unchanged,
|
|
149
|
+
byRule: [...rules.values()].sort((a, b) => changes(b) - changes(a) ||
|
|
150
|
+
b.current - a.current ||
|
|
151
|
+
a.ruleId.localeCompare(b.ruleId)),
|
|
152
|
+
byFile: [...files.values()]
|
|
153
|
+
.filter((f) => changes(f) > 0)
|
|
154
|
+
.sort((a, b) => changes(b) - changes(a) || a.filePath.localeCompare(b.filePath)),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
function matchGroup(before, after) {
|
|
158
|
+
const byMessage = new Map();
|
|
159
|
+
for (const v of [...before].sort(compareViolations)) {
|
|
160
|
+
pushTo(byMessage, normalizeMessage(v.message), v);
|
|
161
|
+
}
|
|
162
|
+
const unmatchedAfter = [];
|
|
163
|
+
for (const v of [...after].sort(compareViolations)) {
|
|
164
|
+
const candidates = byMessage.get(normalizeMessage(v.message));
|
|
165
|
+
if (candidates === undefined || candidates.length === 0) {
|
|
166
|
+
unmatchedAfter.push(v);
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
candidates.shift();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const unmatchedBefore = [...byMessage.values()]
|
|
173
|
+
.flat()
|
|
174
|
+
.sort(compareViolations);
|
|
175
|
+
const paired = Math.min(unmatchedBefore.length, unmatchedAfter.length);
|
|
176
|
+
return {
|
|
177
|
+
added: unmatchedAfter.slice(paired),
|
|
178
|
+
removed: unmatchedBefore.slice(paired),
|
|
179
|
+
unchanged: after.length - (unmatchedAfter.length - paired),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
function groupByRuleAndFile(violations) {
|
|
183
|
+
const groups = new Map();
|
|
184
|
+
for (const v of violations) {
|
|
185
|
+
pushTo(groups, `${v.ruleId}\u0000${v.filePath}`, v);
|
|
186
|
+
}
|
|
187
|
+
return groups;
|
|
188
|
+
}
|
|
189
|
+
function pushTo(map, key, value) {
|
|
190
|
+
const list = map.get(key);
|
|
191
|
+
if (list === undefined) {
|
|
192
|
+
map.set(key, [value]);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
list.push(value);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function emptyRule(ruleId) {
|
|
199
|
+
return { ruleId, previous: 0, current: 0, new: 0, fixed: 0, unchanged: 0 };
|
|
200
|
+
}
|
|
201
|
+
function emptyFile(filePath) {
|
|
202
|
+
return { filePath, previous: 0, current: 0, new: 0, fixed: 0 };
|
|
203
|
+
}
|
|
204
|
+
function sameList(a, b) {
|
|
205
|
+
if (a === null || b === null) {
|
|
206
|
+
return a === b;
|
|
207
|
+
}
|
|
208
|
+
const left = [...a].sort();
|
|
209
|
+
const right = [...b].sort();
|
|
210
|
+
return left.length === right.length && left.every((x, i) => x === right[i]);
|
|
211
|
+
}
|
|
212
|
+
function describeList(list) {
|
|
213
|
+
return list === null ? 'default' : `[${list.join(', ')}]`;
|
|
214
|
+
}
|
|
215
|
+
function isRecord(value) {
|
|
216
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
217
|
+
}
|
|
218
|
+
function isStringArray(value) {
|
|
219
|
+
return Array.isArray(value) && value.every((x) => typeof x === 'string');
|
|
220
|
+
}
|
|
221
|
+
function isListOrNull(value) {
|
|
222
|
+
return value === null || isStringArray(value);
|
|
223
|
+
}
|
|
224
|
+
function isScope(value) {
|
|
225
|
+
return (isRecord(value) &&
|
|
226
|
+
isListOrNull(value['rules']) &&
|
|
227
|
+
isListOrNull(value['includePatterns']) &&
|
|
228
|
+
isListOrNull(value['excludePatterns']));
|
|
229
|
+
}
|
|
230
|
+
function isStoredViolation(value) {
|
|
231
|
+
return (Array.isArray(value) &&
|
|
232
|
+
value.length === 5 &&
|
|
233
|
+
typeof value[0] === 'string' &&
|
|
234
|
+
(value[1] === null || typeof value[1] === 'number') &&
|
|
235
|
+
typeof value[2] === 'string' &&
|
|
236
|
+
typeof value[3] === 'string' &&
|
|
237
|
+
typeof value[4] === 'string');
|
|
238
|
+
}
|
|
239
|
+
//# 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
|