phecda-module 1.0.7 → 2.0.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > phecda-module@1.0.7 build /home/runner/work/phecda/phecda/packages/module
2
+ > phecda-module@2.0.0 build /home/runner/work/phecda/phecda/packages/module
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: src/index.ts, src/vite.ts
@@ -9,14 +9,14 @@
9
9
  CLI Target: esnext
10
10
  CJS Build start
11
11
  ESM Build start
12
- ESM dist/index.mjs 1.87 KB
13
- ESM dist/vite.mjs 519.00 B
14
- ESM ⚡️ Build success in 85ms
15
- CJS dist/index.js 3.16 KB
12
+ CJS dist/index.js 3.15 KB
16
13
  CJS dist/vite.js 1.34 KB
17
- CJS ⚡️ Build success in 89ms
14
+ CJS ⚡️ Build success in 70ms
15
+ ESM dist/index.mjs 1.86 KB
16
+ ESM dist/vite.mjs 519.00 B
17
+ ESM ⚡️ Build success in 70ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 4418ms
19
+ DTS ⚡️ Build success in 4741ms
20
20
  DTS dist/index.d.ts 191.00 B
21
21
  DTS dist/vite.d.ts 210.00 B
22
22
  DTS dist/index.d.mts 191.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # phecda-module
2
2
 
3
+ ## 2.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 831c910: release core v4
8
+
9
+ 1. refactor how meta is set and get
10
+ 2. refactor Phecda target structure
11
+ 3. remove some useless decorators
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [831c910]
16
+ - phecda-core@4.0.0
17
+
18
+ ## 1.0.8
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [c126577]
23
+ - Updated dependencies [c126577]
24
+ - phecda-core@3.1.1
25
+
3
26
  ## 1.0.7
4
27
 
5
28
  ### 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.invokeHandler)("init", instance);
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, invokeHandler } from "phecda-core";
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 invokeHandler("init", instance);
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": "1.0.7",
3
+ "version": "2.0.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": "3.1.0"
36
+ "phecda-core": "4.0.0"
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, invokeHandler } 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 invokeHandler('init', 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
- }
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
+ }