@notjustcoders/ioc-arise 1.1.10 → 1.1.11
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 +37 -115
- package/dist/analyser/ast-parser.d.ts.map +1 -1
- package/dist/analyser/ast-parser.js +4 -4
- package/dist/analyser/ast-parser.js.map +1 -1
- package/dist/analyser/class-analyzer.d.ts.map +1 -1
- package/dist/analyser/class-analyzer.js +8 -5
- package/dist/analyser/class-analyzer.js.map +1 -1
- package/dist/analyser/project-analyzer.d.ts.map +1 -1
- package/dist/analyser/project-analyzer.js +7 -6
- package/dist/analyser/project-analyzer.js.map +1 -1
- package/dist/commands/analyze.d.ts.map +1 -1
- package/dist/commands/analyze.js +12 -11
- package/dist/commands/analyze.js.map +1 -1
- package/dist/commands/generate.d.ts.map +1 -1
- package/dist/commands/generate.js +37 -16
- package/dist/commands/generate.js.map +1 -1
- package/dist/commands/visualize.d.ts.map +1 -1
- package/dist/commands/visualize.js +10 -9
- package/dist/commands/visualize.js.map +1 -1
- package/dist/errors/IoCError.d.ts +7 -0
- package/dist/errors/IoCError.d.ts.map +1 -1
- package/dist/errors/IoCError.js +16 -1
- package/dist/errors/IoCError.js.map +1 -1
- package/dist/errors/errorFactory.d.ts +1 -1
- package/dist/errors/errorFactory.d.ts.map +1 -1
- package/dist/errors/errorFactory.js +23 -23
- package/dist/errors/errorFactory.js.map +1 -1
- package/dist/generator/index.d.ts +2 -19
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +16 -34
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/ioc-container-generator.d.ts +27 -0
- package/dist/generator/ioc-container-generator.d.ts.map +1 -0
- package/dist/generator/ioc-container-generator.js +353 -0
- package/dist/generator/ioc-container-generator.js.map +1 -0
- package/dist/generator/type-declaration-generator.d.ts +10 -0
- package/dist/generator/type-declaration-generator.d.ts.map +1 -0
- package/dist/generator/type-declaration-generator.js +140 -0
- package/dist/generator/type-declaration-generator.js.map +1 -0
- package/dist/utils/circular-dependency-detector.d.ts +16 -0
- package/dist/utils/circular-dependency-detector.d.ts.map +1 -0
- package/dist/utils/circular-dependency-detector.js +70 -0
- package/dist/utils/circular-dependency-detector.js.map +1 -0
- package/dist/utils/configManager.d.ts.map +1 -1
- package/dist/utils/configManager.js +6 -5
- package/dist/utils/configManager.js.map +1 -1
- package/dist/utils/configValidator.d.ts +1 -1
- package/dist/utils/configValidator.d.ts.map +1 -1
- package/dist/utils/configValidator.js +12 -11
- package/dist/utils/configValidator.js.map +1 -1
- package/dist/utils/moduleResolver.d.ts +1 -1
- package/dist/utils/moduleResolver.d.ts.map +1 -1
- package/dist/utils/moduleResolver.js +5 -5
- package/dist/utils/moduleResolver.js.map +1 -1
- package/package.json +3 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+DAA6C"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ClassInfo } from '../types';
|
|
2
|
+
export declare class IoCContainerGenerator {
|
|
3
|
+
/**
|
|
4
|
+
* Generates the IoC container code for the given classes
|
|
5
|
+
* @param classes - Analyzed classes to be registered (can be flat or grouped)
|
|
6
|
+
* @param outputPath - Path where the container file will be generated
|
|
7
|
+
* @param moduleGroupedClasses - Optional: Classes grouped by modules
|
|
8
|
+
*/
|
|
9
|
+
static generate(classes: ClassInfo[], outputPath: string, moduleGroupedClasses?: Map<string, ClassInfo[]>): void;
|
|
10
|
+
private static generateFlatCode;
|
|
11
|
+
private static generateModularFiles;
|
|
12
|
+
private static generateModuleFile;
|
|
13
|
+
private static generateMainContainerFile;
|
|
14
|
+
private static generateModularCode;
|
|
15
|
+
private static generateModuleDefinitions;
|
|
16
|
+
private static generateModuleInstantiations;
|
|
17
|
+
private static generateModuleRegistrations;
|
|
18
|
+
private static generateImports;
|
|
19
|
+
private static classNameAliases;
|
|
20
|
+
private static classNameToAliasMap;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves the full file path of a dependency based on the importing file and relative import path
|
|
23
|
+
*/
|
|
24
|
+
private static resolveDependencyFilePath;
|
|
25
|
+
private static generateRegistrations;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ioc-container-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ioc-container-generator.d.ts","sourceRoot":"","sources":["../../src/generator/ioc-container-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,qBAAa,qBAAqB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CACX,OAAO,EAAE,SAAS,EAAE,EACpB,UAAU,EAAE,MAAM,EAClB,oBAAoB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,GAChD,IAAI;IAqBP,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA0C/B,OAAO,CAAC,MAAM,CAAC,oBAAoB;IAwCnC,OAAO,CAAC,MAAM,CAAC,kBAAkB;IAqCjC,OAAO,CAAC,MAAM,CAAC,yBAAyB;IA0BxC,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAsClC,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAgBxC,OAAO,CAAC,MAAM,CAAC,4BAA4B;IAY3C,OAAO,CAAC,MAAM,CAAC,2BAA2B;IAsD1C,OAAO,CAAC,MAAM,CAAC,eAAe;IA+D9B,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA6B;IAC5D,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAA0C;IAE5E;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAexC,OAAO,CAAC,MAAM,CAAC,qBAAqB;CA6DvC"}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IoCContainerGenerator = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const type_declaration_generator_1 = require("./type-declaration-generator");
|
|
7
|
+
class IoCContainerGenerator {
|
|
8
|
+
/**
|
|
9
|
+
* Generates the IoC container code for the given classes
|
|
10
|
+
* @param classes - Analyzed classes to be registered (can be flat or grouped)
|
|
11
|
+
* @param outputPath - Path where the container file will be generated
|
|
12
|
+
* @param moduleGroupedClasses - Optional: Classes grouped by modules
|
|
13
|
+
*/
|
|
14
|
+
static generate(classes, outputPath, moduleGroupedClasses) {
|
|
15
|
+
// Ensure directory exists
|
|
16
|
+
const outputDir = (0, path_1.dirname)(outputPath);
|
|
17
|
+
(0, fs_1.mkdirSync)(outputDir, { recursive: true });
|
|
18
|
+
if (moduleGroupedClasses && moduleGroupedClasses.size > 1) {
|
|
19
|
+
// Generate modular code with separate files for each module
|
|
20
|
+
this.generateModularFiles(moduleGroupedClasses, outputPath);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
// Generate single flat file
|
|
24
|
+
const containerCode = this.generateFlatCode(classes, outputPath);
|
|
25
|
+
(0, fs_1.writeFileSync)(outputPath, containerCode);
|
|
26
|
+
}
|
|
27
|
+
// Generate type declarations (.d.ts file)
|
|
28
|
+
const typesPath = outputPath.endsWith('.gen.ts')
|
|
29
|
+
? outputPath.replace(/\.gen\.ts$/, '.gen.d.ts')
|
|
30
|
+
: outputPath.replace(/\.ts$/, '.d.ts');
|
|
31
|
+
type_declaration_generator_1.TypeDeclarationGenerator.generate(classes, typesPath);
|
|
32
|
+
}
|
|
33
|
+
static generateFlatCode(classes, outputPath) {
|
|
34
|
+
// Collect all interface names to identify which dependencies should use string tokens
|
|
35
|
+
const interfaceNames = new Set();
|
|
36
|
+
classes.forEach(cls => {
|
|
37
|
+
if (cls.interfaceName) {
|
|
38
|
+
interfaceNames.add(cls.interfaceName);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
// Collect abstract class names from dependencies
|
|
42
|
+
const abstractClassNames = new Set();
|
|
43
|
+
classes.forEach(cls => {
|
|
44
|
+
cls.dependencies.forEach(dep => {
|
|
45
|
+
const isInCurrentClasses = classes.some(c => c.name === dep.name);
|
|
46
|
+
const looksLikeAbstractClass = dep.name.startsWith('Abstract') || dep.name.includes('Abstract');
|
|
47
|
+
if (!isInCurrentClasses && looksLikeAbstractClass) {
|
|
48
|
+
abstractClassNames.add(dep.name);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
const imports = this.generateImports(classes, outputPath);
|
|
53
|
+
const registrations = this.generateRegistrations(classes, interfaceNames, '', abstractClassNames);
|
|
54
|
+
const filename = outputPath.split('/').pop()?.replace(/\.ts$/, '') || 'container.gen';
|
|
55
|
+
const dtsFilename = outputPath.split('/').pop()?.replace(/\.ts$/, '.d') || 'container.gen.d';
|
|
56
|
+
return `/**
|
|
57
|
+
* This file is auto-generated by ioc-arise.
|
|
58
|
+
* Do not modify this file manually.
|
|
59
|
+
*/
|
|
60
|
+
import { Container, Lifecycle } from 'ioc-arise';
|
|
61
|
+
import type { ContainerRegistry } from './${dtsFilename}';
|
|
62
|
+
${imports}
|
|
63
|
+
|
|
64
|
+
export const container = new Container<ContainerRegistry>();
|
|
65
|
+
|
|
66
|
+
${registrations}
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
static generateModularFiles(moduleGroupedClasses, outputPath) {
|
|
70
|
+
const outputDir = (0, path_1.dirname)(outputPath);
|
|
71
|
+
const baseFilename = (0, path_1.basename)(outputPath, '.ts');
|
|
72
|
+
const modulesDir = (0, path_1.join)(outputDir, 'modules');
|
|
73
|
+
// Create modules directory
|
|
74
|
+
(0, fs_1.mkdirSync)(modulesDir, { recursive: true });
|
|
75
|
+
// Collect all interface names
|
|
76
|
+
const allClasses = Array.from(moduleGroupedClasses.values()).flat();
|
|
77
|
+
const interfaceNames = new Set();
|
|
78
|
+
allClasses.forEach(cls => {
|
|
79
|
+
if (cls.interfaceName) {
|
|
80
|
+
interfaceNames.add(cls.interfaceName);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
// Generate each module file
|
|
84
|
+
const moduleImports = [];
|
|
85
|
+
for (const [moduleName, classes] of moduleGroupedClasses.entries()) {
|
|
86
|
+
const moduleFilename = `${moduleName.charAt(0).toLowerCase() + moduleName.slice(1)}.module.ts`;
|
|
87
|
+
const moduleFilePath = (0, path_1.join)(modulesDir, moduleFilename);
|
|
88
|
+
const moduleCode = this.generateModuleFile(moduleName, classes, interfaceNames, moduleFilePath);
|
|
89
|
+
(0, fs_1.writeFileSync)(moduleFilePath, moduleCode);
|
|
90
|
+
// Add import for main container file
|
|
91
|
+
const moduleVarName = moduleName.charAt(0).toLowerCase() + moduleName.slice(1);
|
|
92
|
+
moduleImports.push(`import { ${moduleVarName} } from './modules/${moduleFilename.replace('.ts', '')}';`);
|
|
93
|
+
}
|
|
94
|
+
// Generate main container file
|
|
95
|
+
const dtsFilename = baseFilename.replace(/\.gen$/, '.gen.d');
|
|
96
|
+
const mainContainerCode = this.generateMainContainerFile(moduleGroupedClasses, moduleImports, dtsFilename);
|
|
97
|
+
(0, fs_1.writeFileSync)(outputPath, mainContainerCode);
|
|
98
|
+
}
|
|
99
|
+
static generateModuleFile(moduleName, classes, interfaceNames, moduleFilePath) {
|
|
100
|
+
const imports = this.generateImports(classes, moduleFilePath);
|
|
101
|
+
// Collect abstract class names that are dependencies
|
|
102
|
+
const abstractClassNames = new Set();
|
|
103
|
+
classes.forEach(cls => {
|
|
104
|
+
cls.dependencies.forEach(dep => {
|
|
105
|
+
const isInCurrentModule = classes.some(c => c.name === dep.name);
|
|
106
|
+
const looksLikeAbstractClass = dep.name.startsWith('Abstract') || dep.name.includes('Abstract');
|
|
107
|
+
if (!isInCurrentModule && looksLikeAbstractClass) {
|
|
108
|
+
abstractClassNames.add(dep.name);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
const registrations = this.generateModuleRegistrations(classes, interfaceNames, abstractClassNames);
|
|
113
|
+
const moduleVarName = moduleName.charAt(0).toLowerCase() + moduleName.slice(1);
|
|
114
|
+
return `/**
|
|
115
|
+
* This file is auto-generated by ioc-arise.
|
|
116
|
+
* Do not modify this file manually.
|
|
117
|
+
*
|
|
118
|
+
* Module: ${moduleName}
|
|
119
|
+
*/
|
|
120
|
+
import { ContainerModule, Lifecycle } from 'ioc-arise';
|
|
121
|
+
${imports}
|
|
122
|
+
|
|
123
|
+
export const ${moduleVarName} = new ContainerModule()
|
|
124
|
+
${registrations};
|
|
125
|
+
`;
|
|
126
|
+
}
|
|
127
|
+
static generateMainContainerFile(moduleGroupedClasses, moduleImports, dtsFilename) {
|
|
128
|
+
const moduleInstantiations = Array.from(moduleGroupedClasses.keys())
|
|
129
|
+
.map(name => {
|
|
130
|
+
const varName = name.charAt(0).toLowerCase() + name.slice(1);
|
|
131
|
+
return `container.registerModule(${varName});`;
|
|
132
|
+
})
|
|
133
|
+
.join('\n');
|
|
134
|
+
return `/**
|
|
135
|
+
* This file is auto-generated by ioc-arise.
|
|
136
|
+
* Do not modify this file manually.
|
|
137
|
+
*/
|
|
138
|
+
import { Container } from 'ioc-arise';
|
|
139
|
+
import type { ContainerRegistry } from './${dtsFilename}';
|
|
140
|
+
${moduleImports.join('\n')}
|
|
141
|
+
|
|
142
|
+
export const container = new Container<ContainerRegistry>();
|
|
143
|
+
|
|
144
|
+
${moduleInstantiations}
|
|
145
|
+
`;
|
|
146
|
+
}
|
|
147
|
+
static generateModularCode(moduleGroupedClasses, outputPath) {
|
|
148
|
+
const allClasses = Array.from(moduleGroupedClasses.values()).flat();
|
|
149
|
+
// Collect all interface names
|
|
150
|
+
const interfaceNames = new Set();
|
|
151
|
+
allClasses.forEach(cls => {
|
|
152
|
+
if (cls.interfaceName) {
|
|
153
|
+
interfaceNames.add(cls.interfaceName);
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
const imports = this.generateImports(allClasses, outputPath);
|
|
157
|
+
const moduleDefinitions = this.generateModuleDefinitions(moduleGroupedClasses, interfaceNames);
|
|
158
|
+
const moduleInstantiations = this.generateModuleInstantiations(moduleGroupedClasses);
|
|
159
|
+
const filename = outputPath.split('/').pop()?.replace(/\.ts$/, '') || 'container.gen';
|
|
160
|
+
const dtsFilename = outputPath.split('/').pop()?.replace(/\.ts$/, '.d') || 'container.gen.d';
|
|
161
|
+
return `/**
|
|
162
|
+
* This file is auto-generated by ioc-arise.
|
|
163
|
+
* Do not modify this file manually.
|
|
164
|
+
*/
|
|
165
|
+
import { Container, ContainerModule, Lifecycle } from 'ioc-arise';
|
|
166
|
+
import type { ContainerRegistry } from './${dtsFilename}';
|
|
167
|
+
${imports}
|
|
168
|
+
|
|
169
|
+
${moduleDefinitions}
|
|
170
|
+
|
|
171
|
+
export const container = new Container<ContainerRegistry>();
|
|
172
|
+
|
|
173
|
+
${moduleInstantiations}
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
static generateModuleDefinitions(moduleGroupedClasses, interfaceNames) {
|
|
177
|
+
const modules = [];
|
|
178
|
+
for (const [moduleName, classes] of moduleGroupedClasses.entries()) {
|
|
179
|
+
const registrations = this.generateModuleRegistrations(classes, interfaceNames);
|
|
180
|
+
modules.push(`const ${moduleName.charAt(0).toLowerCase() + moduleName.slice(1)} = new ContainerModule()
|
|
181
|
+
${registrations};`);
|
|
182
|
+
}
|
|
183
|
+
return modules.join('\n\n');
|
|
184
|
+
}
|
|
185
|
+
static generateModuleInstantiations(moduleGroupedClasses) {
|
|
186
|
+
const moduleNames = Array.from(moduleGroupedClasses.keys());
|
|
187
|
+
const instantiations = moduleNames.map(name => {
|
|
188
|
+
const varName = name.charAt(0).toLowerCase() + name.slice(1);
|
|
189
|
+
return `container.registerModule(${varName});`;
|
|
190
|
+
});
|
|
191
|
+
return instantiations.join('\n');
|
|
192
|
+
}
|
|
193
|
+
static generateModuleRegistrations(classes, interfaceNames, abstractClassNames = new Set()) {
|
|
194
|
+
return classes.map(cls => {
|
|
195
|
+
// Get the aliased class name (or original if no alias)
|
|
196
|
+
const className = this.classNameAliases.get(cls.filePath) || cls.name;
|
|
197
|
+
// Determine registration token
|
|
198
|
+
const token = cls.interfaceName
|
|
199
|
+
? `'${cls.interfaceName}'`
|
|
200
|
+
: cls.abstractClassName
|
|
201
|
+
? `'${cls.abstractClassName}'`
|
|
202
|
+
: className;
|
|
203
|
+
// Generate dependencies array
|
|
204
|
+
const dependencies = cls.dependencies.length > 0
|
|
205
|
+
? `, dependencies: [${cls.dependencies.map(dep => {
|
|
206
|
+
// If dependency is an interface, use string token
|
|
207
|
+
if (interfaceNames.has(dep.name)) {
|
|
208
|
+
return `'${dep.name}'`;
|
|
209
|
+
}
|
|
210
|
+
// If dependency is an abstract class, use string token
|
|
211
|
+
if (abstractClassNames.has(dep.name)) {
|
|
212
|
+
return `'${dep.name}'`;
|
|
213
|
+
}
|
|
214
|
+
// Check if this dependency name has collisions (multiple aliases)
|
|
215
|
+
const aliasMap = this.classNameToAliasMap.get(dep.name);
|
|
216
|
+
if (aliasMap && aliasMap.size > 0) {
|
|
217
|
+
// Resolve which specific alias to use based on import path
|
|
218
|
+
const depFilePath = this.resolveDependencyFilePath(cls.filePath, dep.importPath, dep.name);
|
|
219
|
+
const alias = this.classNameAliases.get(depFilePath);
|
|
220
|
+
if (alias) {
|
|
221
|
+
return alias;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// No collision or couldn't resolve - use original name
|
|
225
|
+
return dep.name;
|
|
226
|
+
}).join(', ')}]`
|
|
227
|
+
: '';
|
|
228
|
+
// Determine lifecycle enum value
|
|
229
|
+
const lifecycle = cls.scope === 'singleton'
|
|
230
|
+
? 'Lifecycle.Singleton'
|
|
231
|
+
: 'Lifecycle.Transient';
|
|
232
|
+
return ` .register(${token}, { useClass: ${className}${dependencies}, lifecycle: ${lifecycle} })`;
|
|
233
|
+
}).join('\n');
|
|
234
|
+
}
|
|
235
|
+
static generateImports(classes, outputPath) {
|
|
236
|
+
const outputDir = (0, path_1.dirname)(outputPath);
|
|
237
|
+
// Detect name collisions and create aliases
|
|
238
|
+
const nameToClasses = new Map();
|
|
239
|
+
classes.forEach(cls => {
|
|
240
|
+
if (!nameToClasses.has(cls.name)) {
|
|
241
|
+
nameToClasses.set(cls.name, []);
|
|
242
|
+
}
|
|
243
|
+
nameToClasses.get(cls.name).push(cls);
|
|
244
|
+
});
|
|
245
|
+
const importStatements = [];
|
|
246
|
+
const classNameAliases = new Map(); // filePath -> alias
|
|
247
|
+
const classNameToAliasMap = new Map(); // className -> (filePath -> alias)
|
|
248
|
+
classes.forEach(cls => {
|
|
249
|
+
// Calculate relative path from output file to class file
|
|
250
|
+
let relativePath = (0, path_1.relative)(outputDir, cls.filePath);
|
|
251
|
+
// Remove extension (.ts)
|
|
252
|
+
relativePath = relativePath.replace(/\.ts$/, '');
|
|
253
|
+
// Add ./ if it doesn't start with . or /
|
|
254
|
+
if (!relativePath.startsWith('.')) {
|
|
255
|
+
relativePath = `./${relativePath}`;
|
|
256
|
+
}
|
|
257
|
+
// Use forward slashes for imports
|
|
258
|
+
relativePath = relativePath.replace(/\\/g, '/');
|
|
259
|
+
// Check if this class name has collisions
|
|
260
|
+
const classesWithSameName = nameToClasses.get(cls.name) || [];
|
|
261
|
+
if (classesWithSameName.length > 1) {
|
|
262
|
+
// Name collision detected - create an alias
|
|
263
|
+
// Use the parent directory name as prefix (e.g., user/UpdateItemUseCase -> UserUpdateItemUseCase)
|
|
264
|
+
const pathParts = cls.filePath.split('/');
|
|
265
|
+
const parentDir = pathParts[pathParts.length - 2] || 'Item';
|
|
266
|
+
const alias = `${parentDir.charAt(0).toUpperCase() + parentDir.slice(1)}${cls.name}`;
|
|
267
|
+
classNameAliases.set(cls.filePath, alias);
|
|
268
|
+
// Track alias by class name too
|
|
269
|
+
if (!classNameToAliasMap.has(cls.name)) {
|
|
270
|
+
classNameToAliasMap.set(cls.name, new Map());
|
|
271
|
+
}
|
|
272
|
+
classNameToAliasMap.get(cls.name).set(cls.filePath, alias);
|
|
273
|
+
importStatements.push(`import { ${cls.name} as ${alias} } from '${relativePath}';`);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
// No collision - use regular import
|
|
277
|
+
classNameAliases.set(cls.filePath, cls.name);
|
|
278
|
+
importStatements.push(`import { ${cls.name} } from '${relativePath}';`);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
// Store aliases for use in registrations
|
|
282
|
+
this.classNameAliases = classNameAliases;
|
|
283
|
+
this.classNameToAliasMap = classNameToAliasMap;
|
|
284
|
+
return importStatements.join('\n');
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Resolves the full file path of a dependency based on the importing file and relative import path
|
|
288
|
+
*/
|
|
289
|
+
static resolveDependencyFilePath(importerFilePath, relativeImportPath, depName) {
|
|
290
|
+
const importerDir = (0, path_1.dirname)(importerFilePath);
|
|
291
|
+
const resolvedPath = (0, path_1.join)(importerDir, relativeImportPath);
|
|
292
|
+
// Try with .ts extension first
|
|
293
|
+
if (resolvedPath.endsWith('.ts')) {
|
|
294
|
+
return resolvedPath;
|
|
295
|
+
}
|
|
296
|
+
// Add .ts extension and normalize
|
|
297
|
+
const withExtension = `${resolvedPath}.ts`;
|
|
298
|
+
return withExtension;
|
|
299
|
+
}
|
|
300
|
+
static generateRegistrations(classes, interfaceNames, indent = '', abstractClassNames = new Set()) {
|
|
301
|
+
return classes.map(cls => {
|
|
302
|
+
// Get the aliased class name (or original if no alias)
|
|
303
|
+
const className = this.classNameAliases.get(cls.filePath) || cls.name;
|
|
304
|
+
// Determine registration token:
|
|
305
|
+
// - If implements interface, use string token of interface name
|
|
306
|
+
// - If extends abstract class, use string token of abstract class name
|
|
307
|
+
// - Otherwise, use class constructor
|
|
308
|
+
const token = cls.interfaceName
|
|
309
|
+
? `'${cls.interfaceName}'`
|
|
310
|
+
: cls.abstractClassName
|
|
311
|
+
? `'${cls.abstractClassName}'`
|
|
312
|
+
: className;
|
|
313
|
+
// Generate dependencies array
|
|
314
|
+
const dependencies = cls.dependencies.length > 0
|
|
315
|
+
? `\n${indent} dependencies: [${cls.dependencies.map(dep => {
|
|
316
|
+
// If dependency is an interface, use string token
|
|
317
|
+
if (interfaceNames.has(dep.name)) {
|
|
318
|
+
return `'${dep.name}'`;
|
|
319
|
+
}
|
|
320
|
+
// If dependency is an abstract class, use string token
|
|
321
|
+
if (abstractClassNames.has(dep.name)) {
|
|
322
|
+
return `'${dep.name}'`;
|
|
323
|
+
}
|
|
324
|
+
// Check if this dependency name has collisions (multiple aliases)
|
|
325
|
+
const aliasMap = this.classNameToAliasMap.get(dep.name);
|
|
326
|
+
if (aliasMap && aliasMap.size > 0) {
|
|
327
|
+
// We need to resolve which specific alias to use based on import path
|
|
328
|
+
// Try to find the matching class by resolving the import path
|
|
329
|
+
const depFilePath = this.resolveDependencyFilePath(cls.filePath, dep.importPath, dep.name);
|
|
330
|
+
const alias = this.classNameAliases.get(depFilePath);
|
|
331
|
+
if (alias) {
|
|
332
|
+
return alias;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
// No collision or couldn't resolve - use original name
|
|
336
|
+
return dep.name;
|
|
337
|
+
}).join(', ')}],`
|
|
338
|
+
: '';
|
|
339
|
+
// Determine lifecycle enum value
|
|
340
|
+
const lifecycle = cls.scope === 'singleton'
|
|
341
|
+
? 'Lifecycle.Singleton'
|
|
342
|
+
: 'Lifecycle.Transient';
|
|
343
|
+
return `${indent}container.register(${token}, {
|
|
344
|
+
${indent} useClass: ${className},${dependencies}
|
|
345
|
+
${indent} lifecycle: ${lifecycle},
|
|
346
|
+
${indent}});`;
|
|
347
|
+
}).join('\n\n');
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.IoCContainerGenerator = IoCContainerGenerator;
|
|
351
|
+
IoCContainerGenerator.classNameAliases = new Map(); // filePath -> alias
|
|
352
|
+
IoCContainerGenerator.classNameToAliasMap = new Map(); // className -> (filePath -> alias)
|
|
353
|
+
//# sourceMappingURL=ioc-container-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ioc-container-generator.js","sourceRoot":"","sources":["../../src/generator/ioc-container-generator.ts"],"names":[],"mappings":";;;AACA,+BAAyD;AACzD,2BAA8C;AAC9C,6EAAwE;AAExE,MAAa,qBAAqB;IAC9B;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CACX,OAAoB,EACpB,UAAkB,EAClB,oBAA+C;QAE/C,0BAA0B;QAC1B,MAAM,SAAS,GAAG,IAAA,cAAO,EAAC,UAAU,CAAC,CAAC;QACtC,IAAA,cAAS,EAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAE1C,IAAI,oBAAoB,IAAI,oBAAoB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YACxD,4DAA4D;YAC5D,IAAI,CAAC,oBAAoB,CAAC,oBAAoB,EAAE,UAAU,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACJ,4BAA4B;YAC5B,MAAM,aAAa,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YACjE,IAAA,kBAAa,EAAC,UAAU,EAAE,aAAa,CAAC,CAAC;QAC7C,CAAC;QAED,0CAA0C;QAC1C,MAAM,SAAS,GAAG,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC;YAC5C,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,YAAY,EAAE,WAAW,CAAC;YAC/C,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC3C,qDAAwB,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC1D,CAAC;IAEO,MAAM,CAAC,gBAAgB,CAAC,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B,CAAC,CAAC,qBAAqB,CAAC;YAE5B,OAAO,GAAG,MAAM,sBAAsB,KAAK;EACrD,MAAM,eAAe,SAAS,IAAI,YAAY;EAC9C,MAAM,gBAAgB,SAAS;EAC/B,MAAM,KAAK,CAAC;QACN,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;;AAzbL,sDA0bC;AAlFkB,sCAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC,CAAC,oBAAoB;AAClE,yCAAmB,GAAG,IAAI,GAAG,EAA+B,CAAC,CAAC,mCAAmC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClassInfo } from '../types';
|
|
2
|
+
export declare class TypeDeclarationGenerator {
|
|
3
|
+
static generate(classes: ClassInfo[], outputPath: string): void;
|
|
4
|
+
private static generateTypeDeclarations;
|
|
5
|
+
private static generateTypeImports;
|
|
6
|
+
private static findInterfaceLocations;
|
|
7
|
+
private static generateRegistryInterface;
|
|
8
|
+
private static generateModuleAugmentation;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=type-declaration-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-declaration-generator.d.ts","sourceRoot":"","sources":["../../src/generator/type-declaration-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,qBAAa,wBAAwB;IACjC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;IAO/D,OAAO,CAAC,MAAM,CAAC,wBAAwB;IA4CvC,OAAO,CAAC,MAAM,CAAC,mBAAmB;IA+BlC,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAgDrC,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAWxC,OAAO,CAAC,MAAM,CAAC,0BAA0B;CAgB5C"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeDeclarationGenerator = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
class TypeDeclarationGenerator {
|
|
7
|
+
static generate(classes, outputPath) {
|
|
8
|
+
// outputPath already has .d.ts extension from the generator
|
|
9
|
+
const typeDeclarations = this.generateTypeDeclarations(classes, outputPath);
|
|
10
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(outputPath), { recursive: true });
|
|
11
|
+
(0, fs_1.writeFileSync)(outputPath, typeDeclarations);
|
|
12
|
+
}
|
|
13
|
+
static generateTypeDeclarations(classes, outputPath) {
|
|
14
|
+
// Filter classes that have interface implementations or abstract class implementations
|
|
15
|
+
const interfaceClasses = classes.filter(cls => cls.interfaceName);
|
|
16
|
+
const abstractClasses = classes.filter(cls => cls.abstractClassName);
|
|
17
|
+
if (interfaceClasses.length === 0 && abstractClasses.length === 0) {
|
|
18
|
+
// No interfaces or abstract classes, generate minimal type file
|
|
19
|
+
return `/**
|
|
20
|
+
* This file is auto-generated by ioc-arise.
|
|
21
|
+
* Do not modify this file manually.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export interface ContainerRegistry {}
|
|
25
|
+
`;
|
|
26
|
+
}
|
|
27
|
+
const typeImports = this.generateTypeImports(interfaceClasses, abstractClasses, outputPath);
|
|
28
|
+
// Build registry entries for both interfaces and abstract classes
|
|
29
|
+
const registryEntries = [];
|
|
30
|
+
interfaceClasses.forEach(cls => {
|
|
31
|
+
registryEntries.push(` '${cls.interfaceName}': ${cls.interfaceName};`);
|
|
32
|
+
});
|
|
33
|
+
abstractClasses.forEach(cls => {
|
|
34
|
+
// For abstract classes, we use the concrete implementation type
|
|
35
|
+
registryEntries.push(` '${cls.abstractClassName}': ${cls.name};`);
|
|
36
|
+
});
|
|
37
|
+
return `/**
|
|
38
|
+
* This file is auto-generated by ioc-arise.
|
|
39
|
+
* Do not modify this file manually.
|
|
40
|
+
*
|
|
41
|
+
* This file provides type-safe resolution for string-based tokens.
|
|
42
|
+
*/
|
|
43
|
+
${typeImports}
|
|
44
|
+
|
|
45
|
+
export interface ContainerRegistry {
|
|
46
|
+
${registryEntries.join('\n')}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
static generateTypeImports(interfaceClasses, abstractClasses, outputPath) {
|
|
51
|
+
const outputDir = (0, path_1.dirname)(outputPath);
|
|
52
|
+
const imports = [];
|
|
53
|
+
// Build a map of interface names to their actual file paths by searching the source
|
|
54
|
+
const interfaceLocations = this.findInterfaceLocations(interfaceClasses, outputDir);
|
|
55
|
+
interfaceClasses.forEach(cls => {
|
|
56
|
+
if (!cls.interfaceName)
|
|
57
|
+
return;
|
|
58
|
+
const relativePath = interfaceLocations.get(cls.interfaceName);
|
|
59
|
+
if (relativePath) {
|
|
60
|
+
imports.push(`import type { ${cls.interfaceName} } from '${relativePath}';`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
// For abstract classes, import the concrete implementation class
|
|
64
|
+
abstractClasses.forEach(cls => {
|
|
65
|
+
let relativePath = (0, path_1.relative)(outputDir, cls.filePath);
|
|
66
|
+
relativePath = relativePath.replace(/\.ts$/, '');
|
|
67
|
+
if (!relativePath.startsWith('.')) {
|
|
68
|
+
relativePath = `./${relativePath}`;
|
|
69
|
+
}
|
|
70
|
+
relativePath = relativePath.replace(/\\/g, '/');
|
|
71
|
+
imports.push(`import type { ${cls.name} } from '${relativePath}';`);
|
|
72
|
+
});
|
|
73
|
+
return imports.join('\n');
|
|
74
|
+
}
|
|
75
|
+
static findInterfaceLocations(classes, outputDir) {
|
|
76
|
+
const interfaceLocations = new Map();
|
|
77
|
+
const interfaceNames = new Set(classes.filter(c => c.interfaceName).map(c => c.interfaceName));
|
|
78
|
+
if (interfaceNames.size === 0)
|
|
79
|
+
return interfaceLocations;
|
|
80
|
+
// For each class with an interface, parse its file to find the actual interface import
|
|
81
|
+
classes.forEach(cls => {
|
|
82
|
+
if (!cls.interfaceName || interfaceLocations.has(cls.interfaceName))
|
|
83
|
+
return;
|
|
84
|
+
try {
|
|
85
|
+
const fileContent = (0, fs_1.readFileSync)(cls.filePath, 'utf-8');
|
|
86
|
+
// Match: import { InterfaceName } from './path';
|
|
87
|
+
// or: import type { InterfaceName } from './path';
|
|
88
|
+
const importRegex = new RegExp(`import\\s+(?:type\\s+)?\\{[^}]*\\b${cls.interfaceName}\\b[^}]*\\}\\s+from\\s+['"]([^'"]+)['"]`, 'g');
|
|
89
|
+
const match = importRegex.exec(fileContent);
|
|
90
|
+
if (match && match[1]) {
|
|
91
|
+
// Found the import path relative to the class file
|
|
92
|
+
const classDir = (0, path_1.dirname)(cls.filePath);
|
|
93
|
+
const interfacePathFromClass = match[1];
|
|
94
|
+
// Resolve the absolute path of the interface file
|
|
95
|
+
const interfaceAbsPath = require('path').resolve(classDir, interfacePathFromClass);
|
|
96
|
+
// Calculate relative path from output directory
|
|
97
|
+
let relativePath = (0, path_1.relative)(outputDir, interfaceAbsPath);
|
|
98
|
+
// Normalize
|
|
99
|
+
if (!relativePath.startsWith('.')) {
|
|
100
|
+
relativePath = `./${relativePath}`;
|
|
101
|
+
}
|
|
102
|
+
relativePath = relativePath.replace(/\\/g, '/');
|
|
103
|
+
interfaceLocations.set(cls.interfaceName, relativePath);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
// If we can't read the file or parse it, skip
|
|
108
|
+
console.warn(`Could not parse interface location for ${cls.interfaceName} in ${cls.filePath}`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
return interfaceLocations;
|
|
112
|
+
}
|
|
113
|
+
static generateRegistryInterface(classes) {
|
|
114
|
+
const registrations = classes
|
|
115
|
+
.filter(cls => cls.interfaceName)
|
|
116
|
+
.map(cls => ` '${cls.interfaceName}': ${cls.interfaceName};`)
|
|
117
|
+
.join('\n');
|
|
118
|
+
return `export interface ContainerRegistry {
|
|
119
|
+
${registrations}
|
|
120
|
+
}`;
|
|
121
|
+
}
|
|
122
|
+
static generateModuleAugmentation() {
|
|
123
|
+
return `declare module 'ioc-arise' {
|
|
124
|
+
interface Container {
|
|
125
|
+
/**
|
|
126
|
+
* Type-safe resolve for registered string tokens.
|
|
127
|
+
* Returns the correctly typed instance based on the token.
|
|
128
|
+
*/
|
|
129
|
+
resolve<K extends keyof ContainerRegistry>(token: K): ContainerRegistry[K];
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Generic resolve for class constructors or other token types.
|
|
133
|
+
*/
|
|
134
|
+
resolve<T>(token: import('ioc-arise').Token<T>): T;
|
|
135
|
+
}
|
|
136
|
+
}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
exports.TypeDeclarationGenerator = TypeDeclarationGenerator;
|
|
140
|
+
//# sourceMappingURL=type-declaration-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-declaration-generator.js","sourceRoot":"","sources":["../../src/generator/type-declaration-generator.ts"],"names":[],"mappings":";;;AACA,+BAAyC;AACzC,2BAAwE;AAGxE,MAAa,wBAAwB;IACjC,MAAM,CAAC,QAAQ,CAAC,OAAoB,EAAE,UAAkB;QACpD,4DAA4D;QAC5D,MAAM,gBAAgB,GAAG,IAAI,CAAC,wBAAwB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC5E,IAAA,cAAS,EAAC,IAAA,cAAO,EAAC,UAAU,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpD,IAAA,kBAAa,EAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAChD,CAAC;IAEO,MAAM,CAAC,wBAAwB,CAAC,OAAoB,EAAE,UAAkB;QAC5E,uFAAuF;QACvF,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAA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AO,CAAC,IAAI,CAAC,0CAA0C,GAAG,CAAC,aAAa,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YACnG,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,kBAAkB,CAAC;IAC9B,CAAC;IAEO,MAAM,CAAC,yBAAyB,CAAC,OAAoB;QACzD,MAAM,aAAa,GAAG,OAAO;aACxB,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC;aAChC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,aAAa,MAAM,GAAG,CAAC,aAAa,GAAG,CAAC;aAC7D,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhB,OAAO;EACb,aAAa;EACb,CAAC;IACC,CAAC;IAEO,MAAM,CAAC,0BAA0B;QACrC,OAAO;;;;;;;;;;;;;EAab,CAAC;IACC,CAAC;CACJ;AA9JD,4DA8JC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ClassInfo } from '../types';
|
|
2
|
+
export declare class CircularDependencyDetector {
|
|
3
|
+
/**
|
|
4
|
+
* Detects circular dependencies in a list of classes
|
|
5
|
+
* @param classes - Array of analyzed classes
|
|
6
|
+
* @returns Array of cycles, where each cycle is an array of class names involved
|
|
7
|
+
*/
|
|
8
|
+
static detect(classes: ClassInfo[]): string[][];
|
|
9
|
+
/**
|
|
10
|
+
* Detects circular dependencies between modules
|
|
11
|
+
* @param moduleGroupedClasses - Map of module name to classes in that module
|
|
12
|
+
* @returns Array of cycles, where each cycle is an array of module names involved
|
|
13
|
+
*/
|
|
14
|
+
static detectModuleCycles(moduleGroupedClasses: Map<string, ClassInfo[]>): string[][];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=circular-dependency-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circular-dependency-detector.d.ts","sourceRoot":"","sources":["../../src/utils/circular-dependency-detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,qBAAa,0BAA0B;IACnC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,EAAE,EAAE;IA0B/C;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE;CAuCxF"}
|