phecda-module 2.0.4 → 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.
@@ -1,5 +1,5 @@
1
1
 
2
- > phecda-module@2.0.4 build /home/runner/work/phecda/phecda/packages/module
2
+ > phecda-module@2.1.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,15 +9,15 @@
9
9
  CLI Target: esnext
10
10
  CJS Build start
11
11
  ESM Build start
12
- CJS dist/index.js 3.15 KB
13
12
  CJS dist/vite.js 1.34 KB
14
- CJS ⚡️ Build success in 146ms
15
- ESM dist/index.mjs 1.86 KB
13
+ CJS dist/index.js 3.26 KB
14
+ CJS ⚡️ Build success in 85ms
15
+ ESM dist/index.mjs 1.95 KB
16
16
  ESM dist/vite.mjs 519.00 B
17
- ESM ⚡️ Build success in 147ms
17
+ ESM ⚡️ Build success in 87ms
18
18
  DTS Build start
19
- DTS ⚡️ Build success in 5331ms
20
- DTS dist/index.d.ts 191.00 B
19
+ DTS ⚡️ Build success in 5892ms
20
+ DTS dist/index.d.ts 262.00 B
21
21
  DTS dist/vite.d.ts 210.00 B
22
- DTS dist/index.d.mts 191.00 B
22
+ DTS dist/index.d.mts 262.00 B
23
23
  DTS dist/vite.d.mts 210.00 B
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # phecda-module
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 54449a9: add useM
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [6e44723]
12
+ - phecda-core@4.5.0
13
+
14
+ ## 2.0.5
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [3f674bc]
19
+ - phecda-core@4.4.0
20
+
3
21
  ## 2.0.4
4
22
 
5
23
  ### Patch Changes
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, moduleMap };
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, moduleMap };
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
- moduleMap: () => moduleMap
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 buildNestModule(Module);
35
+ for (const Module of Modules) await buildNestedModule(Module);
36
36
  }
37
37
  __name(Factory, "Factory");
38
- if (__DEV__) {
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 buildNestModule(paramtypes[i]);
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(buildNestModule, "buildNestModule");
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
- moduleMap,
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 buildNestModule(Module);
9
+ for (const Module of Modules) await buildNestedModule(Module);
10
10
  }
11
11
  __name(Factory, "Factory");
12
- if (__DEV__) {
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 buildNestModule(paramtypes[i]);
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(buildNestModule, "buildNestModule");
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
- moduleMap
69
+ useM
66
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-module",
3
- "version": "2.0.4",
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.3.0"
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
- export const moduleMap = new Map<PropertyKey, InstanceType<Construct>>()
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 buildNestModule(Module)
9
+ await buildNestedModule(Module)
10
10
  }
11
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) {
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 buildNestModule(paramtypes[i])
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
+ }