@angular-modernizer/api 0.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/LICENSE +21 -0
- package/README.md +507 -0
- package/dist/analysis/complexity-metrics-calculator.d.ts +99 -0
- package/dist/analysis/complexity-metrics-calculator.d.ts.map +1 -0
- package/dist/analysis/complexity-metrics-calculator.js +195 -0
- package/dist/analysis/complexity-metrics-calculator.js.map +1 -0
- package/dist/analysis/dependency-analyzer.d.ts +227 -0
- package/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/dist/analysis/dependency-analyzer.js +451 -0
- package/dist/analysis/dependency-analyzer.js.map +1 -0
- package/dist/analysis/external-template-loader.d.ts +44 -0
- package/dist/analysis/external-template-loader.d.ts.map +1 -0
- package/dist/analysis/external-template-loader.js +69 -0
- package/dist/analysis/external-template-loader.js.map +1 -0
- package/dist/analysis/selector-mapper.d.ts +77 -0
- package/dist/analysis/selector-mapper.d.ts.map +1 -0
- package/dist/analysis/selector-mapper.js +146 -0
- package/dist/analysis/selector-mapper.js.map +1 -0
- package/dist/analysis/service-detector.d.ts +164 -0
- package/dist/analysis/service-detector.d.ts.map +1 -0
- package/dist/analysis/service-detector.js +231 -0
- package/dist/analysis/service-detector.js.map +1 -0
- package/dist/analysis/service-pattern-recognizer.d.ts +247 -0
- package/dist/analysis/service-pattern-recognizer.d.ts.map +1 -0
- package/dist/analysis/service-pattern-recognizer.js +444 -0
- package/dist/analysis/service-pattern-recognizer.js.map +1 -0
- package/dist/analysis/symbol-locator.d.ts +81 -0
- package/dist/analysis/symbol-locator.d.ts.map +1 -0
- package/dist/analysis/symbol-locator.js +128 -0
- package/dist/analysis/symbol-locator.js.map +1 -0
- package/dist/analysis/template-analyzer-usage.d.ts +144 -0
- package/dist/analysis/template-analyzer-usage.d.ts.map +1 -0
- package/dist/analysis/template-analyzer-usage.js +474 -0
- package/dist/analysis/template-analyzer-usage.js.map +1 -0
- package/dist/analysis/template-analyzer.d.ts +80 -0
- package/dist/analysis/template-analyzer.d.ts.map +1 -0
- package/dist/analysis/template-analyzer.js +146 -0
- package/dist/analysis/template-analyzer.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/investigation/angular-symbol-finder.d.ts +76 -0
- package/dist/investigation/angular-symbol-finder.d.ts.map +1 -0
- package/dist/investigation/angular-symbol-finder.js +199 -0
- package/dist/investigation/angular-symbol-finder.js.map +1 -0
- package/dist/investigation/call-graph-builder.d.ts +85 -0
- package/dist/investigation/call-graph-builder.d.ts.map +1 -0
- package/dist/investigation/call-graph-builder.js +196 -0
- package/dist/investigation/call-graph-builder.js.map +1 -0
- package/dist/investigation/codebase-searcher.d.ts +99 -0
- package/dist/investigation/codebase-searcher.d.ts.map +1 -0
- package/dist/investigation/codebase-searcher.js +201 -0
- package/dist/investigation/codebase-searcher.js.map +1 -0
- package/dist/investigation/stack-trace-parser.d.ts +70 -0
- package/dist/investigation/stack-trace-parser.d.ts.map +1 -0
- package/dist/investigation/stack-trace-parser.js +117 -0
- package/dist/investigation/stack-trace-parser.js.map +1 -0
- package/dist/investigation/type-resolver.d.ts +59 -0
- package/dist/investigation/type-resolver.d.ts.map +1 -0
- package/dist/investigation/type-resolver.js +111 -0
- package/dist/investigation/type-resolver.js.map +1 -0
- package/dist/investigation/usage-finder.d.ts +69 -0
- package/dist/investigation/usage-finder.d.ts.map +1 -0
- package/dist/investigation/usage-finder.js +132 -0
- package/dist/investigation/usage-finder.js.map +1 -0
- package/dist/metrics/complexity-metrics.d.ts +196 -0
- package/dist/metrics/complexity-metrics.d.ts.map +1 -0
- package/dist/metrics/complexity-metrics.js +445 -0
- package/dist/metrics/complexity-metrics.js.map +1 -0
- package/dist/public-api.d.ts +77 -0
- package/dist/public-api.d.ts.map +1 -0
- package/dist/public-api.js +50 -0
- package/dist/public-api.js.map +1 -0
- package/dist/transformation/import-manager.d.ts +276 -0
- package/dist/transformation/import-manager.d.ts.map +1 -0
- package/dist/transformation/import-manager.js +488 -0
- package/dist/transformation/import-manager.js.map +1 -0
- package/dist/transformation/ng-morph-adapter.d.ts +111 -0
- package/dist/transformation/ng-morph-adapter.d.ts.map +1 -0
- package/dist/transformation/ng-morph-adapter.js +179 -0
- package/dist/transformation/ng-morph-adapter.js.map +1 -0
- package/dist/transformation/ngmodule-manager.d.ts +145 -0
- package/dist/transformation/ngmodule-manager.d.ts.map +1 -0
- package/dist/transformation/ngmodule-manager.js +356 -0
- package/dist/transformation/ngmodule-manager.js.map +1 -0
- package/package.json +62 -0
- package/src/analysis/complexity-metrics-calculator.ts +253 -0
- package/src/analysis/dependency-analyzer.ts +720 -0
- package/src/analysis/external-template-loader.ts +79 -0
- package/src/analysis/selector-mapper.ts +186 -0
- package/src/analysis/service-detector.ts +280 -0
- package/src/analysis/service-pattern-recognizer.ts +545 -0
- package/src/analysis/symbol-locator.ts +170 -0
- package/src/analysis/template-analyzer-usage.ts +614 -0
- package/src/analysis/template-analyzer.ts +208 -0
- package/src/index.ts +51 -0
- package/src/investigation/angular-symbol-finder.ts +263 -0
- package/src/investigation/call-graph-builder.ts +298 -0
- package/src/investigation/codebase-searcher.ts +286 -0
- package/src/investigation/stack-trace-parser.ts +166 -0
- package/src/investigation/type-resolver.ts +144 -0
- package/src/investigation/usage-finder.ts +198 -0
- package/src/metrics/complexity-metrics.ts +617 -0
- package/src/public-api.ts +119 -0
- package/src/transformation/import-manager.ts +626 -0
- package/src/transformation/ng-morph-adapter.ts +252 -0
- package/src/transformation/ngmodule-manager.ts +450 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/api - Complexity Metrics Calculator
|
|
3
|
+
*
|
|
4
|
+
* Calculates code complexity and maintainability metrics for Angular applications.
|
|
5
|
+
* Provides quantitative measures to prioritize refactoring efforts.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Complexity Metrics Calculator - analyzes code complexity and maintainability.
|
|
9
|
+
*/
|
|
10
|
+
export class ComplexityMetricsCalculator {
|
|
11
|
+
/**
|
|
12
|
+
* Calculate overall complexity score for a class (0-100 scale).
|
|
13
|
+
* Custom weighted heuristic combining established metrics (McCabe's Cyclomatic Complexity,
|
|
14
|
+
* LOC, method count from CK metrics) with Angular-specific indicators.
|
|
15
|
+
*
|
|
16
|
+
* Combines multiple metrics:
|
|
17
|
+
* - Cyclomatic complexity
|
|
18
|
+
* - Lines of code
|
|
19
|
+
* - Method count
|
|
20
|
+
* - Angular-specific complexity
|
|
21
|
+
*
|
|
22
|
+
* @param classDecl - The class declaration to analyze
|
|
23
|
+
* @returns Complexity score (0-100)
|
|
24
|
+
*/
|
|
25
|
+
calculateOverallComplexity(classDecl) {
|
|
26
|
+
const cyclomatic = this.calculateCyclomaticComplexity(classDecl);
|
|
27
|
+
const loc = this.calculateLOC(classDecl.getSourceFile());
|
|
28
|
+
const methods = this.calculateMethodCount(classDecl);
|
|
29
|
+
const angularMetrics = this.calculateAngularSpecificMetrics(classDecl);
|
|
30
|
+
// Weighted formula for overall complexity - Weights empirically tuned for Angular applications:
|
|
31
|
+
// - 40%: Cyclomatic complexity (McCabe, 1976) - control flow decision points
|
|
32
|
+
// - 20%: Lines of code (÷10 normalization) - file size indicator
|
|
33
|
+
// - 20%: Method count (×2 amplification) - class size indicator (inspired by WMC from CK metrics)
|
|
34
|
+
// - 20%: Angular features (×1.5 weight) - framework coupling (lifecycle hooks, @Input, @Output)
|
|
35
|
+
// Returns 0-100 scale for prioritizing refactoring efforts.
|
|
36
|
+
const score = cyclomatic * 0.4 +
|
|
37
|
+
(loc / 10) * 0.2 +
|
|
38
|
+
methods * 2 * 0.2 +
|
|
39
|
+
(angularMetrics.lifecycleHooks +
|
|
40
|
+
angularMetrics.inputs +
|
|
41
|
+
angularMetrics.outputs) *
|
|
42
|
+
1.5 *
|
|
43
|
+
0.2;
|
|
44
|
+
return Math.min(100, Math.max(0, score));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Calculate cyclomatic complexity for a class.
|
|
48
|
+
*
|
|
49
|
+
* Measures the number of linearly independent paths through the code.
|
|
50
|
+
* Higher values indicate more complex control flow.
|
|
51
|
+
*
|
|
52
|
+
* @param classDecl - The class declaration
|
|
53
|
+
* @returns Cyclomatic complexity score
|
|
54
|
+
*/
|
|
55
|
+
calculateCyclomaticComplexity(classDecl) {
|
|
56
|
+
let complexity = 1; // Base complexity
|
|
57
|
+
const methods = classDecl.getMethods();
|
|
58
|
+
for (const method of methods) {
|
|
59
|
+
complexity += this.calculateMethodComplexity(method);
|
|
60
|
+
}
|
|
61
|
+
return complexity;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Calculate cyclomatic complexity for a single method.
|
|
65
|
+
* Implements McCabe's algorithm by counting decision points:
|
|
66
|
+
* if/else if, loops, switch cases, ternary operators, logical operators.
|
|
67
|
+
*/
|
|
68
|
+
calculateMethodComplexity(method) {
|
|
69
|
+
let complexity = 1; // Base complexity
|
|
70
|
+
const patterns = [
|
|
71
|
+
{ regex: /\bif\s*\(/g, description: 'if statements' },
|
|
72
|
+
{ regex: /\b(for|while|do)\s*\(/g, description: 'loops' },
|
|
73
|
+
{ regex: /\bcase\s+/g, description: 'switch cases' },
|
|
74
|
+
{ regex: /\?/g, description: 'ternary operators' },
|
|
75
|
+
{ regex: /(&&|\|\|)/g, description: 'logical operators' },
|
|
76
|
+
];
|
|
77
|
+
const statements = method.getStatements();
|
|
78
|
+
statements.forEach((statement) => {
|
|
79
|
+
const text = statement.getText();
|
|
80
|
+
patterns.forEach(({ regex }) => {
|
|
81
|
+
const matches = text.match(regex);
|
|
82
|
+
complexity += matches?.length ?? 0;
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return complexity;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Calculate lines of code for a source file.
|
|
89
|
+
*
|
|
90
|
+
* Excludes comments and whitespace for meaningful LOC count.
|
|
91
|
+
*
|
|
92
|
+
* @param sourceFile - The source file
|
|
93
|
+
* @returns Number of lines of code
|
|
94
|
+
*/
|
|
95
|
+
calculateLOC(sourceFile) {
|
|
96
|
+
const text = sourceFile.getText();
|
|
97
|
+
const lines = text.split('\n');
|
|
98
|
+
let loc = 0;
|
|
99
|
+
for (const line of lines) {
|
|
100
|
+
const trimmed = line.trim();
|
|
101
|
+
// Count non-empty, non-comment lines
|
|
102
|
+
if (trimmed &&
|
|
103
|
+
!trimmed.startsWith('//') &&
|
|
104
|
+
!trimmed.startsWith('/*') &&
|
|
105
|
+
!trimmed.startsWith('*')) {
|
|
106
|
+
loc++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return loc;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Calculate the number of methods in a class.
|
|
113
|
+
*
|
|
114
|
+
* @param classDecl - The class declaration
|
|
115
|
+
* @returns Number of methods
|
|
116
|
+
*/
|
|
117
|
+
calculateMethodCount(classDecl) {
|
|
118
|
+
return classDecl.getMethods().length;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Calculate dependency count for a source file.
|
|
122
|
+
*
|
|
123
|
+
* Counts unique external dependencies (imports from node_modules).
|
|
124
|
+
*
|
|
125
|
+
* @param sourceFile - The source file
|
|
126
|
+
* @returns Number of unique dependencies
|
|
127
|
+
*/
|
|
128
|
+
calculateDependencyCount(sourceFile) {
|
|
129
|
+
const importDeclarations = sourceFile.getImportDeclarations();
|
|
130
|
+
const dependencies = new Set();
|
|
131
|
+
for (const importDecl of importDeclarations) {
|
|
132
|
+
const moduleSpecifier = importDecl.getModuleSpecifierValue();
|
|
133
|
+
// Only count external dependencies (not relative imports)
|
|
134
|
+
if (!moduleSpecifier.startsWith('.') &&
|
|
135
|
+
!moduleSpecifier.startsWith('/')) {
|
|
136
|
+
dependencies.add(moduleSpecifier);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return dependencies.size;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Calculate Angular-specific metrics for a class.
|
|
143
|
+
*
|
|
144
|
+
* Analyzes Angular decorators and patterns.
|
|
145
|
+
*
|
|
146
|
+
* @param classDecl - The class declaration
|
|
147
|
+
* @returns Angular-specific metrics
|
|
148
|
+
*/
|
|
149
|
+
calculateAngularSpecificMetrics(classDecl) {
|
|
150
|
+
const metrics = { lifecycleHooks: 0, inputs: 0, outputs: 0, decorators: 0 };
|
|
151
|
+
const lifecycleHookNames = new Set([
|
|
152
|
+
'ngOnInit',
|
|
153
|
+
'ngOnDestroy',
|
|
154
|
+
'ngOnChanges',
|
|
155
|
+
'ngDoCheck',
|
|
156
|
+
'ngAfterContentInit',
|
|
157
|
+
'ngAfterContentChecked',
|
|
158
|
+
'ngAfterViewInit',
|
|
159
|
+
'ngAfterViewChecked',
|
|
160
|
+
]);
|
|
161
|
+
const countIODecorators = (decorators) => {
|
|
162
|
+
decorators.forEach((decorator) => {
|
|
163
|
+
const name = decorator.getName();
|
|
164
|
+
if (name === 'Input') {
|
|
165
|
+
metrics.inputs++;
|
|
166
|
+
}
|
|
167
|
+
if (name === 'Output') {
|
|
168
|
+
metrics.outputs++;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
classDecl.getDecorators().forEach((decorator) => {
|
|
173
|
+
const name = decorator.getName();
|
|
174
|
+
metrics.decorators++;
|
|
175
|
+
if (name === 'Component' || name === 'Directive') {
|
|
176
|
+
// Count lifecycle hook methods
|
|
177
|
+
classDecl.getMethods().forEach((method) => {
|
|
178
|
+
if (lifecycleHookNames.has(method.getName())) {
|
|
179
|
+
metrics.lifecycleHooks++;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
// Count @Input and @Output on properties
|
|
183
|
+
classDecl.getProperties().forEach((prop) => {
|
|
184
|
+
countIODecorators(prop.getDecorators());
|
|
185
|
+
});
|
|
186
|
+
// Count @Input/@Output on setters
|
|
187
|
+
classDecl.getSetAccessors().forEach((setter) => {
|
|
188
|
+
countIODecorators(setter.getDecorators());
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return metrics;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=complexity-metrics-calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complexity-metrics-calculator.js","sourceRoot":"","sources":["../../src/analysis/complexity-metrics-calculator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH;;GAEG;AACH,MAAM,OAAO,2BAA2B;IACtC;;;;;;;;;;;;;OAaG;IACH,0BAA0B,CAAC,SAA2B;QACpD,MAAM,UAAU,GAAG,IAAI,CAAC,6BAA6B,CAAC,SAAS,CAAC,CAAC;QACjE,MAAM,GAAG,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;QACrD,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CAAC,SAAS,CAAC,CAAC;QAEvE,gGAAgG;QAChG,6EAA6E;QAC7E,iEAAiE;QACjE,kGAAkG;QAClG,gGAAgG;QAChG,4DAA4D;QAC5D,MAAM,KAAK,GACT,UAAU,GAAG,GAAG;YAChB,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;YAChB,OAAO,GAAG,CAAC,GAAG,GAAG;YACjB,CAAC,cAAc,CAAC,cAAc;gBAC5B,cAAc,CAAC,MAAM;gBACrB,cAAc,CAAC,OAAO,CAAC;gBACvB,GAAG;gBACH,GAAG,CAAC;QAER,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;OAQG;IACH,6BAA6B,CAAC,SAA2B;QACvD,IAA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C,CAAC,CAAC;gBAEH,kCAAkC;gBAClC,SAAS,CAAC,eAAe,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;oBAC7C,iBAAiB,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;gBAC5C,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/api - Dependency Analyzer
|
|
3
|
+
*
|
|
4
|
+
* The "All-Knowing Cartographer" - builds comprehensive symbol maps for Angular modules.
|
|
5
|
+
* Recursively walks NgModule imports to create a complete map of available symbols.
|
|
6
|
+
*
|
|
7
|
+
* Philosophy: "Trust the Map"
|
|
8
|
+
* - Builds the definitive map of what's available in a module's scope
|
|
9
|
+
* - Handles the critical edge case: `` on setters with aliases
|
|
10
|
+
* - Plugins use this map to make intelligent decisions
|
|
11
|
+
*/
|
|
12
|
+
import type { SourceFile, Project } from 'ts-morph';
|
|
13
|
+
/**
|
|
14
|
+
* Represents a dependency between two artifacts.
|
|
15
|
+
*/
|
|
16
|
+
export interface Dependency {
|
|
17
|
+
/**
|
|
18
|
+
* Source file path.
|
|
19
|
+
*/
|
|
20
|
+
from: string;
|
|
21
|
+
/**
|
|
22
|
+
* Target file path.
|
|
23
|
+
*/
|
|
24
|
+
to: string;
|
|
25
|
+
/**
|
|
26
|
+
* Type of dependency.
|
|
27
|
+
*/
|
|
28
|
+
type: 'import' | 'component-usage' | 'directive-usage' | 'service-injection';
|
|
29
|
+
/**
|
|
30
|
+
* Symbol name being used.
|
|
31
|
+
*/
|
|
32
|
+
symbol?: string;
|
|
33
|
+
/**
|
|
34
|
+
* Additional metadata.
|
|
35
|
+
*/
|
|
36
|
+
metadata?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Represents a symbol in the Angular module system.
|
|
40
|
+
*/
|
|
41
|
+
export interface SymbolInfo {
|
|
42
|
+
/**
|
|
43
|
+
* Class name of the symbol.
|
|
44
|
+
*/
|
|
45
|
+
className: string;
|
|
46
|
+
/**
|
|
47
|
+
* Selector(s) for components/directives.
|
|
48
|
+
* For components: ['app-root']
|
|
49
|
+
* For directives: ['[myDirective]', 'myDirective']
|
|
50
|
+
*/
|
|
51
|
+
selectors: string[];
|
|
52
|
+
/**
|
|
53
|
+
* Input property names (including aliases).
|
|
54
|
+
* For ``('customValue') set value(...), this includes 'customValue'.
|
|
55
|
+
*/
|
|
56
|
+
inputs: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Output property names (including aliases).
|
|
59
|
+
*/
|
|
60
|
+
outputs: string[];
|
|
61
|
+
/**
|
|
62
|
+
* Type of Angular artifact.
|
|
63
|
+
*/
|
|
64
|
+
type: 'component' | 'directive' | 'pipe' | 'module';
|
|
65
|
+
/**
|
|
66
|
+
* Source file path.
|
|
67
|
+
*/
|
|
68
|
+
filePath: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Complete symbol map for a module's scope.
|
|
72
|
+
*/
|
|
73
|
+
export interface SymbolMap {
|
|
74
|
+
/**
|
|
75
|
+
* Symbols declared in this module.
|
|
76
|
+
*/
|
|
77
|
+
declared: Map<string, SymbolInfo>;
|
|
78
|
+
/**
|
|
79
|
+
* Symbols imported into this module (from other modules).
|
|
80
|
+
*/
|
|
81
|
+
imported: Map<string, SymbolInfo>;
|
|
82
|
+
/**
|
|
83
|
+
* Symbols exported by this module (available to consumers).
|
|
84
|
+
*/
|
|
85
|
+
exported: Map<string, SymbolInfo>;
|
|
86
|
+
/**
|
|
87
|
+
* All effectively available symbols in this module's scope.
|
|
88
|
+
* This is the union of declared + imported symbols.
|
|
89
|
+
*/
|
|
90
|
+
available: Map<string, SymbolInfo>;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Dependency Analyzer - extracts dependency relationships and builds symbol maps.
|
|
94
|
+
*
|
|
95
|
+
* This is the "All-Knowing Cartographer" that creates comprehensive maps of
|
|
96
|
+
* what's available in an NgModule's scope.
|
|
97
|
+
*/
|
|
98
|
+
export declare class DependencyAnalyzer {
|
|
99
|
+
/**
|
|
100
|
+
* Analyze all dependencies from a source file.
|
|
101
|
+
* Extracts all named imports and creates dependency objects for each.
|
|
102
|
+
*
|
|
103
|
+
* @param sourceFile - The source file to analyze
|
|
104
|
+
* @returns Array of dependencies
|
|
105
|
+
*/
|
|
106
|
+
analyzeDependencies(sourceFile: SourceFile): Dependency[];
|
|
107
|
+
/**
|
|
108
|
+
* Check if a file depends on another file.
|
|
109
|
+
*
|
|
110
|
+
* @param sourceFile - The source file
|
|
111
|
+
* @param targetPath - The target file path
|
|
112
|
+
* @returns True if dependency exists
|
|
113
|
+
*/
|
|
114
|
+
dependsOn(sourceFile: SourceFile, targetPath: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Build a comprehensive symbol map for an NgModule.
|
|
117
|
+
*
|
|
118
|
+
* This is the heart of the "Trust the Map" architecture.
|
|
119
|
+
* It creates the definitive map of what's available in a module's scope.
|
|
120
|
+
*
|
|
121
|
+
* @param moduleFile - The source file containing the NgModule
|
|
122
|
+
* @param project - Optional ts-morph Project to resolve symbols across files
|
|
123
|
+
* @returns Complete symbol map
|
|
124
|
+
*/
|
|
125
|
+
buildSymbolMap(moduleFile: SourceFile, project?: Project): SymbolMap;
|
|
126
|
+
/**
|
|
127
|
+
* Load exported symbols from an imported module.
|
|
128
|
+
* Recursively resolves module imports to build complete symbol map.
|
|
129
|
+
*
|
|
130
|
+
* @param moduleName - The module class name to load
|
|
131
|
+
* @param project - The ts-morph project
|
|
132
|
+
* @param _currentFile - The current source file (reserved for future use in resolving relative imports)
|
|
133
|
+
* @returns Map of exported symbols
|
|
134
|
+
*/
|
|
135
|
+
private loadModuleExports;
|
|
136
|
+
/**
|
|
137
|
+
* Get all transitive dependencies for a source file.
|
|
138
|
+
* Follows dependency chain recursively.
|
|
139
|
+
*
|
|
140
|
+
* @param sourceFile - The source file
|
|
141
|
+
* @param project - The ts-morph project
|
|
142
|
+
* @param visited - Set of already visited files (for cycle detection)
|
|
143
|
+
* @returns Array of all transitive dependencies
|
|
144
|
+
*/
|
|
145
|
+
getTransitiveDependencies(sourceFile: SourceFile, project: Project, visited?: Set<string>): Dependency[];
|
|
146
|
+
/**
|
|
147
|
+
* Detect circular dependencies in a project.
|
|
148
|
+
*
|
|
149
|
+
* @param project - The ts-morph project
|
|
150
|
+
* @returns Array of circular dependency chains
|
|
151
|
+
*/
|
|
152
|
+
detectCircularDependencies(project: Project): {
|
|
153
|
+
cycle: string[];
|
|
154
|
+
severity: 'warning' | 'error';
|
|
155
|
+
}[];
|
|
156
|
+
/**
|
|
157
|
+
* Detect cycles starting from a specific file.
|
|
158
|
+
* Recursively traverses local dependencies to find circular import chains.
|
|
159
|
+
* Severity based on cycle length: >3 files = error, ≤3 files = warning.
|
|
160
|
+
*/
|
|
161
|
+
private detectCyclesFromFile;
|
|
162
|
+
/**
|
|
163
|
+
* Deduplicate cycle arrays (same cycle in different order).
|
|
164
|
+
* Example: [A→B→C→A] and [B→C→A→B] represent the same cycle.
|
|
165
|
+
* Uses sorted paths to create unique signatures for comparison.
|
|
166
|
+
*/
|
|
167
|
+
private deduplicateCycles;
|
|
168
|
+
/**
|
|
169
|
+
* Extract comprehensive symbol information from a class.
|
|
170
|
+
* Identifies Angular artifact types (``, ``, ``) and extracts metadata.
|
|
171
|
+
*
|
|
172
|
+
* CRITICAL: Handles the edge case of `` on setters with aliases.
|
|
173
|
+
*
|
|
174
|
+
* @param sourceFile - The source file
|
|
175
|
+
* @param className - The class name to analyze
|
|
176
|
+
* @returns Symbol information or undefined
|
|
177
|
+
*/
|
|
178
|
+
extractSymbolInfo(sourceFile: SourceFile, className: string): SymbolInfo | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Extract component information including selectors and inputs.
|
|
181
|
+
*/
|
|
182
|
+
private extractComponentInfo;
|
|
183
|
+
/**
|
|
184
|
+
* Extract directive information including selectors and inputs.
|
|
185
|
+
*/
|
|
186
|
+
private extractDirectiveInfo;
|
|
187
|
+
/**
|
|
188
|
+
* Extract pipe information.
|
|
189
|
+
*/
|
|
190
|
+
private extractPipeInfo;
|
|
191
|
+
/**
|
|
192
|
+
* Extract all `` properties from a class.
|
|
193
|
+
*
|
|
194
|
+
* CRITICAL: Handles the edge case of `` on setters with aliases.
|
|
195
|
+
* Example: ``('customValue') set value(val: any) { ... }
|
|
196
|
+
* This should extract 'customValue', not 'value'.
|
|
197
|
+
*/
|
|
198
|
+
private extractInputs;
|
|
199
|
+
/**
|
|
200
|
+
* Extract all `` properties from a class.
|
|
201
|
+
*/
|
|
202
|
+
private extractOutputs;
|
|
203
|
+
/**
|
|
204
|
+
* Extract alias from a decorator.
|
|
205
|
+
* Example: ``('customValue') -> 'customValue'
|
|
206
|
+
*/
|
|
207
|
+
private extractDecoratorAlias;
|
|
208
|
+
/**
|
|
209
|
+
* Find a decorator on a node by name.
|
|
210
|
+
*/
|
|
211
|
+
private findDecorator;
|
|
212
|
+
/**
|
|
213
|
+
* Find the NgModule class in a source file.
|
|
214
|
+
*/
|
|
215
|
+
private findNgModuleClass;
|
|
216
|
+
/**
|
|
217
|
+
* Extract a string property value from decorator text.
|
|
218
|
+
* Example: selector: 'app-root' -> 'app-root'
|
|
219
|
+
*/
|
|
220
|
+
private extractStringProperty;
|
|
221
|
+
/**
|
|
222
|
+
* Extract an array property value from decorator text.
|
|
223
|
+
* Example: declarations: [Foo, Bar] -> ['Foo', 'Bar']
|
|
224
|
+
*/
|
|
225
|
+
private extractArrayProperty;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=dependency-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-analyzer.d.ts","sourceRoot":"","sources":["../../src/analysis/dependency-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAA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