@kanjijs/config 0.2.0-beta.15 → 0.2.0-beta.16
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/core/src/di/module-compiler.d.ts +1 -0
- package/dist/index.js +24 -10
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1531,12 +1531,14 @@ class KanjijsIoC {
|
|
|
1531
1531
|
KanjijsIoC.providers.set(target, provider);
|
|
1532
1532
|
}
|
|
1533
1533
|
if (!provider) {
|
|
1534
|
-
|
|
1534
|
+
const targetName2 = typeof target === "function" ? target.name ?? "anonymous" : String(target);
|
|
1535
|
+
throw new Error(`Provider not found for token: ${targetName2}`);
|
|
1535
1536
|
}
|
|
1536
1537
|
if (provider.instance) {
|
|
1537
1538
|
return provider.instance;
|
|
1538
1539
|
}
|
|
1539
|
-
|
|
1540
|
+
const targetName = typeof target === "function" ? target.name ?? "anonymous" : String(target);
|
|
1541
|
+
console.log(`[DI] Creating NEW instance for ${targetName}`);
|
|
1540
1542
|
if (provider.useValue !== undefined) {
|
|
1541
1543
|
provider.instance = provider.useValue;
|
|
1542
1544
|
} else if (provider.useClass) {
|
|
@@ -1565,7 +1567,8 @@ class Container {
|
|
|
1565
1567
|
resolve(token) {
|
|
1566
1568
|
const provider = this.providers.get(token);
|
|
1567
1569
|
if (!provider) {
|
|
1568
|
-
|
|
1570
|
+
const tokenName = typeof token === "function" ? token.name ?? "anonymous" : String(token);
|
|
1571
|
+
throw new Error(`[DI] Provider not found for token: ${tokenName}`);
|
|
1569
1572
|
}
|
|
1570
1573
|
if (provider.instance) {
|
|
1571
1574
|
return provider.instance;
|
|
@@ -1597,12 +1600,11 @@ class ModuleCompiler {
|
|
|
1597
1600
|
this.scan(rootModule);
|
|
1598
1601
|
this.validate();
|
|
1599
1602
|
const container = new Container;
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
container.register(token, definition);
|
|
1604
|
-
}
|
|
1603
|
+
const rootNode = this.nodes.get(rootModule);
|
|
1604
|
+
if (!rootNode) {
|
|
1605
|
+
return container;
|
|
1605
1606
|
}
|
|
1607
|
+
this.registerProviders(rootNode, container, new Set);
|
|
1606
1608
|
return container;
|
|
1607
1609
|
}
|
|
1608
1610
|
scan(target) {
|
|
@@ -1689,16 +1691,28 @@ class ModuleCompiler {
|
|
|
1689
1691
|
return overrideToken || paramType;
|
|
1690
1692
|
});
|
|
1691
1693
|
} else if ("useFactory" in provider) {
|
|
1692
|
-
targetName = typeof provider.provide === "function" ? provider.provide.name : String(provider.provide);
|
|
1694
|
+
targetName = typeof provider.provide === "function" ? provider.provide.name ?? "anonymous" : String(provider.provide);
|
|
1693
1695
|
dependencies = provider.inject || [];
|
|
1694
1696
|
}
|
|
1695
1697
|
for (const dep of dependencies) {
|
|
1696
1698
|
if (!visibleTokens.has(dep)) {
|
|
1697
|
-
const depName = typeof dep === "function" ? dep.name : String(dep);
|
|
1699
|
+
const depName = typeof dep === "function" ? dep.name ?? "anonymous" : String(dep);
|
|
1698
1700
|
throw new Error(`[Kanjijs] strict-di-error: Provider '${targetName}' in Module '${moduleName}' ` + `depends on '${depName}', but it is not visible. ` + `Make sure it is imported and exported by the source module.`);
|
|
1699
1701
|
}
|
|
1700
1702
|
}
|
|
1701
1703
|
}
|
|
1704
|
+
registerProviders(node, container, visited) {
|
|
1705
|
+
if (visited.has(node))
|
|
1706
|
+
return;
|
|
1707
|
+
visited.add(node);
|
|
1708
|
+
for (const imp of node.imports) {
|
|
1709
|
+
this.registerProviders(imp, container, visited);
|
|
1710
|
+
}
|
|
1711
|
+
for (const [token, provider] of node.providers) {
|
|
1712
|
+
const { provide: _provide, ...definition } = provider;
|
|
1713
|
+
container.register(token, definition);
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1702
1716
|
}
|
|
1703
1717
|
|
|
1704
1718
|
// ../core/src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/config",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "bun build src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --declaration --outDir dist"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@kanjijs/core": "^0.2.0-beta.
|
|
16
|
+
"@kanjijs/core": "^0.2.0-beta.16",
|
|
17
17
|
"dotenv": "^16.4.1",
|
|
18
18
|
"zod": "^3.22.4"
|
|
19
19
|
},
|