@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,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Analysis part of the scan tools
|
|
3
|
+
*
|
|
4
|
+
* The part of a scan between "build the kernel" and "all files analyzed":
|
|
5
|
+
* kernel, project, rules, file loading and rule runs. It runs in a scan worker
|
|
6
|
+
* (`scan-host/`) or, as fallback and under Jest, in the calling thread; both
|
|
7
|
+
* paths run this function, so they produce the same findings in the same
|
|
8
|
+
* order. Glob, scan cache, result window, progress and the MCP protocol stay
|
|
9
|
+
* with the tool on the main thread.
|
|
10
|
+
*
|
|
11
|
+
* The engine does not write to disk (the kernel gets no cache config), so a
|
|
12
|
+
* worker killed in the middle leaves nothing half written.
|
|
13
|
+
*/
|
|
14
|
+
import { existsSync } from 'node:fs';
|
|
15
|
+
import { Kernel, loadConfig } from '@angular-modernizer/core';
|
|
16
|
+
import { createPublicApi } from '@angular-modernizer/api';
|
|
17
|
+
import { ContextFactory, } from '@angular-modernizer/plugin-system';
|
|
18
|
+
import { loadSourceFiles } from './load-source-files.js';
|
|
19
|
+
import { runRulesOverFiles, } from './rule-runner.js';
|
|
20
|
+
import { templateDependencies } from './scan-cache.js';
|
|
21
|
+
import { yieldIfCancellable } from './tool-context.js';
|
|
22
|
+
/**
|
|
23
|
+
* Plugins of a scan, loaded on demand: a worker loads only the plugins its
|
|
24
|
+
* scan runs (plugin-angular brings `@angular/compiler`).
|
|
25
|
+
*/
|
|
26
|
+
async function createPlugins(set) {
|
|
27
|
+
switch (set) {
|
|
28
|
+
case 'all': {
|
|
29
|
+
const [solid, angular, architecture] = await Promise.all([
|
|
30
|
+
import('@angular-modernizer/plugin-solid'),
|
|
31
|
+
import('@angular-modernizer/plugin-angular'),
|
|
32
|
+
import('@angular-modernizer/plugin-architecture'),
|
|
33
|
+
]);
|
|
34
|
+
return [
|
|
35
|
+
new solid.SolidPlugin(),
|
|
36
|
+
new angular.AngularPlugin(),
|
|
37
|
+
new architecture.ArchitecturePlugin(),
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
case 'solid':
|
|
41
|
+
return [new (await import('@angular-modernizer/plugin-solid')).SolidPlugin()];
|
|
42
|
+
case 'angular':
|
|
43
|
+
return [new (await import('@angular-modernizer/plugin-angular')).AngularPlugin()];
|
|
44
|
+
case 'architecture':
|
|
45
|
+
return [new (await import('@angular-modernizer/plugin-architecture')).ArchitecturePlugin()];
|
|
46
|
+
case 'analyzer':
|
|
47
|
+
return [new (await import('@angular-modernizer/plugin-analyzer')).AnalyzerPlugin()];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Runs the analysis part of a scan and reports each analyzed file to `sink`.
|
|
52
|
+
*/
|
|
53
|
+
export async function runScanEngine(spec, sink, control = {}) {
|
|
54
|
+
// analyze-project analyzes against the whole tsconfig program; the other
|
|
55
|
+
// scans add their files themselves (keeps dist/, e2e/ and the like out).
|
|
56
|
+
const kernel = new Kernel({
|
|
57
|
+
tsConfigPath: spec.tsConfigPath,
|
|
58
|
+
plugins: await createPlugins(spec.plugins),
|
|
59
|
+
fileSystem: undefined,
|
|
60
|
+
projectOptions: { skipAddingFilesFromTsConfig: spec.mode !== 'sequential' },
|
|
61
|
+
});
|
|
62
|
+
await kernel.initialize();
|
|
63
|
+
// The kernel's plugin instances carry the ruleConfigs of .angular-modernizer.json
|
|
64
|
+
const allRules = kernel
|
|
65
|
+
.getAllPlugins()
|
|
66
|
+
.flatMap((p) => p.getAnalysisRules());
|
|
67
|
+
const rules = spec.ruleIds === undefined
|
|
68
|
+
? allRules
|
|
69
|
+
: allRules.filter((rule) => spec.ruleIds.includes(rule.id));
|
|
70
|
+
if (rules.length === 0 && spec.mode === 'runner') {
|
|
71
|
+
throw new Error('No matching rules found');
|
|
72
|
+
}
|
|
73
|
+
const ruleIds = rules.map((r) => r.id);
|
|
74
|
+
sink.ready?.(ruleIds);
|
|
75
|
+
// Per-rule overrides of .angular-modernizer.json (BUG-3)
|
|
76
|
+
const config = (loadConfig(spec.rootPath).rules ?? {});
|
|
77
|
+
switch (spec.mode) {
|
|
78
|
+
case 'batches':
|
|
79
|
+
return runBatches(kernel, rules, config, spec, sink, control, ruleIds);
|
|
80
|
+
case 'runner':
|
|
81
|
+
return runRunner(kernel, rules, config, spec, sink, control, ruleIds);
|
|
82
|
+
case 'sequential':
|
|
83
|
+
return runSequential(kernel, rules, config, spec, sink, control, ruleIds);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function runBatches(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
87
|
+
const { signal } = control;
|
|
88
|
+
const batchSize = spec.batchSize ?? 100;
|
|
89
|
+
const totalBatches = Math.ceil(spec.files.length / batchSize);
|
|
90
|
+
const project = kernel.getProject();
|
|
91
|
+
for (let batchNum = 0; batchNum < totalBatches; batchNum++) {
|
|
92
|
+
const batchFiles = spec.files.slice(batchNum * batchSize, (batchNum + 1) * batchSize);
|
|
93
|
+
console.info(`\n${spec.tool} batch ${batchNum + 1}/${totalBatches}: ${batchFiles.length} files`);
|
|
94
|
+
// A new batch replaces the files of the previous one
|
|
95
|
+
for (const file of project.getSourceFiles()) {
|
|
96
|
+
project.removeSourceFile(file);
|
|
97
|
+
}
|
|
98
|
+
// Sorted order kept: findings must come out in the order a warm run
|
|
99
|
+
// reads them from the cache. A cancel during the load stops the scan.
|
|
100
|
+
const loaded = await loadSourceFiles(project, batchFiles, { signal });
|
|
101
|
+
if (loaded.cancelled) {
|
|
102
|
+
return { cancelled: true, ruleIds };
|
|
103
|
+
}
|
|
104
|
+
const api = createPublicApi(project);
|
|
105
|
+
const sourceFiles = spec.analyzeProjectFiles === true ? project.getSourceFiles() : loaded.sourceFiles;
|
|
106
|
+
for (const sourceFile of sourceFiles) {
|
|
107
|
+
await yieldIfCancellable(signal);
|
|
108
|
+
if (signal?.aborted === true) {
|
|
109
|
+
return { cancelled: true, ruleIds };
|
|
110
|
+
}
|
|
111
|
+
const findings = [];
|
|
112
|
+
for (const rule of rules) {
|
|
113
|
+
try {
|
|
114
|
+
const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
|
|
115
|
+
for (const result of results) {
|
|
116
|
+
findings.push(toFinding(rule, result));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.warn(`Failed to analyze with rule ${rule.id}:`, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
sink.file(fileEvent(sourceFile, findings, spec));
|
|
124
|
+
}
|
|
125
|
+
sink.batchDone?.(batchFiles.length);
|
|
126
|
+
}
|
|
127
|
+
return { cancelled: false, ruleIds };
|
|
128
|
+
}
|
|
129
|
+
async function runRunner(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
130
|
+
const project = kernel.getProject();
|
|
131
|
+
const run = await runRulesOverFiles({
|
|
132
|
+
project,
|
|
133
|
+
files: spec.files,
|
|
134
|
+
rules,
|
|
135
|
+
api: createPublicApi(project),
|
|
136
|
+
config,
|
|
137
|
+
maxDurationMs: spec.maxDurationMs,
|
|
138
|
+
startTime: spec.startTime,
|
|
139
|
+
signal: control.signal,
|
|
140
|
+
collect: false,
|
|
141
|
+
onFileResults: (filePath, violations) => sink.file({ filePath, findings: violations }),
|
|
142
|
+
});
|
|
143
|
+
const { violations: _collected, ...summary } = run;
|
|
144
|
+
return { cancelled: run.stopReason === 'cancelled', ruleIds, run: summary };
|
|
145
|
+
}
|
|
146
|
+
async function runSequential(kernel, rules, config, spec, sink, control, ruleIds) {
|
|
147
|
+
const { signal } = control;
|
|
148
|
+
const project = kernel.getProject();
|
|
149
|
+
const api = createPublicApi(project);
|
|
150
|
+
for (const filePath of spec.files) {
|
|
151
|
+
await yieldIfCancellable(signal);
|
|
152
|
+
if (signal?.aborted === true) {
|
|
153
|
+
return { cancelled: true, ruleIds };
|
|
154
|
+
}
|
|
155
|
+
// A file that fails counts as analyzed with the findings it got so far
|
|
156
|
+
const findings = [];
|
|
157
|
+
try {
|
|
158
|
+
const sourceFile = project.addSourceFileAtPath(filePath);
|
|
159
|
+
for (const rule of rules) {
|
|
160
|
+
const results = await rule.analyze(ContextFactory.createAnalysisContext({ sourceFile, project, api: api, config }));
|
|
161
|
+
for (const result of results) {
|
|
162
|
+
findings.push(toFinding(rule, result));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
console.warn(`Error analyzing ${filePath}:`, error);
|
|
168
|
+
}
|
|
169
|
+
sink.file({ filePath, findings });
|
|
170
|
+
}
|
|
171
|
+
return { cancelled: false, ruleIds };
|
|
172
|
+
}
|
|
173
|
+
function toFinding(rule, result) {
|
|
174
|
+
return {
|
|
175
|
+
ruleId: result.ruleId,
|
|
176
|
+
severity: result.severity ?? rule.severity,
|
|
177
|
+
message: result.message,
|
|
178
|
+
filePath: result.filePath,
|
|
179
|
+
line: result.line,
|
|
180
|
+
column: result.column,
|
|
181
|
+
category: rule.category,
|
|
182
|
+
suggestedFix: result.suggestedFix,
|
|
183
|
+
metadata: result.metadata,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
function fileEvent(sourceFile, findings, spec) {
|
|
187
|
+
const filePath = sourceFile.getFilePath();
|
|
188
|
+
if (spec.templateDependencies !== true) {
|
|
189
|
+
return { filePath, findings };
|
|
190
|
+
}
|
|
191
|
+
return {
|
|
192
|
+
filePath,
|
|
193
|
+
findings,
|
|
194
|
+
dependencies: templateDependencies(filePath, sourceFile.getFullText(), findings.map((f) => f.filePath), existsSync),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=scan-engine.js.map
|
|
@@ -28,8 +28,11 @@ export interface ScanPlanResult {
|
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Read violations from a saved scan-architecture result. Accepts the tool
|
|
31
|
-
* result object (`{ violations: [...] }`),
|
|
32
|
-
*
|
|
31
|
+
* result object (`{ violations: [...] }`), the MCP tool result with
|
|
32
|
+
* `structuredContent`, a bare violation array, or an MCP content array
|
|
33
|
+
* (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
|
|
34
|
+
* array whose text is no JSON (the text summary of a structured result) is
|
|
35
|
+
* rejected like any other file without violations.
|
|
33
36
|
*/
|
|
34
37
|
export declare function readScanResultFile(filePath: string): ScanViolationInput[];
|
|
35
38
|
/**
|
|
@@ -18,8 +18,11 @@ function isRecord(value) {
|
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Read violations from a saved scan-architecture result. Accepts the tool
|
|
21
|
-
* result object (`{ violations: [...] }`),
|
|
22
|
-
*
|
|
21
|
+
* result object (`{ violations: [...] }`), the MCP tool result with
|
|
22
|
+
* `structuredContent`, a bare violation array, or an MCP content array
|
|
23
|
+
* (`[{ type: 'text', text: '<json>' }]`) as clients persist it. A content
|
|
24
|
+
* array whose text is no JSON (the text summary of a structured result) is
|
|
25
|
+
* rejected like any other file without violations.
|
|
23
26
|
*/
|
|
24
27
|
export function readScanResultFile(filePath) {
|
|
25
28
|
if (!existsSync(filePath)) {
|
|
@@ -42,15 +45,27 @@ function extractViolations(value) {
|
|
|
42
45
|
if (Array.isArray(value)) {
|
|
43
46
|
const first = value[0];
|
|
44
47
|
if (isRecord(first) && first['type'] === 'text' && typeof first['text'] === 'string') {
|
|
45
|
-
return extractViolations(
|
|
48
|
+
return extractViolations(parseJson(first['text']));
|
|
46
49
|
}
|
|
47
50
|
return value.filter(isScanViolation);
|
|
48
51
|
}
|
|
49
52
|
if (isRecord(value) && Array.isArray(value['violations'])) {
|
|
50
53
|
return value['violations'].filter(isScanViolation);
|
|
51
54
|
}
|
|
55
|
+
if (isRecord(value) && isRecord(value['structuredContent'])) {
|
|
56
|
+
return extractViolations(value['structuredContent']);
|
|
57
|
+
}
|
|
52
58
|
return undefined;
|
|
53
59
|
}
|
|
60
|
+
/** Parsed JSON, or `undefined` for text that is no JSON. */
|
|
61
|
+
function parseJson(text) {
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
54
69
|
function isScanViolation(value) {
|
|
55
70
|
return (isRecord(value) &&
|
|
56
71
|
typeof value['ruleId'] === 'string' &&
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scope path matching
|
|
3
|
+
*
|
|
4
|
+
* A file belongs to a scope path when it is that path or lies below it. A
|
|
5
|
+
* bare `startsWith` also matched sibling folders sharing the prefix
|
|
6
|
+
* (`features/orders` took in `features/orders-shared`).
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Whether `file` is `scopePath` itself or lies inside the folder
|
|
10
|
+
* `scopePath`. Both are compared with `/` separators.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isInScopePath(file: string, scopePath: string): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The files inside at least one of `scopePaths`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function filterFilesByScopePaths(files: readonly string[], scopePaths: readonly string[]): string[];
|
|
17
|
+
//# sourceMappingURL=scope-paths.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scope path matching
|
|
3
|
+
*
|
|
4
|
+
* A file belongs to a scope path when it is that path or lies below it. A
|
|
5
|
+
* bare `startsWith` also matched sibling folders sharing the prefix
|
|
6
|
+
* (`features/orders` took in `features/orders-shared`).
|
|
7
|
+
*/
|
|
8
|
+
/** `/` separators and no trailing separator. */
|
|
9
|
+
function normalizePath(path) {
|
|
10
|
+
const slashes = path.replaceAll('\\', '/');
|
|
11
|
+
return slashes.length > 1 ? slashes.replace(/\/+$/, '') : slashes;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Whether `file` is `scopePath` itself or lies inside the folder
|
|
15
|
+
* `scopePath`. Both are compared with `/` separators.
|
|
16
|
+
*/
|
|
17
|
+
export function isInScopePath(file, scopePath) {
|
|
18
|
+
const normalizedFile = normalizePath(file);
|
|
19
|
+
const normalizedScope = normalizePath(scopePath);
|
|
20
|
+
if (normalizedFile === normalizedScope) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
const folder = normalizedScope.endsWith('/') ? normalizedScope : `${normalizedScope}/`;
|
|
24
|
+
return normalizedFile.startsWith(folder);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The files inside at least one of `scopePaths`.
|
|
28
|
+
*/
|
|
29
|
+
export function filterFilesByScopePaths(files, scopePaths) {
|
|
30
|
+
return files.filter((file) => scopePaths.some((scopePath) => isInScopePath(file, scopePath)));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=scope-paths.js.map
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Suggestion Generator Helper
|
|
3
|
-
*
|
|
4
|
-
* Generates actionable rule improvement suggestions based on feedback analysis.
|
|
5
|
-
*
|
|
6
|
-
* Suggestion Logic:
|
|
7
|
-
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
8
|
-
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
9
|
-
* - Approach change: Alternative approach has >90% success rate → switch
|
|
10
|
-
*
|
|
11
|
-
* All suggestions require human approval before implementation.
|
|
12
|
-
*/
|
|
13
1
|
import type { TransformationFeedback } from '@angular-modernizer/core';
|
|
14
2
|
/**
|
|
15
3
|
* Performance metrics for a transformation rule
|
|
@@ -23,7 +11,15 @@ export interface Performance {
|
|
|
23
11
|
qualityImprovement: number;
|
|
24
12
|
}
|
|
25
13
|
/**
|
|
26
|
-
*
|
|
14
|
+
* Rule improvement suggestion generated from feedback analysis.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* Suggestion logic:
|
|
18
|
+
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
19
|
+
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
20
|
+
* - Approach change: Alternative approach has >90% success rate → switch
|
|
21
|
+
*
|
|
22
|
+
* All suggestions require human approval before implementation.
|
|
27
23
|
*/
|
|
28
24
|
export interface Suggestion {
|
|
29
25
|
/** Type of suggestion */
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @angular-modernizer/adapter-mcp - Suggestion Generator Helper
|
|
3
|
-
*
|
|
4
|
-
* Generates actionable rule improvement suggestions based on feedback analysis.
|
|
5
|
-
*
|
|
6
|
-
* Suggestion Logic:
|
|
7
|
-
* - Parameter adjustment: ≥3 high-confidence failures → lower threshold
|
|
8
|
-
* - Prerequisite check: ≥40% failures share common pattern → add validation
|
|
9
|
-
* - Approach change: Alternative approach has >90% success rate → switch
|
|
10
|
-
*
|
|
11
|
-
* All suggestions require human approval before implementation.
|
|
12
|
-
*/
|
|
13
1
|
/**
|
|
14
2
|
* Calculate current performance metrics for a rule
|
|
15
3
|
*
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
|
|
3
|
+
*
|
|
4
|
+
* scan-solid, scan-angular and scan-architecture read and write their cache
|
|
5
|
+
* on the main thread; the kernel that used to own it runs in the scan worker
|
|
6
|
+
* now and gets no cache config there.
|
|
7
|
+
*/
|
|
8
|
+
import { CacheManager } from '@angular-modernizer/core';
|
|
9
|
+
/** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
|
|
10
|
+
export declare function openToolCache(rootPath: string, tool: 'solid' | 'angular' | 'architecture'): Promise<CacheManager>;
|
|
11
|
+
//# sourceMappingURL=tool-cache.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/adapter-mcp - Scan cache of the single-plugin scans
|
|
3
|
+
*
|
|
4
|
+
* scan-solid, scan-angular and scan-architecture read and write their cache
|
|
5
|
+
* on the main thread; the kernel that used to own it runs in the scan worker
|
|
6
|
+
* now and gets no cache config there.
|
|
7
|
+
*/
|
|
8
|
+
import { CacheManager, RealFileSystemAdapter, createToolCacheConfig, } from '@angular-modernizer/core';
|
|
9
|
+
/** Opens `.angular-modernizer-cache/<tool>/` of `rootPath`. */
|
|
10
|
+
export async function openToolCache(rootPath, tool) {
|
|
11
|
+
const cache = new CacheManager(new RealFileSystemAdapter(), createToolCacheConfig(rootPath, tool));
|
|
12
|
+
await cache.initialize();
|
|
13
|
+
return cache;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=tool-cache.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { type ProgressFn } from '../../types.js';
|
|
2
|
+
/** Minimum gap between two progress notifications. */
|
|
3
|
+
export declare const PROGRESS_INTERVAL_MS = 250;
|
|
4
|
+
/**
|
|
5
|
+
* Wraps `send` so it fires for the first value, for the last value
|
|
6
|
+
* (`progress >= total`) and otherwise at most once per `intervalMs`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function throttleProgress(send: ProgressFn, intervalMs?: number, now?: () => number): ProgressFn;
|
|
9
|
+
/**
|
|
10
|
+
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
11
|
+
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
12
|
+
* (direct calls, tests) it returns at once.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
16
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
17
|
+
* the event loop a turn. Long loops therefore call this once per file.
|
|
18
|
+
*/
|
|
19
|
+
export declare function yieldIfCancellable(signal: AbortSignal | undefined): Promise<void>;
|
|
20
|
+
/** Progress message of a file loop: `12/40 files, 3 violations`. */
|
|
21
|
+
export declare function fileProgressMessage(analyzed: number, total: number, violations: number): string;
|
|
22
|
+
/**
|
|
23
|
+
* `onFileAnalyzed` callback of a file loop that reports to `progress`;
|
|
24
|
+
* `undefined` without progress, so the loop does no extra work.
|
|
25
|
+
*/
|
|
26
|
+
export declare function fileProgress(progress: ProgressFn | undefined): ((analyzed: number, total: number, violations: number) => void) | undefined;
|
|
27
|
+
/** Execution details of a scan the client cancelled. */
|
|
28
|
+
export interface CancelledExecution {
|
|
29
|
+
/** Time budget of the scan in milliseconds, when the tool has one. */
|
|
30
|
+
maxDurationMs?: number;
|
|
31
|
+
/** Always `true`: the scan stopped early. */
|
|
32
|
+
incomplete: true;
|
|
33
|
+
/** Why the scan stopped. */
|
|
34
|
+
stopReason: 'cancelled';
|
|
35
|
+
/** Files that were not analyzed. */
|
|
36
|
+
skippedFiles: number;
|
|
37
|
+
/** Always empty for a cancelled scan. */
|
|
38
|
+
ruleTimings: [];
|
|
39
|
+
/** Human-readable note: files analyzed and skipped. */
|
|
40
|
+
note: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Execution details of a scan the client cancelled after `analyzed` files.
|
|
44
|
+
* The SDK does not send the result of a cancelled request; it still has to
|
|
45
|
+
* be complete for direct callers (compare-health, tests).
|
|
46
|
+
*/
|
|
47
|
+
export declare function cancelledExecution(analyzed: number, skippedFiles: number, maxDurationMs?: number): CancelledExecution;
|
|
48
|
+
/** The part of the kernel's `ProgressReporter` the forwarding needs. */
|
|
49
|
+
interface KernelProgressSource {
|
|
50
|
+
on(event: 'progress', listener: (event: {
|
|
51
|
+
current: number;
|
|
52
|
+
total: number;
|
|
53
|
+
message?: string;
|
|
54
|
+
}) => void): unknown;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Forwards the kernel's progress events (parallel and incremental analysis)
|
|
58
|
+
* to `progress`. The reporter belongs to the call's own kernel, so the
|
|
59
|
+
* listener goes away with it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function forwardKernelProgress(reporter: KernelProgressSource | undefined, progress: ProgressFn): void;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=tool-context.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Minimum gap between two progress notifications. */
|
|
2
|
+
export const PROGRESS_INTERVAL_MS = 250;
|
|
3
|
+
/**
|
|
4
|
+
* Wraps `send` so it fires for the first value, for the last value
|
|
5
|
+
* (`progress >= total`) and otherwise at most once per `intervalMs`.
|
|
6
|
+
*/
|
|
7
|
+
export function throttleProgress(send, intervalMs = PROGRESS_INTERVAL_MS, now = Date.now) {
|
|
8
|
+
let last;
|
|
9
|
+
return (progress, total, message) => {
|
|
10
|
+
const time = now();
|
|
11
|
+
const isLast = total !== undefined && progress >= total;
|
|
12
|
+
if (last !== undefined && !isLast && time - last < intervalMs) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
last = time;
|
|
16
|
+
send(progress, total, message);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Gives the event loop one turn when the call can be cancelled, so a pending
|
|
21
|
+
* `notifications/cancelled` is read and `signal` aborts. Without a signal
|
|
22
|
+
* (direct calls, tests) it returns at once.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* Analysis is synchronous CPU work: while a loop runs, the server does not
|
|
26
|
+
* read stdin, so `notifications/cancelled` only arrives once the loop gives
|
|
27
|
+
* the event loop a turn. Long loops therefore call this once per file.
|
|
28
|
+
*/
|
|
29
|
+
export async function yieldIfCancellable(signal) {
|
|
30
|
+
if (signal === undefined) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
34
|
+
}
|
|
35
|
+
/** Progress message of a file loop: `12/40 files, 3 violations`. */
|
|
36
|
+
export function fileProgressMessage(analyzed, total, violations) {
|
|
37
|
+
return `${analyzed}/${total} files, ${violations} violation${violations === 1 ? '' : 's'}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `onFileAnalyzed` callback of a file loop that reports to `progress`;
|
|
41
|
+
* `undefined` without progress, so the loop does no extra work.
|
|
42
|
+
*/
|
|
43
|
+
export function fileProgress(progress) {
|
|
44
|
+
if (progress === undefined) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
return (analyzed, total, violations) => {
|
|
48
|
+
progress(analyzed, total, fileProgressMessage(analyzed, total, violations));
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Execution details of a scan the client cancelled after `analyzed` files.
|
|
53
|
+
* The SDK does not send the result of a cancelled request; it still has to
|
|
54
|
+
* be complete for direct callers (compare-health, tests).
|
|
55
|
+
*/
|
|
56
|
+
export function cancelledExecution(analyzed, skippedFiles, maxDurationMs) {
|
|
57
|
+
return {
|
|
58
|
+
...(maxDurationMs === undefined ? {} : { maxDurationMs }),
|
|
59
|
+
incomplete: true,
|
|
60
|
+
stopReason: 'cancelled',
|
|
61
|
+
skippedFiles,
|
|
62
|
+
ruleTimings: [],
|
|
63
|
+
note: `Scan cancelled after ${analyzed} file(s); ${skippedFiles} file(s) not analyzed.`,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Forwards the kernel's progress events (parallel and incremental analysis)
|
|
68
|
+
* to `progress`. The reporter belongs to the call's own kernel, so the
|
|
69
|
+
* listener goes away with it.
|
|
70
|
+
*/
|
|
71
|
+
export function forwardKernelProgress(reporter, progress) {
|
|
72
|
+
if (reporter === undefined) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
reporter.on('progress', (event) => {
|
|
76
|
+
progress(event.current, event.total, `${event.current}/${event.total} files`);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=tool-context.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety envelope shared by transform-code and rollback-changes: backups in
|
|
3
|
+
* the project (not in the server's working directory), one RollbackManager
|
|
4
|
+
* configuration for both tools, and the type check of a transformed file.
|
|
5
|
+
*/
|
|
6
|
+
import { type SourceFile } from 'ts-morph';
|
|
7
|
+
import { RollbackManager, RollbackStrategy } from '@angular-modernizer/core';
|
|
8
|
+
/**
|
|
9
|
+
* Backup directory name inside the project root.
|
|
10
|
+
*/
|
|
11
|
+
export declare const BACKUP_DIR_NAME = ".angular-modernizer-backups";
|
|
12
|
+
/**
|
|
13
|
+
* Backup directory of a project: the explicit one, else inside the project.
|
|
14
|
+
*/
|
|
15
|
+
export declare function projectBackupDir(projectRoot: string, backupDir?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* RollbackManager writing to and reading from the project's backup
|
|
18
|
+
* directory; git snapshots run in the project root.
|
|
19
|
+
*/
|
|
20
|
+
export declare function createProjectRollbackManager(projectRoot: string, options?: {
|
|
21
|
+
backupDir?: string;
|
|
22
|
+
strategy?: RollbackStrategy;
|
|
23
|
+
}): RollbackManager;
|
|
24
|
+
/**
|
|
25
|
+
* Nearest directory above a file that holds a tsconfig.json, package.json or
|
|
26
|
+
* .angular-modernizer.json; undefined when none exists up to the file system
|
|
27
|
+
* root.
|
|
28
|
+
*/
|
|
29
|
+
export declare function findProjectRootOf(filePath: string): string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Type errors of one file, as `TS<code>: <message>` without positions so the
|
|
32
|
+
* lists before and after a transformation can be compared.
|
|
33
|
+
*/
|
|
34
|
+
export declare function fileTypeErrors(sourceFile: SourceFile): string[];
|
|
35
|
+
/**
|
|
36
|
+
* Errors in `after` that `before` did not have (multiset difference): errors
|
|
37
|
+
* the file already had do not fail the transformation.
|
|
38
|
+
*/
|
|
39
|
+
export declare function introducedTypeErrors(before: readonly string[], after: readonly string[]): string[];
|
|
40
|
+
//# sourceMappingURL=transform-safety.d.ts.map
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safety envelope shared by transform-code and rollback-changes: backups in
|
|
3
|
+
* the project (not in the server's working directory), one RollbackManager
|
|
4
|
+
* configuration for both tools, and the type check of a transformed file.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from 'node:fs';
|
|
7
|
+
import { dirname, join, resolve } from 'node:path';
|
|
8
|
+
import { DiagnosticCategory } from 'ts-morph';
|
|
9
|
+
import { RollbackManager, RollbackStrategy } from '@angular-modernizer/core';
|
|
10
|
+
/**
|
|
11
|
+
* Backup directory name inside the project root.
|
|
12
|
+
*/
|
|
13
|
+
export const BACKUP_DIR_NAME = '.angular-modernizer-backups';
|
|
14
|
+
/**
|
|
15
|
+
* Backup directory of a project: the explicit one, else inside the project.
|
|
16
|
+
*/
|
|
17
|
+
export function projectBackupDir(projectRoot, backupDir) {
|
|
18
|
+
return backupDir ?? join(projectRoot, BACKUP_DIR_NAME);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* RollbackManager writing to and reading from the project's backup
|
|
22
|
+
* directory; git snapshots run in the project root.
|
|
23
|
+
*/
|
|
24
|
+
export function createProjectRollbackManager(projectRoot, options = {}) {
|
|
25
|
+
return new RollbackManager({
|
|
26
|
+
backupDir: projectBackupDir(projectRoot, options.backupDir),
|
|
27
|
+
gitRoot: projectRoot,
|
|
28
|
+
strategy: options.strategy ?? RollbackStrategy.AUTO,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Nearest directory above a file that holds a tsconfig.json, package.json or
|
|
33
|
+
* .angular-modernizer.json; undefined when none exists up to the file system
|
|
34
|
+
* root.
|
|
35
|
+
*/
|
|
36
|
+
export function findProjectRootOf(filePath) {
|
|
37
|
+
let dir = dirname(resolve(filePath));
|
|
38
|
+
for (;;) {
|
|
39
|
+
const marker = ['tsconfig.json', 'package.json', '.angular-modernizer.json']
|
|
40
|
+
.map((name) => join(dir, name))
|
|
41
|
+
.some((path) => existsSync(path));
|
|
42
|
+
if (marker) {
|
|
43
|
+
return dir;
|
|
44
|
+
}
|
|
45
|
+
const parent = dirname(dir);
|
|
46
|
+
if (parent === dir) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
dir = parent;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type errors of one file, as `TS<code>: <message>` without positions so the
|
|
54
|
+
* lists before and after a transformation can be compared.
|
|
55
|
+
*/
|
|
56
|
+
export function fileTypeErrors(sourceFile) {
|
|
57
|
+
return sourceFile
|
|
58
|
+
.getPreEmitDiagnostics()
|
|
59
|
+
.filter((d) => d.getCategory() === DiagnosticCategory.Error)
|
|
60
|
+
.map((d) => {
|
|
61
|
+
const message = d.getMessageText();
|
|
62
|
+
const text = typeof message === 'string' ? message : message.getMessageText();
|
|
63
|
+
return `TS${d.getCode()}: ${text}`;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Errors in `after` that `before` did not have (multiset difference): errors
|
|
68
|
+
* the file already had do not fail the transformation.
|
|
69
|
+
*/
|
|
70
|
+
export function introducedTypeErrors(before, after) {
|
|
71
|
+
const remaining = new Map();
|
|
72
|
+
for (const error of before) {
|
|
73
|
+
remaining.set(error, (remaining.get(error) ?? 0) + 1);
|
|
74
|
+
}
|
|
75
|
+
const introduced = [];
|
|
76
|
+
for (const error of after) {
|
|
77
|
+
const count = remaining.get(error) ?? 0;
|
|
78
|
+
if (count > 0) {
|
|
79
|
+
remaining.set(error, count - 1);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
introduced.push(error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return introduced;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=transform-safety.js.map
|