@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,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API for @angular-modernizer/api
|
|
3
|
+
*
|
|
4
|
+
* This file exports the main interfaces and classes that plugins and tools
|
|
5
|
+
* can use for Angular analysis and transformation.
|
|
6
|
+
*/
|
|
7
|
+
import { NgMorphAdapter } from './transformation/ng-morph-adapter.js';
|
|
8
|
+
import { NgModuleManager } from './transformation/ngmodule-manager.js';
|
|
9
|
+
import { ImportManager } from './transformation/import-manager.js';
|
|
10
|
+
import { ServicePatternRecognizer } from './analysis/service-pattern-recognizer.js';
|
|
11
|
+
import { ServiceDetector } from './analysis/service-detector.js';
|
|
12
|
+
import { SymbolLocator } from './analysis/symbol-locator.js';
|
|
13
|
+
import { TemplateAnalyzer } from './analysis/template-analyzer.js';
|
|
14
|
+
import type { Project } from 'ts-morph';
|
|
15
|
+
/**
|
|
16
|
+
* Public API interface that provides access to all analysis and transformation tools
|
|
17
|
+
*/
|
|
18
|
+
export interface PublicApi {
|
|
19
|
+
/**
|
|
20
|
+
* Analysis tools for code inspection and pattern detection
|
|
21
|
+
*/
|
|
22
|
+
analysis: {
|
|
23
|
+
/**
|
|
24
|
+
* Service pattern recognizer for classifying Angular service patterns
|
|
25
|
+
*/
|
|
26
|
+
servicePatternRecognizer: ServicePatternRecognizer;
|
|
27
|
+
/**
|
|
28
|
+
* Service detector with caching and bulk operations
|
|
29
|
+
*/
|
|
30
|
+
serviceDetector: ServiceDetector;
|
|
31
|
+
/**
|
|
32
|
+
* Symbol locator for resolving symbols across the project
|
|
33
|
+
*/
|
|
34
|
+
symbolLocator: SymbolLocator;
|
|
35
|
+
/**
|
|
36
|
+
* Template analyzer for analyzing Angular templates
|
|
37
|
+
*/
|
|
38
|
+
templateAnalyzer: TemplateAnalyzer;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Transformation tools for code modification
|
|
42
|
+
*/
|
|
43
|
+
transformation: {
|
|
44
|
+
/**
|
|
45
|
+
* NgModule manager for managing NgModule declarations and exports
|
|
46
|
+
*/
|
|
47
|
+
ngModuleManager: NgModuleManager;
|
|
48
|
+
/**
|
|
49
|
+
* Import manager for managing imports with hybrid ng-morph approach
|
|
50
|
+
*/
|
|
51
|
+
importManager: ImportManager;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* ng-morph adapter for Angular-specific AST operations
|
|
55
|
+
*/
|
|
56
|
+
ngMorph: NgMorphAdapter;
|
|
57
|
+
/**
|
|
58
|
+
* The underlying ts-morph Project instance
|
|
59
|
+
*/
|
|
60
|
+
project: Project;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Factory function to create a PublicApi instance
|
|
64
|
+
*
|
|
65
|
+
* @param project - The ts-morph Project instance
|
|
66
|
+
* @param options - Optional configuration for the adapters
|
|
67
|
+
*/
|
|
68
|
+
export declare function createPublicApi(project: Project, options?: {
|
|
69
|
+
rootPath?: string;
|
|
70
|
+
pattern?: string;
|
|
71
|
+
}): PublicApi;
|
|
72
|
+
export { NgMorphAdapter, type NgMorphAdapterOptions } from './transformation/ng-morph-adapter.js';
|
|
73
|
+
export { NgModuleManager } from './transformation/ngmodule-manager.js';
|
|
74
|
+
export { ImportManager } from './transformation/import-manager.js';
|
|
75
|
+
export { ServiceDetector } from './analysis/service-detector.js';
|
|
76
|
+
export { ServicePatternRecognizer } from './analysis/service-pattern-recognizer.js';
|
|
77
|
+
//# sourceMappingURL=public-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-api.d.ts","sourceRoot":"","sources":["../src/public-api.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EAEf,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,QAAQ,EAAE;QACR;;WAEG;QACH,wBAAwB,EAAE,wBAAwB,CAAC;QAEnD;;WAEG;QACH,eAAe,EAAE,eAAe,CAAC;QAEjC;;WAEG;QACH,aAAa,EAAE,aAAa,CAAC;QAE7B;;WAEG;QACH,gBAAgB,EAAE,gBAAgB,CAAC;KACpC,CAAC;IAEF;;OAEG;IACH,cAAc,EAAE;QACd;;WAEG;QACH,eAAe,EAAE,eAAe,CAAC;QAEjC;;WAEG;QACH,aAAa,EAAE,aAAa,CAAC;KAC9B,CAAC;IAEF;;OAEG;IACH,OAAO,EAAE,cAAc,CAAC;IAExB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,SAAS,CAyBX;AAGD,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public API for @angular-modernizer/api
|
|
3
|
+
*
|
|
4
|
+
* This file exports the main interfaces and classes that plugins and tools
|
|
5
|
+
* can use for Angular analysis and transformation.
|
|
6
|
+
*/
|
|
7
|
+
import { NgMorphAdapter, } from './transformation/ng-morph-adapter.js';
|
|
8
|
+
import { NgModuleManager } from './transformation/ngmodule-manager.js';
|
|
9
|
+
import { ImportManager } from './transformation/import-manager.js';
|
|
10
|
+
import { ServicePatternRecognizer } from './analysis/service-pattern-recognizer.js';
|
|
11
|
+
import { ServiceDetector } from './analysis/service-detector.js';
|
|
12
|
+
import { SymbolLocator } from './analysis/symbol-locator.js';
|
|
13
|
+
import { TemplateAnalyzer } from './analysis/template-analyzer.js';
|
|
14
|
+
/**
|
|
15
|
+
* Factory function to create a PublicApi instance
|
|
16
|
+
*
|
|
17
|
+
* @param project - The ts-morph Project instance
|
|
18
|
+
* @param options - Optional configuration for the adapters
|
|
19
|
+
*/
|
|
20
|
+
export function createPublicApi(project, options) {
|
|
21
|
+
const ngMorphOptions = {
|
|
22
|
+
project,
|
|
23
|
+
rootPath: options?.rootPath,
|
|
24
|
+
pattern: options?.pattern,
|
|
25
|
+
};
|
|
26
|
+
const ngMorphAdapter = new NgMorphAdapter(ngMorphOptions);
|
|
27
|
+
const servicePatternRecognizer = new ServicePatternRecognizer(ngMorphAdapter);
|
|
28
|
+
const serviceDetector = new ServiceDetector(servicePatternRecognizer);
|
|
29
|
+
return {
|
|
30
|
+
analysis: {
|
|
31
|
+
servicePatternRecognizer,
|
|
32
|
+
serviceDetector,
|
|
33
|
+
symbolLocator: new SymbolLocator(),
|
|
34
|
+
templateAnalyzer: new TemplateAnalyzer(),
|
|
35
|
+
},
|
|
36
|
+
transformation: {
|
|
37
|
+
ngModuleManager: new NgModuleManager(ngMorphAdapter),
|
|
38
|
+
importManager: new ImportManager(ngMorphAdapter),
|
|
39
|
+
},
|
|
40
|
+
ngMorph: ngMorphAdapter,
|
|
41
|
+
project,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
// Re-export key types and classes
|
|
45
|
+
export { NgMorphAdapter } from './transformation/ng-morph-adapter.js';
|
|
46
|
+
export { NgModuleManager } from './transformation/ngmodule-manager.js';
|
|
47
|
+
export { ImportManager } from './transformation/import-manager.js';
|
|
48
|
+
export { ServiceDetector } from './analysis/service-detector.js';
|
|
49
|
+
export { ServicePatternRecognizer } from './analysis/service-pattern-recognizer.js';
|
|
50
|
+
//# source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,MAAM,sCAAsC,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @angular-modernizer/api - Import Manager
|
|
3
|
+
*
|
|
4
|
+
* High-level API for managing imports in TypeScript files.
|
|
5
|
+
* Handles adding, removing, and organizing imports safely.
|
|
6
|
+
*
|
|
7
|
+
* ## HYBRID ng-morph + ts-morph APPROACH
|
|
8
|
+
*
|
|
9
|
+
* ### What ng-morph HANDLES (Component/Module Metadata):
|
|
10
|
+
* - Component imports: [] array (e.g., @Component({ imports: [CommonModule] }))
|
|
11
|
+
* - Module imports: [] array (e.g., @NgModule({ imports: [CommonModule] }))
|
|
12
|
+
* - These are decorator metadata, NOT ES6 import statements
|
|
13
|
+
*
|
|
14
|
+
* ### What ts-morph HANDLES (Everything Else):
|
|
15
|
+
* - ES6 import statements (e.g., import { CommonModule } from '@angular/common')
|
|
16
|
+
* - Import organization and merging
|
|
17
|
+
* - Removal of imports
|
|
18
|
+
* - Aliases and complex imports
|
|
19
|
+
* - Non-Angular imports
|
|
20
|
+
*
|
|
21
|
+
* ### Code Impact:
|
|
22
|
+
* - ng-morph provides value for ~5-10% of import operations (metadata only)
|
|
23
|
+
* - ts-morph still handles 90-95% of imports (ES6 statements)
|
|
24
|
+
* - Maintains 100% backward compatibility
|
|
25
|
+
*
|
|
26
|
+
* ### Why This Hybrid?
|
|
27
|
+
* ng-morph provides cleaner API for adding to decorator metadata arrays.
|
|
28
|
+
* For ES6 import statements, ng-morph is just a thin wrapper around ts-morph with no advantage.
|
|
29
|
+
*/
|
|
30
|
+
import type { SourceFile } from 'ts-morph';
|
|
31
|
+
import type { NgMorphAdapter } from './ng-morph-adapter.js';
|
|
32
|
+
/**
|
|
33
|
+
* Import information.
|
|
34
|
+
*/
|
|
35
|
+
export interface ImportInfo {
|
|
36
|
+
/**
|
|
37
|
+
* Module specifier (e.g., '@angular/core').
|
|
38
|
+
*/
|
|
39
|
+
moduleSpecifier: string;
|
|
40
|
+
/**
|
|
41
|
+
* Named imports (e.g., ['Component', 'OnInit']).
|
|
42
|
+
*/
|
|
43
|
+
namedImports?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Default import (e.g., 'React').
|
|
46
|
+
*/
|
|
47
|
+
defaultImport?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Namespace import (e.g., '* as fs').
|
|
50
|
+
*/
|
|
51
|
+
namespaceImport?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Import Manager - manages imports in source files using hybrid ng-morph + ts-morph approach.
|
|
55
|
+
*
|
|
56
|
+
* ## HYBRID STRATEGY (See file header for full explanation)
|
|
57
|
+
*
|
|
58
|
+
* **ng-morph (5-10% of operations):**
|
|
59
|
+
* - ONLY for adding to component/module imports: [] metadata arrays
|
|
60
|
+
* - Example: @Component({ imports: [CommonModule] }) ← ng-morph adds here
|
|
61
|
+
*
|
|
62
|
+
* **ts-morph (90-95% of operations):**
|
|
63
|
+
* - ES6 import statements: import { X } from 'y'
|
|
64
|
+
* - Import removal, organization, aliases
|
|
65
|
+
* - All non-metadata import operations
|
|
66
|
+
*
|
|
67
|
+
* **Result:** Cleaner API for metadata, minimal overall code reduction.
|
|
68
|
+
*/
|
|
69
|
+
export declare class ImportManager {
|
|
70
|
+
private readonly ngMorphAdapter?;
|
|
71
|
+
/**
|
|
72
|
+
* Constructor for ImportManager.
|
|
73
|
+
*
|
|
74
|
+
* @param ngMorphAdapter - Optional ng-morph adapter for Angular-specific operations
|
|
75
|
+
*
|
|
76
|
+
* BACKWARD COMPATIBILITY: Constructor is optional - if not provided, falls back to pure ts-morph.
|
|
77
|
+
*/
|
|
78
|
+
constructor(ngMorphAdapter?: NgMorphAdapter);
|
|
79
|
+
/**
|
|
80
|
+
* Add a named import to a source file.
|
|
81
|
+
* Handles merging with existing imports from the same module.
|
|
82
|
+
*
|
|
83
|
+
* HYBRID APPROACH:
|
|
84
|
+
* - Angular imports (@angular/*): Try ng-morph for components/modules
|
|
85
|
+
* - Non-Angular/complex: Fall back to ts-morph
|
|
86
|
+
*
|
|
87
|
+
* @param sourceFile - The source file to modify
|
|
88
|
+
* @param moduleSpecifier - The module to import from (e.g., '@angular/common')
|
|
89
|
+
* @param namedImport - The named import to add (e.g., 'CommonModule')
|
|
90
|
+
* @param alias - Optional alias for the import (e.g., 'NgComponent')
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* importManager.addNamedImport(sourceFile, '@angular/common', 'CommonModule');
|
|
95
|
+
* // Result: import { CommonModule } from '@angular/common';
|
|
96
|
+
*
|
|
97
|
+
* importManager.addNamedImport(sourceFile, '@angular/core', 'Component', 'NgComponent');
|
|
98
|
+
* // Result: import { Component as NgComponent } from '@angular/core';
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* BEFORE (ts-morph): 30 lines with manual checking
|
|
102
|
+
* AFTER (hybrid): ~20 lines with ng-morph for Angular imports
|
|
103
|
+
*/
|
|
104
|
+
addNamedImport(sourceFile: SourceFile, moduleSpecifier: string, namedImport: string, alias?: string): void;
|
|
105
|
+
/**
|
|
106
|
+
* Check if a module specifier is an Angular import.
|
|
107
|
+
*
|
|
108
|
+
* @param moduleSpecifier - The module specifier to check
|
|
109
|
+
* @returns True if it's an Angular module
|
|
110
|
+
*/
|
|
111
|
+
private isAngularImport;
|
|
112
|
+
/**
|
|
113
|
+
* Try to add an Angular import using ng-morph.
|
|
114
|
+
*
|
|
115
|
+
* ng-morph can add imports to component/module metadata (imports: [] array).
|
|
116
|
+
* This is useful for adding Angular modules like CommonModule, FormsModule, etc.
|
|
117
|
+
*
|
|
118
|
+
* @param sourceFile - The source file
|
|
119
|
+
* @param moduleSpecifier - The Angular module specifier
|
|
120
|
+
* @param namedImport - The import name (e.g., 'CommonModule')
|
|
121
|
+
* @param alias - Optional alias (not supported for metadata array imports)
|
|
122
|
+
* @returns True if successfully added via ng-morph, false to fall back
|
|
123
|
+
*/
|
|
124
|
+
private tryAddAngularImport;
|
|
125
|
+
/**
|
|
126
|
+
* Add import using ts-morph (fallback for complex cases).
|
|
127
|
+
*
|
|
128
|
+
* @param sourceFile - The source file
|
|
129
|
+
* @param moduleSpecifier - The module specifier
|
|
130
|
+
* @param namedImport - The import name
|
|
131
|
+
* @param alias - Optional alias
|
|
132
|
+
*/
|
|
133
|
+
private addImportUsingTsMorph;
|
|
134
|
+
/**
|
|
135
|
+
* Remove a named import from a source file.
|
|
136
|
+
* Cleans up empty import declarations after removal.
|
|
137
|
+
*
|
|
138
|
+
* HYBRID APPROACH:
|
|
139
|
+
* - Always uses ts-morph for removal (simpler than ng-morph)
|
|
140
|
+
* - ng-morph doesn't provide significant benefits for removal operations
|
|
141
|
+
*
|
|
142
|
+
* @param sourceFile - The source file
|
|
143
|
+
* @param namedImport - The named import to remove
|
|
144
|
+
* @param moduleSpecifier - Optional module specifier to target specific imports
|
|
145
|
+
*
|
|
146
|
+
* Handles:
|
|
147
|
+
* - Removing specific named imports from import declarations
|
|
148
|
+
* - Cleaning up empty import declarations
|
|
149
|
+
* - Preserving other imports from the same module
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* // Before: import { Foo, Bar } from './module';
|
|
154
|
+
* importManager.removeNamedImport(sourceFile, 'Bar', './module');
|
|
155
|
+
* // After: import { Foo } from './module';
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
removeNamedImport(sourceFile: SourceFile, namedImport: string, moduleSpecifier?: string): void;
|
|
159
|
+
/**
|
|
160
|
+
* Get all imports from a source file.
|
|
161
|
+
*
|
|
162
|
+
* @param sourceFile - The source file
|
|
163
|
+
* @returns Array of import information
|
|
164
|
+
*
|
|
165
|
+
* Extracts:
|
|
166
|
+
* - All named imports with their module specifiers
|
|
167
|
+
* - Default imports and namespace imports
|
|
168
|
+
* - Import declaration positions for organization
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const imports = importManager.getImports(sourceFile);
|
|
173
|
+
* // Returns:
|
|
174
|
+
* // [
|
|
175
|
+
* // { moduleSpecifier: '@angular/core', namedImports: ['Component', 'OnInit'] },
|
|
176
|
+
* // { moduleSpecifier: 'rxjs', namedImports: ['Observable'], defaultImport: 'Rx' }
|
|
177
|
+
* // ]
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
getImports(sourceFile: SourceFile): ImportInfo[];
|
|
181
|
+
/**
|
|
182
|
+
* Organize imports (sort and remove duplicates).
|
|
183
|
+
*
|
|
184
|
+
* @param sourceFile - The source file
|
|
185
|
+
*
|
|
186
|
+
* Handles:
|
|
187
|
+
* - Sorting imports by module specifier (external libraries first, then internal)
|
|
188
|
+
* - Removing duplicate imports
|
|
189
|
+
* - Grouping related imports
|
|
190
|
+
* - Maintaining proper spacing and formatting
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* // Before:
|
|
195
|
+
* // import { Component } from '@angular/core';
|
|
196
|
+
* // import { MyService } from './my-service';
|
|
197
|
+
* // import { Injectable } from '@angular/core';
|
|
198
|
+
*
|
|
199
|
+
* importManager.organizeImports(sourceFile);
|
|
200
|
+
*
|
|
201
|
+
* // After:
|
|
202
|
+
* // import { Component, Injectable } from '@angular/core';
|
|
203
|
+
* // import { MyService } from './my-service';
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
206
|
+
organizeImports(sourceFile: SourceFile): void;
|
|
207
|
+
/**
|
|
208
|
+
* Merge duplicate import declarations.
|
|
209
|
+
*
|
|
210
|
+
* Combines multiple import statements from the same module into one.
|
|
211
|
+
*
|
|
212
|
+
* @param sourceFile - The source file
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* // Before:
|
|
217
|
+
* // import { Component } from '@angular/core';
|
|
218
|
+
* // import { Injectable } from '@angular/core';
|
|
219
|
+
*
|
|
220
|
+
* importManager.mergeImports(sourceFile);
|
|
221
|
+
*
|
|
222
|
+
* // After:
|
|
223
|
+
* // import { Component, Injectable } from '@angular/core';
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
mergeImports(sourceFile: SourceFile): void;
|
|
227
|
+
/**
|
|
228
|
+
* Remove import declarations that have no imports.
|
|
229
|
+
*
|
|
230
|
+
* Cleans up empty import statements that may result from refactoring.
|
|
231
|
+
*
|
|
232
|
+
* @param sourceFile - The source file
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Before: import {} from '@angular/core';
|
|
237
|
+
*
|
|
238
|
+
* importManager.cleanupEmptyImports(sourceFile);
|
|
239
|
+
*
|
|
240
|
+
* // After: (empty import removed)
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
cleanupEmptyImports(sourceFile: SourceFile): void;
|
|
244
|
+
/**
|
|
245
|
+
* Check if a named import exists in the source file.
|
|
246
|
+
*
|
|
247
|
+
* @param sourceFile - The source file
|
|
248
|
+
* @param symbol - The symbol name to check
|
|
249
|
+
* @param module - Optional module specifier to check specifically
|
|
250
|
+
* @returns True if the import exists
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```typescript
|
|
254
|
+
* const exists = importManager.hasImport(sourceFile, 'Component', '@angular/core');
|
|
255
|
+
* // Returns true if 'import { Component } from '@angular/core';' exists
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
hasImport(sourceFile: SourceFile, symbol: string, module?: string): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Get the alias for a named import, if it exists.
|
|
261
|
+
*
|
|
262
|
+
* @param sourceFile - The source file
|
|
263
|
+
* @param symbol - The symbol name
|
|
264
|
+
* @param module - Optional module specifier
|
|
265
|
+
* @returns The alias if found, undefined otherwise
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```typescript
|
|
269
|
+
* // import { Component as NgComponent } from '@angular/core';
|
|
270
|
+
* const alias = importManager.getImportAlias(sourceFile, 'Component', '@angular/core');
|
|
271
|
+
* // Returns 'NgComponent'
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
getImportAlias(sourceFile: SourceFile, symbol: string, module?: string): string | undefined;
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=import-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-manager.d.ts","sourceRoot":"","sources":["../../src/transformation/import-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAExB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAiB;IAEjD;;;;;;OAMG;gBACS,cAAc,CAAC,EAAE,cAAc;IAG3C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,cAAc,CACZ,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,MAAM,GACb,IAAI;IAmBP;;;;;OAK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