phecda-module 1.0.8 → 2.0.1
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 +8 -8
- package/CHANGELOG.md +22 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- package/src/core.ts +68 -68
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
|
|
2
|
-
> phecda-module@
|
|
2
|
+
> phecda-module@2.0.1 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
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.
|
|
7
|
+
[34mCLI[39m tsup v8.3.0
|
|
8
8
|
[34mCLI[39m Using tsup config: /home/runner/work/phecda/phecda/packages/module/tsup.config.ts
|
|
9
9
|
[34mCLI[39m Target: esnext
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[
|
|
13
|
-
[32mCJS[39m [1mdist/vite.js [22m[32m1.34 KB[39m
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in 56ms
|
|
15
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m1.87 KB[39m
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m1.86 KB[39m
|
|
16
13
|
[32mESM[39m [1mdist/vite.mjs [22m[32m519.00 B[39m
|
|
17
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 80ms
|
|
15
|
+
[32mCJS[39m [1mdist/index.js [22m[32m3.15 KB[39m
|
|
16
|
+
[32mCJS[39m [1mdist/vite.js [22m[32m1.34 KB[39m
|
|
17
|
+
[32mCJS[39m ⚡️ Build success in 81ms
|
|
18
18
|
[34mDTS[39m Build start
|
|
19
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
+
[32mDTS[39m ⚡️ Build success in 4750ms
|
|
20
20
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m191.00 B[39m
|
|
21
21
|
[32mDTS[39m [1mdist/vite.d.ts [22m[32m210.00 B[39m
|
|
22
22
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m191.00 B[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# phecda-module
|
|
2
2
|
|
|
3
|
+
## 2.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [bffb0a0]
|
|
8
|
+
- phecda-core@4.0.1
|
|
9
|
+
|
|
10
|
+
## 2.0.0
|
|
11
|
+
|
|
12
|
+
### Major Changes
|
|
13
|
+
|
|
14
|
+
- 831c910: release core v4
|
|
15
|
+
|
|
16
|
+
1. refactor how meta is set and get
|
|
17
|
+
2. refactor Phecda target structure
|
|
18
|
+
3. remove some useless decorators
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- Updated dependencies [831c910]
|
|
23
|
+
- phecda-core@4.0.0
|
|
24
|
+
|
|
3
25
|
## 1.0.8
|
|
4
26
|
|
|
5
27
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -62,7 +62,7 @@ async function buildNestModule(Module) {
|
|
|
62
62
|
} else {
|
|
63
63
|
instance = new Module();
|
|
64
64
|
}
|
|
65
|
-
await (0, import_phecda_core.
|
|
65
|
+
await (0, import_phecda_core.invokeInit)(instance);
|
|
66
66
|
moduleMap.set(tag, instance);
|
|
67
67
|
if (__DEV__) {
|
|
68
68
|
const proxy = new Proxy({}, {
|
package/dist/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
3
|
|
|
4
4
|
// src/core.ts
|
|
5
|
-
import { getTag,
|
|
5
|
+
import { getTag, invokeInit } from "phecda-core";
|
|
6
6
|
import "reflect-metadata";
|
|
7
7
|
var moduleMap = /* @__PURE__ */ new Map();
|
|
8
8
|
async function Factory(Modules) {
|
|
@@ -36,7 +36,7 @@ async function buildNestModule(Module) {
|
|
|
36
36
|
} else {
|
|
37
37
|
instance = new Module();
|
|
38
38
|
}
|
|
39
|
-
await
|
|
39
|
+
await invokeInit(instance);
|
|
40
40
|
moduleMap.set(tag, instance);
|
|
41
41
|
if (__DEV__) {
|
|
42
42
|
const proxy = new Proxy({}, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-module",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
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": "
|
|
36
|
+
"phecda-core": "4.0.1"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"tsup": "^8.1.0"
|
package/src/core.ts
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
import type { Construct } from 'phecda-core'
|
|
2
|
-
import { getTag,
|
|
3
|
-
import 'reflect-metadata'
|
|
4
|
-
|
|
5
|
-
export const moduleMap = new Map<PropertyKey, InstanceType<Construct>>()
|
|
6
|
-
|
|
7
|
-
export async function Factory(Modules: (new (...args: any) => any)[]) {
|
|
8
|
-
for (const Module of Modules)
|
|
9
|
-
await buildNestModule(Module)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (__DEV__) {
|
|
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) {
|
|
25
|
-
const paramtypes = getParamtypes(Module) as Construct[]
|
|
26
|
-
|
|
27
|
-
let instance: InstanceType<Construct>
|
|
28
|
-
const tag = getTag(Module)
|
|
29
|
-
|
|
30
|
-
if (moduleMap.has(tag)) {
|
|
31
|
-
instance = moduleMap.get(tag)
|
|
32
|
-
if (!instance)
|
|
33
|
-
throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Module}`)
|
|
34
|
-
|
|
35
|
-
return instance
|
|
36
|
-
}
|
|
37
|
-
moduleMap.set(tag, undefined)
|
|
38
|
-
if (paramtypes) {
|
|
39
|
-
const paramtypesInstances = [] as any[]
|
|
40
|
-
for (const i in paramtypes)
|
|
41
|
-
paramtypesInstances[i] = await buildNestModule(paramtypes[i])
|
|
42
|
-
|
|
43
|
-
instance = new Module(...paramtypesInstances)
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
instance = new Module()
|
|
47
|
-
}
|
|
48
|
-
await
|
|
49
|
-
moduleMap.set(tag, instance)
|
|
50
|
-
if (__DEV__) {
|
|
51
|
-
const proxy = new Proxy({}, {
|
|
52
|
-
get(_target, p) {
|
|
53
|
-
return moduleMap.get(tag)[p]
|
|
54
|
-
},
|
|
55
|
-
set(_target, p, value) {
|
|
56
|
-
moduleMap.get(tag)[p] = value
|
|
57
|
-
return true
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
return proxy
|
|
62
|
-
}
|
|
63
|
-
return instance
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function getParamtypes(Module: any, key?: string | symbol) {
|
|
67
|
-
return Reflect.getMetadata('design:paramtypes', Module, key!)
|
|
68
|
-
}
|
|
1
|
+
import type { Construct } from 'phecda-core'
|
|
2
|
+
import { getTag, invokeInit } from 'phecda-core'
|
|
3
|
+
import 'reflect-metadata'
|
|
4
|
+
|
|
5
|
+
export const moduleMap = new Map<PropertyKey, InstanceType<Construct>>()
|
|
6
|
+
|
|
7
|
+
export async function Factory(Modules: (new (...args: any) => any)[]) {
|
|
8
|
+
for (const Module of Modules)
|
|
9
|
+
await buildNestModule(Module)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (__DEV__) {
|
|
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) {
|
|
25
|
+
const paramtypes = getParamtypes(Module) as Construct[]
|
|
26
|
+
|
|
27
|
+
let instance: InstanceType<Construct>
|
|
28
|
+
const tag = getTag(Module)
|
|
29
|
+
|
|
30
|
+
if (moduleMap.has(tag)) {
|
|
31
|
+
instance = moduleMap.get(tag)
|
|
32
|
+
if (!instance)
|
|
33
|
+
throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Module}`)
|
|
34
|
+
|
|
35
|
+
return instance
|
|
36
|
+
}
|
|
37
|
+
moduleMap.set(tag, undefined)
|
|
38
|
+
if (paramtypes) {
|
|
39
|
+
const paramtypesInstances = [] as any[]
|
|
40
|
+
for (const i in paramtypes)
|
|
41
|
+
paramtypesInstances[i] = await buildNestModule(paramtypes[i])
|
|
42
|
+
|
|
43
|
+
instance = new Module(...paramtypesInstances)
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
instance = new Module()
|
|
47
|
+
}
|
|
48
|
+
await invokeInit(instance)
|
|
49
|
+
moduleMap.set(tag, instance)
|
|
50
|
+
if (__DEV__) {
|
|
51
|
+
const proxy = new Proxy({}, {
|
|
52
|
+
get(_target, p) {
|
|
53
|
+
return moduleMap.get(tag)[p]
|
|
54
|
+
},
|
|
55
|
+
set(_target, p, value) {
|
|
56
|
+
moduleMap.get(tag)[p] = value
|
|
57
|
+
return true
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
return proxy
|
|
62
|
+
}
|
|
63
|
+
return instance
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getParamtypes(Module: any, key?: string | symbol) {
|
|
67
|
+
return Reflect.getMetadata('design:paramtypes', Module, key!)
|
|
68
|
+
}
|