@art-ws/di 2.0.13 → 2.0.14
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/dist/es/injector.js +22 -6
- package/dist/es/types.d.ts +1 -0
- package/package.json +3 -3
package/dist/es/injector.js
CHANGED
@@ -24,14 +24,15 @@ export class Injector {
|
|
24
24
|
this.addFactory(token, () => value);
|
25
25
|
}
|
26
26
|
addModuleInner(set, ...modules) {
|
27
|
-
for (const
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
for (const m of modules) {
|
28
|
+
if (set.has(m)) {
|
29
|
+
throw new Error(`Circular dependency detected: ${getModuleName(m)}`);
|
30
|
+
}
|
31
|
+
set.add(m);
|
32
|
+
for (const imp of m.imports || []) {
|
32
33
|
this.addModuleInner(set, imp);
|
33
34
|
}
|
34
|
-
this.addProviders(...(
|
35
|
+
this.addProviders(...(m.providers || []));
|
35
36
|
}
|
36
37
|
}
|
37
38
|
addModule(...modules) {
|
@@ -122,3 +123,18 @@ export function inject(token) {
|
|
122
123
|
function isClass(value) {
|
123
124
|
return typeof value === "function" && !!value.prototype;
|
124
125
|
}
|
126
|
+
function getModuleName(module) {
|
127
|
+
let name = module.name;
|
128
|
+
if (!name && module.providers?.length) {
|
129
|
+
const providers = module.providers
|
130
|
+
.map((p) => {
|
131
|
+
if (isClass(p))
|
132
|
+
return p.name;
|
133
|
+
return p.toString();
|
134
|
+
})
|
135
|
+
.join(", ");
|
136
|
+
name = `Module{providers:[${providers}]}`;
|
137
|
+
}
|
138
|
+
name = name || "Unknown Module";
|
139
|
+
return name;
|
140
|
+
}
|
package/dist/es/types.d.ts
CHANGED
@@ -27,6 +27,7 @@ export type ProviderAngularLikeDef<T = unknown> = {
|
|
27
27
|
};
|
28
28
|
export type Provider<T = unknown> = Type<T> | ProviderCoreDef<T> | ProviderAngularLikeDef<T>;
|
29
29
|
export type DIModuleDef = {
|
30
|
+
name?: string;
|
30
31
|
imports?: DIModuleDef[];
|
31
32
|
providers?: Provider[];
|
32
33
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@art-ws/di",
|
3
|
-
"version": "2.0.
|
3
|
+
"version": "2.0.14",
|
4
4
|
"description": "Dependency injection for TypeScript",
|
5
5
|
"license": "UNLICENSED",
|
6
6
|
"author": "art-ws Team",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"eslint": "^9.34.0",
|
16
16
|
"typescript": "^5.9.2",
|
17
17
|
"vitest": "^3.2.4",
|
18
|
-
"@art-ws/config-
|
19
|
-
"@art-ws/config-
|
18
|
+
"@art-ws/config-eslint": "2.0.3",
|
19
|
+
"@art-ws/config-ts": "2.0.6"
|
20
20
|
},
|
21
21
|
"scripts": {
|
22
22
|
"build": "tsc",
|