@xrystal/core 3.14.3 → 3.14.4
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/package.json
CHANGED
package/source/project/index.js
CHANGED
|
@@ -16,14 +16,11 @@ const coreLoader = async ({}) => {
|
|
|
16
16
|
try {
|
|
17
17
|
const { configs } = core._;
|
|
18
18
|
const rootFolderPath = configs.rootFolderPath;
|
|
19
|
-
x
|
|
20
|
-
.load([
|
|
19
|
+
await (await x.load([
|
|
21
20
|
path.join(__dirname, '..', 'loader', '**/*.{ts,js}'),
|
|
22
21
|
], {
|
|
23
|
-
exclude: [
|
|
24
|
-
|
|
25
|
-
]
|
|
26
|
-
})
|
|
22
|
+
exclude: [path.join(__dirname, '..', 'utils', '**/class.x.{ts,js}')]
|
|
23
|
+
}))
|
|
27
24
|
.initialize([
|
|
28
25
|
{
|
|
29
26
|
service: SystemService,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LifetimeType } from 'awilix';
|
|
2
2
|
export declare class X {
|
|
3
3
|
private container;
|
|
4
4
|
private initializedNames;
|
|
@@ -6,9 +6,9 @@ export declare class X {
|
|
|
6
6
|
private getSource;
|
|
7
7
|
load(patterns: string | string[], options?: {
|
|
8
8
|
verbose?: boolean;
|
|
9
|
-
exclude?:
|
|
9
|
+
exclude?: (string | Function)[];
|
|
10
10
|
lifetime?: LifetimeType;
|
|
11
|
-
}): this
|
|
11
|
+
}): Promise<this>;
|
|
12
12
|
register(Dependency: any, lifetime?: LifetimeType): this;
|
|
13
13
|
registerAll(dependencies: any[], lifetime?: LifetimeType): this;
|
|
14
14
|
registerInstance(name: string, instance: any): this;
|
|
@@ -20,10 +20,8 @@ export declare class X {
|
|
|
20
20
|
props?: any;
|
|
21
21
|
}[], verbose?: boolean): Promise<this>;
|
|
22
22
|
get<T>(target: string | any): T;
|
|
23
|
-
createScope(): AwilixContainer<any>;
|
|
24
23
|
get cradle(): any;
|
|
25
24
|
private isRegistered;
|
|
26
|
-
private getSourceByInstance;
|
|
27
25
|
}
|
|
28
26
|
declare const _default: X;
|
|
29
27
|
export default _default;
|
|
@@ -14,7 +14,8 @@ export class X {
|
|
|
14
14
|
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
15
15
|
return normalizedPath.includes('node_modules') || !normalizedPath.startsWith(projectRoot) ? 'LIB' : 'APP';
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
// 1. ASYNC YAPTIK (await import desteği için)
|
|
18
|
+
async load(patterns, options = {}) {
|
|
18
19
|
const { verbose = false, exclude = [], lifetime = Lifetime.SINGLETON } = options;
|
|
19
20
|
const cwd = process.cwd();
|
|
20
21
|
const excludeList = Array.isArray(exclude) ? exclude : [exclude];
|
|
@@ -32,26 +33,33 @@ export class X {
|
|
|
32
33
|
}
|
|
33
34
|
for (const m of modules) {
|
|
34
35
|
const source = this.getSource(m.path);
|
|
35
|
-
|
|
36
|
+
const normalizedMPath = m.path.replace(/\\/g, '/');
|
|
37
|
+
if (normalizedMPath === __filename.replace(/\\/g, '/') || normalizedMPath.endsWith('.d.ts'))
|
|
36
38
|
continue;
|
|
39
|
+
// --- KRİTİK DÜZELTME 1: DOSYAYI YÜKLEMEDEN ÖNCE EXCLUDE KONTROLÜ ---
|
|
40
|
+
const isPathExcluded = excludeList.some(ex => {
|
|
41
|
+
if (typeof ex === 'string') {
|
|
42
|
+
const normalizedEx = ex.replace(/\\/g, '/');
|
|
43
|
+
return normalizedMPath.includes(normalizedEx) || m.name === ex;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
});
|
|
47
|
+
if (isPathExcluded) {
|
|
48
|
+
if (verbose)
|
|
49
|
+
console.log(`[DI][${source}] Pre-load Excluded: ${m.name}`);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
37
52
|
try {
|
|
38
|
-
|
|
53
|
+
// --- KRİTİK DÜZELTME 2: REQUIRE YERİNE IMPORT (Async Module Hatası İçin) ---
|
|
54
|
+
const loaded = await import(m.path);
|
|
39
55
|
let dependency = loaded.default;
|
|
40
56
|
if (!dependency) {
|
|
41
57
|
dependency = Object.values(loaded).find(val => typeof val === 'function' && !!val.prototype && !!val.name);
|
|
42
58
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (typeof ex === 'function')
|
|
47
|
-
return dependency === ex;
|
|
48
|
-
return false;
|
|
49
|
-
});
|
|
50
|
-
if (isExcluded) {
|
|
51
|
-
if (verbose)
|
|
52
|
-
console.log(`[DI][${source}] Excluded: ${m.name}`);
|
|
59
|
+
// Class referansı üzerinden exclude (Eğer class yüklendiyse)
|
|
60
|
+
const isClassExcluded = excludeList.some(ex => typeof ex === 'function' && dependency === ex);
|
|
61
|
+
if (isClassExcluded)
|
|
53
62
|
continue;
|
|
54
|
-
}
|
|
55
63
|
const isClass = typeof dependency === 'function' && !!dependency.prototype && !!dependency.name;
|
|
56
64
|
if (isClass) {
|
|
57
65
|
const className = dependency.name;
|
|
@@ -61,25 +69,26 @@ export class X {
|
|
|
61
69
|
[name]: asClass(dependency).setLifetime(lifetime)
|
|
62
70
|
});
|
|
63
71
|
if (verbose)
|
|
64
|
-
console.log(`[DI][${source}] Registered
|
|
72
|
+
console.log(`[DI][${source}] Registered: ${name}`);
|
|
65
73
|
}
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
catch (err) {
|
|
69
|
-
|
|
77
|
+
// Burada hata alıyorsan dosya bozuktur veya import edilemiyordur
|
|
78
|
+
if (verbose)
|
|
79
|
+
console.error(`[DI][${source}] Load Error in ${m.name}:`, err.message);
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
return this;
|
|
73
83
|
}
|
|
84
|
+
// ... (register, initialize, get metodları aynı kalıyor)
|
|
74
85
|
register(Dependency, lifetime = Lifetime.SINGLETON) {
|
|
75
86
|
if (!Dependency?.name)
|
|
76
87
|
return this;
|
|
77
88
|
const name = Dependency.name.charAt(0).toLowerCase() + Dependency.name.slice(1);
|
|
78
89
|
if (this.isRegistered(name))
|
|
79
90
|
return this;
|
|
80
|
-
this.container.register({
|
|
81
|
-
[name]: asClass(Dependency).setLifetime(lifetime)
|
|
82
|
-
});
|
|
91
|
+
this.container.register({ [name]: asClass(Dependency).setLifetime(lifetime) });
|
|
83
92
|
return this;
|
|
84
93
|
}
|
|
85
94
|
registerAll(dependencies, lifetime = Lifetime.SINGLETON) {
|
|
@@ -117,16 +126,15 @@ export class X {
|
|
|
117
126
|
continue;
|
|
118
127
|
const instance = cradle[key];
|
|
119
128
|
if (instance && typeof instance.load === 'function') {
|
|
120
|
-
const source = this.getSourceByInstance(instance);
|
|
121
129
|
try {
|
|
122
130
|
const props = propsMap.get(key) || {};
|
|
123
131
|
await instance.load(props);
|
|
124
132
|
this.initializedNames.add(key);
|
|
125
133
|
if (verbose)
|
|
126
|
-
console.log(`[DI]
|
|
134
|
+
console.log(`[DI] Initialized: ${key}`);
|
|
127
135
|
}
|
|
128
136
|
catch (err) {
|
|
129
|
-
console.error(`[DI]
|
|
137
|
+
console.error(`[DI] Initialization Failed: ${key} ->`, err.message);
|
|
130
138
|
}
|
|
131
139
|
}
|
|
132
140
|
}
|
|
@@ -134,28 +142,19 @@ export class X {
|
|
|
134
142
|
}
|
|
135
143
|
get(target) {
|
|
136
144
|
try {
|
|
137
|
-
const resolveName = typeof target === 'function'
|
|
138
|
-
? target.name.charAt(0).toLowerCase() + target.name.slice(1)
|
|
139
|
-
: target;
|
|
145
|
+
const resolveName = typeof target === 'function' ? target.name.charAt(0).toLowerCase() + target.name.slice(1) : target;
|
|
140
146
|
return this.container.resolve(resolveName);
|
|
141
147
|
}
|
|
142
148
|
catch (err) {
|
|
143
149
|
if (err.message.includes('Cyclic dependencies')) {
|
|
144
|
-
console.error(
|
|
145
|
-
console.error(`🔍 Resolution Path: ${err.resolutionStack}`);
|
|
150
|
+
console.error(`\n❌ [DI][CRITICAL] Cyclic dependency detected!\n🔍 Path: ${err.resolutionStack}`);
|
|
146
151
|
}
|
|
147
152
|
throw err;
|
|
148
153
|
}
|
|
149
154
|
}
|
|
150
|
-
createScope() {
|
|
151
|
-
return this.container.createScope();
|
|
152
|
-
}
|
|
153
155
|
get cradle() { return this.container.cradle; }
|
|
154
156
|
isRegistered(name) {
|
|
155
157
|
return !!this.container.registrations[name] && this.container.registrations[name].resolve !== undefined;
|
|
156
158
|
}
|
|
157
|
-
getSourceByInstance(instance) {
|
|
158
|
-
return instance.constructor?.name?.includes('Service') || instance.constructor?.name?.includes('Controller') ? 'APP' : 'LIB';
|
|
159
|
-
}
|
|
160
159
|
}
|
|
161
160
|
export default new X();
|