phecda-module 2.0.5 → 2.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/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +11 -0
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +20 -16
- package/dist/index.mjs +19 -15
- package/package.json +2 -2
- package/src/core.ts +20 -16
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> phecda-module@2.0
|
|
2
|
+
> phecda-module@2.1.0 build /home/runner/work/phecda/phecda/packages/module
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts, src/vite.ts
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
[34mCLI[39m Target: esnext
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m1.86 KB[39m
|
|
13
|
-
[32mESM[39m [1mdist/vite.mjs [22m[32m519.00 B[39m
|
|
14
|
-
[32mESM[39m ⚡️ Build success in 96ms
|
|
15
|
-
[32mCJS[39m [1mdist/index.js [22m[32m3.15 KB[39m
|
|
16
12
|
[32mCJS[39m [1mdist/vite.js [22m[32m1.34 KB[39m
|
|
17
|
-
[32mCJS[39m
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m3.26 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 85ms
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m1.95 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/vite.mjs [22m[32m519.00 B[39m
|
|
17
|
+
[32mESM[39m ⚡️ Build success in 87ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 5892ms
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m262.00 B[39m
|
|
21
21
|
[32mDTS[39m [1mdist/vite.d.ts [22m[32m210.00 B[39m
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m262.00 B[39m
|
|
23
23
|
[32mDTS[39m [1mdist/vite.d.mts [22m[32m210.00 B[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Construct } from 'phecda-core';
|
|
1
2
|
export * from 'phecda-core';
|
|
2
3
|
|
|
3
|
-
declare const moduleMap: Map<PropertyKey, any>;
|
|
4
4
|
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<void>;
|
|
5
|
+
declare function useM<Model extends Construct>(model: Model): InstanceType<Model>;
|
|
5
6
|
|
|
6
|
-
export { Factory,
|
|
7
|
+
export { Factory, useM };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { Construct } from 'phecda-core';
|
|
1
2
|
export * from 'phecda-core';
|
|
2
3
|
|
|
3
|
-
declare const moduleMap: Map<PropertyKey, any>;
|
|
4
4
|
declare function Factory(Modules: (new (...args: any) => any)[]): Promise<void>;
|
|
5
|
+
declare function useM<Model extends Construct>(model: Model): InstanceType<Model>;
|
|
5
6
|
|
|
6
|
-
export { Factory,
|
|
7
|
+
export { Factory, useM };
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
var index_exports = {};
|
|
24
24
|
__export(index_exports, {
|
|
25
25
|
Factory: () => Factory,
|
|
26
|
-
|
|
26
|
+
useM: () => useM
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
29
|
|
|
@@ -32,20 +32,10 @@ var import_phecda_core = require("phecda-core");
|
|
|
32
32
|
var import_reflect_metadata = require("reflect-metadata");
|
|
33
33
|
var moduleMap = /* @__PURE__ */ new Map();
|
|
34
34
|
async function Factory(Modules) {
|
|
35
|
-
for (const Module of Modules) await
|
|
35
|
+
for (const Module of Modules) await buildNestedModule(Module);
|
|
36
36
|
}
|
|
37
37
|
__name(Factory, "Factory");
|
|
38
|
-
|
|
39
|
-
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
40
|
-
target = Object.values(target)[0];
|
|
41
|
-
const tag = (0, import_phecda_core.getTag)(target);
|
|
42
|
-
const module2 = moduleMap.get(tag);
|
|
43
|
-
module2.destroy?.();
|
|
44
|
-
moduleMap.delete(tag);
|
|
45
|
-
buildNestModule(target);
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
async function buildNestModule(Module) {
|
|
38
|
+
async function buildNestedModule(Module) {
|
|
49
39
|
const paramtypes = getParamtypes(Module);
|
|
50
40
|
let instance;
|
|
51
41
|
const tag = (0, import_phecda_core.getTag)(Module);
|
|
@@ -57,7 +47,7 @@ async function buildNestModule(Module) {
|
|
|
57
47
|
moduleMap.set(tag, void 0);
|
|
58
48
|
if (paramtypes) {
|
|
59
49
|
const paramtypesInstances = [];
|
|
60
|
-
for (const i in paramtypes) paramtypesInstances[i] = await
|
|
50
|
+
for (const i in paramtypes) paramtypesInstances[i] = await buildNestedModule(paramtypes[i]);
|
|
61
51
|
instance = new Module(...paramtypesInstances);
|
|
62
52
|
} else {
|
|
63
53
|
instance = new Module();
|
|
@@ -78,17 +68,31 @@ async function buildNestModule(Module) {
|
|
|
78
68
|
}
|
|
79
69
|
return instance;
|
|
80
70
|
}
|
|
81
|
-
__name(
|
|
71
|
+
__name(buildNestedModule, "buildNestedModule");
|
|
82
72
|
function getParamtypes(Module, key) {
|
|
83
73
|
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
84
74
|
}
|
|
85
75
|
__name(getParamtypes, "getParamtypes");
|
|
76
|
+
function useM(model) {
|
|
77
|
+
return moduleMap.get((0, import_phecda_core.getTag)(model));
|
|
78
|
+
}
|
|
79
|
+
__name(useM, "useM");
|
|
80
|
+
if (__DEV__) {
|
|
81
|
+
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
82
|
+
target = Object.values(target)[0];
|
|
83
|
+
const tag = (0, import_phecda_core.getTag)(target);
|
|
84
|
+
const module2 = moduleMap.get(tag);
|
|
85
|
+
module2.destroy?.();
|
|
86
|
+
moduleMap.delete(tag);
|
|
87
|
+
buildNestedModule(target);
|
|
88
|
+
};
|
|
89
|
+
}
|
|
86
90
|
|
|
87
91
|
// src/index.ts
|
|
88
92
|
__reExport(index_exports, require("phecda-core"), module.exports);
|
|
89
93
|
// Annotate the CommonJS export names for ESM import in node:
|
|
90
94
|
0 && (module.exports = {
|
|
91
95
|
Factory,
|
|
92
|
-
|
|
96
|
+
useM,
|
|
93
97
|
...require("phecda-core")
|
|
94
98
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -6,20 +6,10 @@ import { getTag, invokeInit } from "phecda-core";
|
|
|
6
6
|
import "reflect-metadata";
|
|
7
7
|
var moduleMap = /* @__PURE__ */ new Map();
|
|
8
8
|
async function Factory(Modules) {
|
|
9
|
-
for (const Module of Modules) await
|
|
9
|
+
for (const Module of Modules) await buildNestedModule(Module);
|
|
10
10
|
}
|
|
11
11
|
__name(Factory, "Factory");
|
|
12
|
-
|
|
13
|
-
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
14
|
-
target = Object.values(target)[0];
|
|
15
|
-
const tag = getTag(target);
|
|
16
|
-
const module = moduleMap.get(tag);
|
|
17
|
-
module.destroy?.();
|
|
18
|
-
moduleMap.delete(tag);
|
|
19
|
-
buildNestModule(target);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
async function buildNestModule(Module) {
|
|
12
|
+
async function buildNestedModule(Module) {
|
|
23
13
|
const paramtypes = getParamtypes(Module);
|
|
24
14
|
let instance;
|
|
25
15
|
const tag = getTag(Module);
|
|
@@ -31,7 +21,7 @@ async function buildNestModule(Module) {
|
|
|
31
21
|
moduleMap.set(tag, void 0);
|
|
32
22
|
if (paramtypes) {
|
|
33
23
|
const paramtypesInstances = [];
|
|
34
|
-
for (const i in paramtypes) paramtypesInstances[i] = await
|
|
24
|
+
for (const i in paramtypes) paramtypesInstances[i] = await buildNestedModule(paramtypes[i]);
|
|
35
25
|
instance = new Module(...paramtypesInstances);
|
|
36
26
|
} else {
|
|
37
27
|
instance = new Module();
|
|
@@ -52,15 +42,29 @@ async function buildNestModule(Module) {
|
|
|
52
42
|
}
|
|
53
43
|
return instance;
|
|
54
44
|
}
|
|
55
|
-
__name(
|
|
45
|
+
__name(buildNestedModule, "buildNestedModule");
|
|
56
46
|
function getParamtypes(Module, key) {
|
|
57
47
|
return Reflect.getMetadata("design:paramtypes", Module, key);
|
|
58
48
|
}
|
|
59
49
|
__name(getParamtypes, "getParamtypes");
|
|
50
|
+
function useM(model) {
|
|
51
|
+
return moduleMap.get(getTag(model));
|
|
52
|
+
}
|
|
53
|
+
__name(useM, "useM");
|
|
54
|
+
if (__DEV__) {
|
|
55
|
+
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
56
|
+
target = Object.values(target)[0];
|
|
57
|
+
const tag = getTag(target);
|
|
58
|
+
const module = moduleMap.get(tag);
|
|
59
|
+
module.destroy?.();
|
|
60
|
+
moduleMap.delete(tag);
|
|
61
|
+
buildNestedModule(target);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
60
64
|
|
|
61
65
|
// src/index.ts
|
|
62
66
|
export * from "phecda-core";
|
|
63
67
|
export {
|
|
64
68
|
Factory,
|
|
65
|
-
|
|
69
|
+
useM
|
|
66
70
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-module",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "provide DI and HMR for modules by reflect-metadata and vite",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"reflect-metadata": "^0.1.13",
|
|
36
|
-
"phecda-core": "4.
|
|
36
|
+
"phecda-core": "4.5.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.1.0"
|
package/src/core.ts
CHANGED
|
@@ -2,26 +2,14 @@ import type { Construct } from 'phecda-core'
|
|
|
2
2
|
import { getTag, invokeInit } from 'phecda-core'
|
|
3
3
|
import 'reflect-metadata'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const moduleMap = new Map<PropertyKey, InstanceType<Construct>>()
|
|
6
6
|
|
|
7
7
|
export async function Factory(Modules: (new (...args: any) => any)[]) {
|
|
8
8
|
for (const Module of Modules)
|
|
9
|
-
await
|
|
9
|
+
await buildNestedModule(Module)
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
// @ts-expect-error work for hmr
|
|
14
|
-
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
15
|
-
target = Object.values(target)[0]
|
|
16
|
-
const tag = getTag(target)
|
|
17
|
-
const module = moduleMap.get(tag)
|
|
18
|
-
module.destroy?.()
|
|
19
|
-
moduleMap.delete(tag)
|
|
20
|
-
buildNestModule(target)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function buildNestModule(Module: Construct) {
|
|
12
|
+
async function buildNestedModule(Module: Construct) {
|
|
25
13
|
const paramtypes = getParamtypes(Module) as Construct[]
|
|
26
14
|
|
|
27
15
|
let instance: InstanceType<Construct>
|
|
@@ -38,7 +26,7 @@ async function buildNestModule(Module: Construct) {
|
|
|
38
26
|
if (paramtypes) {
|
|
39
27
|
const paramtypesInstances = [] as any[]
|
|
40
28
|
for (const i in paramtypes)
|
|
41
|
-
paramtypesInstances[i] = await
|
|
29
|
+
paramtypesInstances[i] = await buildNestedModule(paramtypes[i])
|
|
42
30
|
|
|
43
31
|
instance = new Module(...paramtypesInstances)
|
|
44
32
|
}
|
|
@@ -66,3 +54,19 @@ async function buildNestModule(Module: Construct) {
|
|
|
66
54
|
function getParamtypes(Module: any, key?: string | symbol) {
|
|
67
55
|
return Reflect.getMetadata('design:paramtypes', Module, key!)
|
|
68
56
|
}
|
|
57
|
+
|
|
58
|
+
export function useM<Model extends Construct>(model: Model): InstanceType<Model> {
|
|
59
|
+
return moduleMap.get(getTag(model))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (__DEV__) {
|
|
63
|
+
// @ts-expect-error work for hmr
|
|
64
|
+
window.__PHECDA_MODULE_UPDATE__ = (target) => {
|
|
65
|
+
target = Object.values(target)[0]
|
|
66
|
+
const tag = getTag(target)
|
|
67
|
+
const module = moduleMap.get(tag)
|
|
68
|
+
module.destroy?.()
|
|
69
|
+
moduleMap.delete(tag)
|
|
70
|
+
buildNestedModule(target)
|
|
71
|
+
}
|
|
72
|
+
}
|