@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +507 -0
  3. package/dist/analysis/complexity-metrics-calculator.d.ts +99 -0
  4. package/dist/analysis/complexity-metrics-calculator.d.ts.map +1 -0
  5. package/dist/analysis/complexity-metrics-calculator.js +195 -0
  6. package/dist/analysis/complexity-metrics-calculator.js.map +1 -0
  7. package/dist/analysis/dependency-analyzer.d.ts +227 -0
  8. package/dist/analysis/dependency-analyzer.d.ts.map +1 -0
  9. package/dist/analysis/dependency-analyzer.js +451 -0
  10. package/dist/analysis/dependency-analyzer.js.map +1 -0
  11. package/dist/analysis/external-template-loader.d.ts +44 -0
  12. package/dist/analysis/external-template-loader.d.ts.map +1 -0
  13. package/dist/analysis/external-template-loader.js +69 -0
  14. package/dist/analysis/external-template-loader.js.map +1 -0
  15. package/dist/analysis/selector-mapper.d.ts +77 -0
  16. package/dist/analysis/selector-mapper.d.ts.map +1 -0
  17. package/dist/analysis/selector-mapper.js +146 -0
  18. package/dist/analysis/selector-mapper.js.map +1 -0
  19. package/dist/analysis/service-detector.d.ts +164 -0
  20. package/dist/analysis/service-detector.d.ts.map +1 -0
  21. package/dist/analysis/service-detector.js +231 -0
  22. package/dist/analysis/service-detector.js.map +1 -0
  23. package/dist/analysis/service-pattern-recognizer.d.ts +247 -0
  24. package/dist/analysis/service-pattern-recognizer.d.ts.map +1 -0
  25. package/dist/analysis/service-pattern-recognizer.js +444 -0
  26. package/dist/analysis/service-pattern-recognizer.js.map +1 -0
  27. package/dist/analysis/symbol-locator.d.ts +81 -0
  28. package/dist/analysis/symbol-locator.d.ts.map +1 -0
  29. package/dist/analysis/symbol-locator.js +128 -0
  30. package/dist/analysis/symbol-locator.js.map +1 -0
  31. package/dist/analysis/template-analyzer-usage.d.ts +144 -0
  32. package/dist/analysis/template-analyzer-usage.d.ts.map +1 -0
  33. package/dist/analysis/template-analyzer-usage.js +474 -0
  34. package/dist/analysis/template-analyzer-usage.js.map +1 -0
  35. package/dist/analysis/template-analyzer.d.ts +80 -0
  36. package/dist/analysis/template-analyzer.d.ts.map +1 -0
  37. package/dist/analysis/template-analyzer.js +146 -0
  38. package/dist/analysis/template-analyzer.js.map +1 -0
  39. package/dist/index.d.ts +23 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +22 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/investigation/angular-symbol-finder.d.ts +76 -0
  44. package/dist/investigation/angular-symbol-finder.d.ts.map +1 -0
  45. package/dist/investigation/angular-symbol-finder.js +199 -0
  46. package/dist/investigation/angular-symbol-finder.js.map +1 -0
  47. package/dist/investigation/call-graph-builder.d.ts +85 -0
  48. package/dist/investigation/call-graph-builder.d.ts.map +1 -0
  49. package/dist/investigation/call-graph-builder.js +196 -0
  50. package/dist/investigation/call-graph-builder.js.map +1 -0
  51. package/dist/investigation/codebase-searcher.d.ts +99 -0
  52. package/dist/investigation/codebase-searcher.d.ts.map +1 -0
  53. package/dist/investigation/codebase-searcher.js +201 -0
  54. package/dist/investigation/codebase-searcher.js.map +1 -0
  55. package/dist/investigation/stack-trace-parser.d.ts +70 -0
  56. package/dist/investigation/stack-trace-parser.d.ts.map +1 -0
  57. package/dist/investigation/stack-trace-parser.js +117 -0
  58. package/dist/investigation/stack-trace-parser.js.map +1 -0
  59. package/dist/investigation/type-resolver.d.ts +59 -0
  60. package/dist/investigation/type-resolver.d.ts.map +1 -0
  61. package/dist/investigation/type-resolver.js +111 -0
  62. package/dist/investigation/type-resolver.js.map +1 -0
  63. package/dist/investigation/usage-finder.d.ts +69 -0
  64. package/dist/investigation/usage-finder.d.ts.map +1 -0
  65. package/dist/investigation/usage-finder.js +132 -0
  66. package/dist/investigation/usage-finder.js.map +1 -0
  67. package/dist/metrics/complexity-metrics.d.ts +196 -0
  68. package/dist/metrics/complexity-metrics.d.ts.map +1 -0
  69. package/dist/metrics/complexity-metrics.js +445 -0
  70. package/dist/metrics/complexity-metrics.js.map +1 -0
  71. package/dist/public-api.d.ts +77 -0
  72. package/dist/public-api.d.ts.map +1 -0
  73. package/dist/public-api.js +50 -0
  74. package/dist/public-api.js.map +1 -0
  75. package/dist/transformation/import-manager.d.ts +276 -0
  76. package/dist/transformation/import-manager.d.ts.map +1 -0
  77. package/dist/transformation/import-manager.js +488 -0
  78. package/dist/transformation/import-manager.js.map +1 -0
  79. package/dist/transformation/ng-morph-adapter.d.ts +111 -0
  80. package/dist/transformation/ng-morph-adapter.d.ts.map +1 -0
  81. package/dist/transformation/ng-morph-adapter.js +179 -0
  82. package/dist/transformation/ng-morph-adapter.js.map +1 -0
  83. package/dist/transformation/ngmodule-manager.d.ts +145 -0
  84. package/dist/transformation/ngmodule-manager.d.ts.map +1 -0
  85. package/dist/transformation/ngmodule-manager.js +356 -0
  86. package/dist/transformation/ngmodule-manager.js.map +1 -0
  87. package/package.json +62 -0
  88. package/src/analysis/complexity-metrics-calculator.ts +253 -0
  89. package/src/analysis/dependency-analyzer.ts +720 -0
  90. package/src/analysis/external-template-loader.ts +79 -0
  91. package/src/analysis/selector-mapper.ts +186 -0
  92. package/src/analysis/service-detector.ts +280 -0
  93. package/src/analysis/service-pattern-recognizer.ts +545 -0
  94. package/src/analysis/symbol-locator.ts +170 -0
  95. package/src/analysis/template-analyzer-usage.ts +614 -0
  96. package/src/analysis/template-analyzer.ts +208 -0
  97. package/src/index.ts +51 -0
  98. package/src/investigation/angular-symbol-finder.ts +263 -0
  99. package/src/investigation/call-graph-builder.ts +298 -0
  100. package/src/investigation/codebase-searcher.ts +286 -0
  101. package/src/investigation/stack-trace-parser.ts +166 -0
  102. package/src/investigation/type-resolver.ts +144 -0
  103. package/src/investigation/usage-finder.ts +198 -0
  104. package/src/metrics/complexity-metrics.ts +617 -0
  105. package/src/public-api.ts +119 -0
  106. package/src/transformation/import-manager.ts +626 -0
  107. package/src/transformation/ng-morph-adapter.ts +252 -0
  108. package/src/transformation/ngmodule-manager.ts +450 -0
@@ -0,0 +1,179 @@
1
+ /**
2
+ * NgMorphAdapter - Wrapper around ng-morph for Angular-specific AST operations
3
+ *
4
+ * This adapter provides a simplified interface to ng-morph functionality while
5
+ * maintaining compatibility with our existing ts-morph-based infrastructure.
6
+ */
7
+ import { getNgComponents, getNgModules, findNgModule, addImportToNgModule, addDeclarationToNgModule, addImportToComponent, addProviderToComponent, } from 'ng-morph';
8
+ /**
9
+ * Adapter for ng-morph that integrates with our ts-morph Project
10
+ */
11
+ export class NgMorphAdapter {
12
+ project;
13
+ pattern;
14
+ constructor(options) {
15
+ this.project = options.project;
16
+ this.pattern = options.pattern ?? '**/*.ts';
17
+ }
18
+ /**
19
+ * Get all Angular components matching a pattern
20
+ */
21
+ getComponents(pattern) {
22
+ return getNgComponents(pattern ?? this.pattern);
23
+ }
24
+ /**
25
+ * Get a specific component by file path
26
+ */
27
+ getComponent(filePath) {
28
+ const sourceFile = this.project.getSourceFile(filePath);
29
+ if (!sourceFile) {
30
+ return undefined;
31
+ }
32
+ const components = getNgComponents(filePath);
33
+ return components[0]; // Return first component in file
34
+ }
35
+ /**
36
+ * Get all Angular modules matching a pattern
37
+ */
38
+ getModules(pattern) {
39
+ return getNgModules(pattern ?? this.pattern);
40
+ }
41
+ /**
42
+ * Get a specific module by file path
43
+ */
44
+ getModule(filePath) {
45
+ const sourceFile = this.project.getSourceFile(filePath);
46
+ if (!sourceFile) {
47
+ return undefined;
48
+ }
49
+ const modules = getNgModules(filePath);
50
+ return modules[0]; // Return first module in file
51
+ }
52
+ /**
53
+ * Find the NgModule that declares a component
54
+ */
55
+ findModuleForComponent(component) {
56
+ return findNgModule(component, this.pattern);
57
+ }
58
+ /**
59
+ * Add an import to an NgModule
60
+ * @param moduleClass - The NgModule class declaration
61
+ * @param moduleName - Name of the module to import (e.g., 'CommonModule')
62
+ * @param options - Optional configuration
63
+ */
64
+ addImportToModule(moduleClass, moduleName, options) {
65
+ addImportToNgModule(moduleClass, moduleName, options);
66
+ }
67
+ /**
68
+ * Add a declaration to an NgModule
69
+ * @param moduleClass - The NgModule class declaration
70
+ * @param declaration - Name of the component/directive/pipe to declare
71
+ * @param options - Optional configuration
72
+ */
73
+ addDeclarationToModule(moduleClass, declaration, options) {
74
+ addDeclarationToNgModule(moduleClass, declaration, options);
75
+ }
76
+ /**
77
+ * Remove a component from an NgModule's declarations
78
+ * This is a custom implementation since ng-morph doesn't provide this directly
79
+ *
80
+ * Uses ts-morph to manipulate the `` decorator's declarations array.
81
+ *
82
+ * @param moduleClass - The NgModule class declaration
83
+ * @param componentName - Name of the component to remove
84
+ * @returns True if successfully removed, false otherwise
85
+ */
86
+ removeFromDeclarations(moduleClass, componentName) {
87
+ try {
88
+ // Get the @NgModule decorator
89
+ const ngModuleDecorator = moduleClass.getDecorator('NgModule');
90
+ if (!ngModuleDecorator) {
91
+ return false;
92
+ }
93
+ // Get the decorator arguments (should be an object literal)
94
+ const args = ngModuleDecorator.getArguments();
95
+ if (args.length === 0) {
96
+ return false;
97
+ }
98
+ // Get the configuration object - type assertion needed for ng-morph/ts-morph compatibility
99
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment
100
+ const configObj = args[0];
101
+ if (!configObj) {
102
+ return false;
103
+ }
104
+ // Find the declarations property
105
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
106
+ const properties = configObj.getProperties?.() ?? [];
107
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
108
+ for (const prop of properties) {
109
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
110
+ const propName = prop.getName?.() ?? '';
111
+ if (propName === 'declarations') {
112
+ // Get the array of declarations
113
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
114
+ const initializer = prop.getInitializer?.();
115
+ if (!initializer) {
116
+ continue;
117
+ }
118
+ // Get array elements
119
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
120
+ const elements = initializer.getElements?.() ?? [];
121
+ // Find and remove the component
122
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
123
+ for (const element of elements) {
124
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
125
+ const elementText = element.getText();
126
+ if (elementText === componentName) {
127
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
128
+ element.remove();
129
+ return true;
130
+ }
131
+ }
132
+ }
133
+ }
134
+ return false;
135
+ }
136
+ catch (error) {
137
+ console.warn(`Failed to remove ${componentName} from declarations:`, error);
138
+ return false;
139
+ }
140
+ }
141
+ /**
142
+ * Add an import to a standalone component
143
+ * @param componentClass - The component class declaration
144
+ * @param importName - Name of the import (e.g., 'CommonModule')
145
+ * @param options - Optional configuration
146
+ */
147
+ addImportToComponent(componentClass, importName, options) {
148
+ addImportToComponent(componentClass, importName, options);
149
+ }
150
+ /**
151
+ * Add a provider to a standalone component
152
+ * @param componentClass - The component class declaration
153
+ * @param provider - Provider to add (e.g., 'MyService')
154
+ * @param options - Optional configuration
155
+ */
156
+ addProviderToComponent(componentClass, provider, options) {
157
+ addProviderToComponent(componentClass, provider, options);
158
+ }
159
+ /**
160
+ * Apply all changes to the file system
161
+ * This delegates to the ts-morph Project's save method
162
+ */
163
+ async apply() {
164
+ await this.project.save();
165
+ }
166
+ /**
167
+ * Apply changes synchronously
168
+ */
169
+ applySync() {
170
+ this.project.saveSync();
171
+ }
172
+ /**
173
+ * Get the underlying ts-morph Project
174
+ */
175
+ getProject() {
176
+ return this.project;
177
+ }
178
+ }
179
+ //# sourceMappingURL=ng-morph-adapter.js.map
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KAAK;QACT,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,SAAS;QACP,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC1B,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @angular-modernizer/api - NgModule Manager
3
+ *
4
+ * Service for managing NgModule declarations and exports.
5
+ * Handles finding NgModules and removing standalone components from them.
6
+ *
7
+ * This is critical for completing the standalone migration, as components
8
+ * marked as standalone must be removed from NgModule declarations/exports
9
+ * to avoid compiler errors.
10
+ *
11
+ * MIGRATION NOTE: Refactored to use ng-morph for Angular-specific operations.
12
+ * - Code reduction: 268 lines → ~150 lines (~44% reduction)
13
+ * - Eliminated SyntaxKind checking and manual AST traversal
14
+ * - Leverages ng-morph's high-level Angular abstractions
15
+ */
16
+ import type { Project, SourceFile } from 'ts-morph';
17
+ import type { NgMorphAdapter } from './ng-morph-adapter.js';
18
+ /**
19
+ * NgModule Manager - manages NgModule modifications during migration.
20
+ *
21
+ * This service provides high-level operations for NgModule cleanup,
22
+ * enabling the removal of standalone components from NgModule declarations.
23
+ */
24
+ export declare class NgModuleManager {
25
+ private readonly ngMorphAdapter;
26
+ /**
27
+ * Constructor for NgModuleManager.
28
+ *
29
+ * @param ngMorphAdapter - The ng-morph adapter instance
30
+ */
31
+ constructor(ngMorphAdapter: NgMorphAdapter);
32
+ /**
33
+ * Find the NgModule that declares a specific component.
34
+ *
35
+ * Uses two-tier detection strategy:
36
+ * 1. Fast path: ng-morph for standard `` decorators
37
+ * 2. Fallback: ts-morph for custom decorators (e.g., ``)
38
+ *
39
+ * This enables support for projects with external decorator patterns.
40
+ *
41
+ * @param project - The ts-morph Project instance
42
+ * @param componentClassName - The name of the component to find (e.g., 'CashbookOverviewComponent')
43
+ * @returns The source file containing the NgModule, or undefined if not found
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const ngModuleFile = ngModuleManager.findNgModuleForComponent(project, 'CashbookOverviewComponent');
48
+ * if (ngModuleFile) {
49
+ * console.info(`Found in: ${ngModuleFile.getFilePath()}`);
50
+ * }
51
+ * ```
52
+ *
53
+ * TIER 1 (ng-morph): Fast path for standard Angular components
54
+ * TIER 2 (ts-morph): Fallback for components with custom decorators
55
+ */
56
+ findNgModuleForComponent(project: Project, componentClassName: string): SourceFile | undefined;
57
+ /**
58
+ * Find NgModule for components with custom decorators (ts-morph fallback).
59
+ *
60
+ * Searches all files for:
61
+ * 1. A class with the target name
62
+ * 2. That has a `` decorator (standard or with custom decorators)
63
+ * 3. Then finds which NgModule declares that class
64
+ *
65
+ * This is slower than ng-morph but necessary for external decorator support.
66
+ *
67
+ * @param project - The ts-morph Project instance
68
+ * @param componentClassName - The name of the component class
69
+ * @returns The source file containing the declaring NgModule, or undefined
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // Finds components like:
74
+ * // ``()
75
+ * // ``({ selector: 'app-user' })
76
+ * // export class UserComponent {}
77
+ * ```
78
+ */
79
+ private findNgModuleForComponentWithCustomDecorators;
80
+ /**
81
+ * Remove components from NgModule declarations and exports arrays.
82
+ *
83
+ * Uses ng-morph to locate the module and ts-morph to remove array elements.
84
+ * This is simpler than the previous implementation.
85
+ *
86
+ * @param ngModuleFile - The source file containing the NgModule
87
+ * @param classNamesToRemove - Array of component class names to remove
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * ngModuleManager.removeDeclarations(
92
+ * ngModuleFile,
93
+ * ['CashbookOverviewComponent', 'AddCashbookEntryDialogComponent']
94
+ * );
95
+ * ```
96
+ *
97
+ * BEFORE (ts-morph): 35+ lines with SyntaxKind and manual AST traversal
98
+ * AFTER (ng-morph + ts-morph): ~20 lines with cleaner logic
99
+ */
100
+ removeDeclarations(ngModuleFile: SourceFile, classNamesToRemove: string[]): void;
101
+ /**
102
+ * Get the imports array from an NgModule.
103
+ *
104
+ * Uses ng-morph to locate the module, then extracts imports using ts-morph.
105
+ * Simpler than the previous implementation.
106
+ *
107
+ * @param ngModuleFile - The source file containing the NgModule
108
+ * @returns Array of import names (e.g., ['CommonModule', 'ReactiveFormsModule'])
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const imports = ngModuleManager.getNgModuleImports(cashbookModuleFile);
113
+ * // imports = ['CommonModule', 'ReactiveFormsModule', 'SharedComponentsModule']
114
+ * ```
115
+ *
116
+ * BEFORE (ts-morph): 45+ lines with SyntaxKind checking
117
+ * AFTER (ng-morph + ts-morph): ~15 lines with cleaner logic
118
+ */
119
+ getNgModuleImports(ngModuleFile: SourceFile): string[];
120
+ /**
121
+ * Extract an array property from NgModule metadata.
122
+ *
123
+ * Helper method to extract array values from metadata object.
124
+ *
125
+ * @param metadata - The metadata object from `` decorator
126
+ * @param propertyName - The property name (e.g., 'imports', 'declarations')
127
+ * @returns Array of string values from the property
128
+ *
129
+ * Note: Uses type assertions due to ng-morph/ts-morph version mismatch
130
+ */
131
+ private extractArrayFromMetadata;
132
+ /**
133
+ * Remove elements from a metadata array property.
134
+ *
135
+ * Helper method to remove specific values from arrays in metadata.
136
+ *
137
+ * @param metadata - The metadata object from `` decorator
138
+ * @param propertyName - The property name (e.g., 'declarations', 'exports')
139
+ * @param namesToRemove - Set of names to remove
140
+ *
141
+ * Note: Uses type assertions due to ng-morph/ts-morph version mismatch
142
+ */
143
+ private removeFromMetadataArray;
144
+ }
145
+ //# sourceMappingURL=ngmodule-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ngmodule-manager.d.ts","sourceRoot":"","sources":["../../src/transformation/ngmodule-manager.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAoB,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAEhD;;;;OAIG;gBACS,cAAc,EAAE,cAAc;IAI1C;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,wBAAwB,CACtB,OAAO,EAAE,OAAO,EAChB,kBAAkB,EAAE,MAAM,GACzB,UAAU,GAAG,SAAS;IAwBzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,4CAA4C;IA0EpD;;;;;;;;;;;;;;;;;;;OAmBG;IACH,kBAAkB,CAChB,YAAY,EAAE,UAAU,EACxB,kBAAkB,EAAE,MAAM,EAAE,GAC3B,IAAI;IAyDP;;;;;;;;;;;;;;;;;OAiBG;IACH,kBAAkB,CAAC,YAAY,EAAE,UAAU,GAAG,MAAM,EAAE;IA8CtD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,wBAAwB;IAmDhC;;;;;;;;;;OAUG;IACH,OAAO,CAAC,uBAAuB;CA0ChC"}