@eggjs/tegg-loader 4.0.2-beta.6 → 4.0.2-beta.7

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.
@@ -3,11 +3,33 @@ import { ModuleDescriptor } from "@eggjs/metadata";
3
3
 
4
4
  //#region src/LoaderFactory.d.ts
5
5
  type LoaderCreator = (unitPath: string) => Loader;
6
+ interface ManifestModuleReference {
7
+ name: string;
8
+ path: string;
9
+ optional?: boolean;
10
+ loaderType?: string;
11
+ }
12
+ interface ManifestModuleDescriptor {
13
+ name: string;
14
+ unitPath: string;
15
+ optional?: boolean;
16
+ /** Files containing decorated classes, relative to unitPath */
17
+ decoratedFiles: string[];
18
+ }
19
+ /** Shape of the 'tegg' manifest extension stored via ManifestStore.setExtension() */
20
+ interface TeggManifestExtension {
21
+ moduleReferences: ManifestModuleReference[];
22
+ moduleDescriptors: ManifestModuleDescriptor[];
23
+ }
24
+ declare const TEGG_MANIFEST_KEY = "tegg";
25
+ interface LoadAppManifest {
26
+ moduleDescriptors: ManifestModuleDescriptor[];
27
+ }
6
28
  declare class LoaderFactory {
7
29
  private static loaderCreatorMap;
8
30
  static createLoader(unitPath: string, type: EggLoadUnitTypeLike): Loader;
9
31
  static registerLoader(type: EggLoadUnitTypeLike, creator: LoaderCreator): void;
10
- static loadApp(moduleReferences: readonly ModuleReference[]): Promise<ModuleDescriptor[]>;
32
+ static loadApp(moduleReferences: readonly ModuleReference[], manifest?: LoadAppManifest): Promise<ModuleDescriptor[]>;
11
33
  }
12
34
  //#endregion
13
- export { LoaderCreator, LoaderFactory };
35
+ export { LoadAppManifest, LoaderCreator, LoaderFactory, ManifestModuleDescriptor, ManifestModuleReference, TEGG_MANIFEST_KEY, TeggManifestExtension };
@@ -2,6 +2,7 @@ import { PrototypeUtil } from "@eggjs/core-decorator";
2
2
  import { EggLoadUnitType } from "@eggjs/tegg-types";
3
3
 
4
4
  //#region src/LoaderFactory.ts
5
+ const TEGG_MANIFEST_KEY = "tegg";
5
6
  var LoaderFactory = class LoaderFactory {
6
7
  static loaderCreatorMap = /* @__PURE__ */ new Map();
7
8
  static createLoader(unitPath, type) {
@@ -12,11 +13,19 @@ var LoaderFactory = class LoaderFactory {
12
13
  static registerLoader(type, creator) {
13
14
  this.loaderCreatorMap.set(type, creator);
14
15
  }
15
- static async loadApp(moduleReferences) {
16
+ static async loadApp(moduleReferences, manifest) {
16
17
  const result = [];
17
18
  const multiInstanceClazzList = [];
19
+ const manifestMap = /* @__PURE__ */ new Map();
20
+ if (manifest?.moduleDescriptors) for (const desc of manifest.moduleDescriptors) manifestMap.set(desc.unitPath, desc);
21
+ let ModuleLoaderClass;
22
+ if (manifestMap.size > 0) ModuleLoaderClass = (await import("./impl/ModuleLoader.js")).ModuleLoader;
18
23
  for (const moduleReference of moduleReferences) {
19
- const loader = LoaderFactory.createLoader(moduleReference.path, moduleReference.loaderType || EggLoadUnitType.MODULE);
24
+ const manifestDesc = manifestMap.get(moduleReference.path);
25
+ const loaderType = moduleReference.loaderType || EggLoadUnitType.MODULE;
26
+ let loader;
27
+ if (manifestDesc && ModuleLoaderClass && loaderType === EggLoadUnitType.MODULE) loader = new ModuleLoaderClass(moduleReference.path, manifestDesc.decoratedFiles);
28
+ else loader = LoaderFactory.createLoader(moduleReference.path, loaderType);
20
29
  const res = {
21
30
  name: moduleReference.name,
22
31
  unitPath: moduleReference.path,
@@ -35,4 +44,4 @@ var LoaderFactory = class LoaderFactory {
35
44
  };
36
45
 
37
46
  //#endregion
38
- export { LoaderFactory };
47
+ export { LoaderFactory, TEGG_MANIFEST_KEY };
@@ -4,7 +4,9 @@ import { EggProtoImplClass, Loader } from "@eggjs/tegg-types";
4
4
  declare class ModuleLoader implements Loader {
5
5
  private readonly moduleDir;
6
6
  private protoClazzList;
7
- constructor(moduleDir: string);
7
+ /** Pre-computed file list from manifest (only decorated files) */
8
+ private readonly precomputedFiles?;
9
+ constructor(moduleDir: string, precomputedFiles?: string[]);
8
10
  load(): Promise<EggProtoImplClass[]>;
9
11
  static createModuleLoader(path: string): ModuleLoader;
10
12
  }
@@ -9,15 +9,24 @@ const debug = debuglog("egg/tegg/loader/impl/ModuleLoader");
9
9
  var ModuleLoader = class ModuleLoader {
10
10
  moduleDir;
11
11
  protoClazzList;
12
- constructor(moduleDir) {
12
+ /** Pre-computed file list from manifest (only decorated files) */
13
+ precomputedFiles;
14
+ constructor(moduleDir, precomputedFiles) {
13
15
  this.moduleDir = moduleDir;
16
+ this.precomputedFiles = precomputedFiles;
14
17
  }
15
18
  async load() {
16
19
  if (this.protoClazzList) return this.protoClazzList;
17
20
  const protoClassList = [];
18
- const filePattern = LoaderUtil.filePattern();
19
- const files = await globby(filePattern, { cwd: this.moduleDir });
20
- debug("load files: %o, filePattern: %o, moduleDir: %o", files, filePattern, this.moduleDir);
21
+ let files;
22
+ if (this.precomputedFiles) {
23
+ files = this.precomputedFiles;
24
+ debug("load from manifest, files: %o, moduleDir: %o", files, this.moduleDir);
25
+ } else {
26
+ const filePattern = LoaderUtil.filePattern();
27
+ files = await globby(filePattern, { cwd: this.moduleDir });
28
+ debug("load files: %o, filePattern: %o, moduleDir: %o", files, filePattern, this.moduleDir);
29
+ }
21
30
  for (const file of files) {
22
31
  const realPath = path.join(this.moduleDir, file);
23
32
  const fileClazzList = await LoaderUtil.loadFile(realPath);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { LoaderCreator, LoaderFactory } from "./LoaderFactory.js";
1
+ import { LoadAppManifest, LoaderCreator, LoaderFactory, ManifestModuleDescriptor, ManifestModuleReference, TEGG_MANIFEST_KEY, TeggManifestExtension } from "./LoaderFactory.js";
2
2
  import { LoaderUtil } from "./LoaderUtil.js";
3
3
  import { ModuleLoader } from "./impl/ModuleLoader.js";
4
4
  import "./impl/index.js";
5
- export { LoaderCreator, LoaderFactory, LoaderUtil, ModuleLoader };
5
+ export { LoadAppManifest, LoaderCreator, LoaderFactory, LoaderUtil, ManifestModuleDescriptor, ManifestModuleReference, ModuleLoader, TEGG_MANIFEST_KEY, TeggManifestExtension };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { LoaderFactory } from "./LoaderFactory.js";
1
+ import { LoaderFactory, TEGG_MANIFEST_KEY } from "./LoaderFactory.js";
2
2
  import { LoaderUtil } from "./LoaderUtil.js";
3
3
  import { ModuleLoader } from "./impl/ModuleLoader.js";
4
4
  import "./impl/index.js";
5
5
 
6
- export { LoaderFactory, LoaderUtil, ModuleLoader };
6
+ export { LoaderFactory, LoaderUtil, ModuleLoader, TEGG_MANIFEST_KEY };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/tegg-loader",
3
- "version": "4.0.2-beta.6",
3
+ "version": "4.0.2-beta.7",
4
4
  "description": "tegg default loader implement",
5
5
  "keywords": [
6
6
  "egg",
@@ -36,9 +36,9 @@
36
36
  "dependencies": {
37
37
  "globby": "^11.0.2",
38
38
  "is-type-of": "^2.2.0",
39
- "@eggjs/core-decorator": "4.0.2-beta.6",
40
- "@eggjs/tegg-types": "4.0.2-beta.6",
41
- "@eggjs/metadata": "4.0.2-beta.6"
39
+ "@eggjs/tegg-types": "4.0.2-beta.7",
40
+ "@eggjs/metadata": "4.0.2-beta.7",
41
+ "@eggjs/core-decorator": "4.0.2-beta.7"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^24.10.2",