@eggjs/tegg-plugin 4.0.2-beta.1 → 4.0.2-beta.11
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/dist/app.d.ts +1 -0
- package/dist/app.js +7 -0
- package/dist/lib/EggModuleLoader.d.ts +18 -1
- package/dist/lib/EggModuleLoader.js +52 -4
- package/package.json +19 -18
package/dist/app.d.ts
CHANGED
package/dist/app.js
CHANGED
|
@@ -3,12 +3,14 @@ import "./lib/AppLoadUnitInstance.js";
|
|
|
3
3
|
import "./lib/EggCompatibleObject.js";
|
|
4
4
|
import { CompatibleUtil } from "./lib/CompatibleUtil.js";
|
|
5
5
|
import { ConfigSourceLoadUnitHook } from "./lib/ConfigSourceLoadUnitHook.js";
|
|
6
|
+
import { EggModuleLoader } from "./lib/EggModuleLoader.js";
|
|
6
7
|
import { ModuleHandler } from "./lib/ModuleHandler.js";
|
|
7
8
|
import { EggContextCompatibleHook } from "./lib/EggContextCompatibleHook.js";
|
|
8
9
|
import { EggContextHandler } from "./lib/EggContextHandler.js";
|
|
9
10
|
import { EggQualifierProtoHook } from "./lib/EggQualifierProtoHook.js";
|
|
10
11
|
import { hijackRunInBackground } from "./lib/run_in_background.js";
|
|
11
12
|
import { LoadUnitMultiInstanceProtoHook } from "@eggjs/metadata";
|
|
13
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
12
14
|
|
|
13
15
|
//#region src/app.ts
|
|
14
16
|
var TeggAppBoot = class {
|
|
@@ -42,6 +44,11 @@ var TeggAppBoot = class {
|
|
|
42
44
|
this.compatibleHook = new EggContextCompatibleHook(this.app.moduleHandler);
|
|
43
45
|
this.app.eggContextLifecycleUtil.registerLifecycle(this.compatibleHook);
|
|
44
46
|
}
|
|
47
|
+
async loadMetadata() {
|
|
48
|
+
if (!this.app.moduleReferences) return;
|
|
49
|
+
const moduleDescriptors = await LoaderFactory.loadApp(this.app.moduleReferences);
|
|
50
|
+
EggModuleLoader.collectTeggManifest(this.app, moduleDescriptors);
|
|
51
|
+
}
|
|
45
52
|
async beforeClose() {
|
|
46
53
|
CompatibleUtil.clean();
|
|
47
54
|
await this.app.moduleHandler.destroy();
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { GlobalGraph, GlobalGraphBuildHook } from "@eggjs/metadata";
|
|
1
|
+
import { GlobalGraph, GlobalGraphBuildHook, ModuleDescriptor } from "@eggjs/metadata";
|
|
2
|
+
import { TeggManifestExtension } from "@eggjs/tegg-loader";
|
|
3
|
+
import { ModuleReference } from "@eggjs/tegg-types";
|
|
2
4
|
import { Application } from "egg";
|
|
3
5
|
|
|
4
6
|
//#region src/lib/EggModuleLoader.d.ts
|
|
@@ -6,10 +8,25 @@ declare class EggModuleLoader {
|
|
|
6
8
|
app: Application;
|
|
7
9
|
globalGraph: GlobalGraph;
|
|
8
10
|
private pendingBuildHooks;
|
|
11
|
+
/**
|
|
12
|
+
* True when the app graph was built from a tegg manifest (bundle mode). In
|
|
13
|
+
* that case the module source files do not exist on disk, so module load
|
|
14
|
+
* units must reuse the manifest's precomputed decorated files instead of
|
|
15
|
+
* globbing the file system.
|
|
16
|
+
*/
|
|
17
|
+
private loadedFromManifest;
|
|
9
18
|
constructor(app: Application);
|
|
10
19
|
registerBuildHook(hook: GlobalGraphBuildHook): void;
|
|
11
20
|
private loadApp;
|
|
12
21
|
private buildAppGraph;
|
|
22
|
+
/**
|
|
23
|
+
* Build tegg manifest data from module references and descriptors.
|
|
24
|
+
*/
|
|
25
|
+
static buildTeggManifestData(moduleReferences: readonly ModuleReference[], moduleDescriptors: readonly ModuleDescriptor[]): TeggManifestExtension;
|
|
26
|
+
/**
|
|
27
|
+
* Collect tegg manifest data and store in manifest extensions.
|
|
28
|
+
*/
|
|
29
|
+
static collectTeggManifest(app: Application, moduleDescriptors: readonly ModuleDescriptor[]): void;
|
|
13
30
|
private loadModule;
|
|
14
31
|
load(): Promise<void>;
|
|
15
32
|
}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { EggAppLoader } from "./EggAppLoader.js";
|
|
2
2
|
import { EggLoadUnitType, GlobalGraph, LoadUnitFactory, ModuleDescriptorDumper } from "@eggjs/metadata";
|
|
3
|
-
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
3
|
+
import { LoaderFactory, ModuleLoader, TEGG_MANIFEST_KEY } from "@eggjs/tegg-loader";
|
|
4
4
|
|
|
5
5
|
//#region src/lib/EggModuleLoader.ts
|
|
6
|
-
var EggModuleLoader = class {
|
|
6
|
+
var EggModuleLoader = class EggModuleLoader {
|
|
7
7
|
app;
|
|
8
8
|
globalGraph;
|
|
9
9
|
pendingBuildHooks = [];
|
|
10
|
+
/**
|
|
11
|
+
* True when the app graph was built from a tegg manifest (bundle mode). In
|
|
12
|
+
* that case the module source files do not exist on disk, so module load
|
|
13
|
+
* units must reuse the manifest's precomputed decorated files instead of
|
|
14
|
+
* globbing the file system.
|
|
15
|
+
*/
|
|
16
|
+
loadedFromManifest = false;
|
|
10
17
|
constructor(app) {
|
|
11
18
|
this.app = app;
|
|
12
19
|
}
|
|
@@ -24,20 +31,61 @@ var EggModuleLoader = class {
|
|
|
24
31
|
const modulePlugin = this.app.moduleReferences.find((t) => t.path === plugin.path);
|
|
25
32
|
if (modulePlugin) modulePlugin.optional = false;
|
|
26
33
|
}
|
|
27
|
-
const
|
|
34
|
+
const manifestTegg = this.app.loader.manifest.getExtension(TEGG_MANIFEST_KEY);
|
|
35
|
+
const loadAppManifest = manifestTegg?.moduleDescriptors?.length ? manifestTegg : void 0;
|
|
36
|
+
this.loadedFromManifest = !!loadAppManifest;
|
|
37
|
+
const loaderFS = this.app.loader.loaderFS;
|
|
38
|
+
const moduleDescriptors = await LoaderFactory.loadApp(this.app.moduleReferences, loadAppManifest, loaderFS);
|
|
39
|
+
if (!loadAppManifest) EggModuleLoader.collectTeggManifest(this.app, moduleDescriptors);
|
|
28
40
|
for (const moduleDescriptor of moduleDescriptors) ModuleDescriptorDumper.dump(moduleDescriptor, { dumpDir: this.app.baseDir }).catch((e) => {
|
|
29
41
|
e.message = "dump module descriptor failed: " + e.message;
|
|
30
42
|
this.app.logger.warn(e);
|
|
31
43
|
});
|
|
32
44
|
return await GlobalGraph.create(moduleDescriptors);
|
|
33
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Build tegg manifest data from module references and descriptors.
|
|
48
|
+
*/
|
|
49
|
+
static buildTeggManifestData(moduleReferences, moduleDescriptors) {
|
|
50
|
+
return {
|
|
51
|
+
moduleReferences: moduleReferences.map((ref) => ({
|
|
52
|
+
name: ref.name,
|
|
53
|
+
path: ref.path,
|
|
54
|
+
optional: ref.optional,
|
|
55
|
+
loaderType: ref.loaderType
|
|
56
|
+
})),
|
|
57
|
+
moduleDescriptors: moduleDescriptors.map((desc) => ({
|
|
58
|
+
name: desc.name,
|
|
59
|
+
unitPath: desc.unitPath,
|
|
60
|
+
optional: desc.optional,
|
|
61
|
+
decoratedFiles: ModuleDescriptorDumper.getDecoratedFiles(desc)
|
|
62
|
+
}))
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Collect tegg manifest data and store in manifest extensions.
|
|
67
|
+
*/
|
|
68
|
+
static collectTeggManifest(app, moduleDescriptors) {
|
|
69
|
+
const data = EggModuleLoader.buildTeggManifestData(app.moduleReferences, moduleDescriptors);
|
|
70
|
+
app.loader.manifest.setExtension(TEGG_MANIFEST_KEY, data);
|
|
71
|
+
}
|
|
34
72
|
async loadModule() {
|
|
35
73
|
this.globalGraph.build();
|
|
36
74
|
this.globalGraph.sort();
|
|
37
75
|
const moduleConfigList = this.globalGraph.moduleConfigList;
|
|
76
|
+
const loaderFS = this.app.loader.loaderFS;
|
|
77
|
+
const decoratedFilesMap = /* @__PURE__ */ new Map();
|
|
78
|
+
if (this.loadedFromManifest) {
|
|
79
|
+
const manifestTegg = this.app.loader.manifest.getExtension(TEGG_MANIFEST_KEY);
|
|
80
|
+
for (const desc of manifestTegg?.moduleDescriptors ?? []) decoratedFilesMap.set(desc.unitPath, desc.decoratedFiles);
|
|
81
|
+
}
|
|
38
82
|
for (const moduleConfig of moduleConfigList) {
|
|
39
83
|
const modulePath = moduleConfig.path;
|
|
40
|
-
const
|
|
84
|
+
const precomputedFiles = decoratedFilesMap.get(modulePath);
|
|
85
|
+
const loader = precomputedFiles ? new ModuleLoader(modulePath, {
|
|
86
|
+
precomputedFiles,
|
|
87
|
+
loaderFS
|
|
88
|
+
}) : LoaderFactory.createLoader(modulePath, EggLoadUnitType.MODULE, loaderFS);
|
|
41
89
|
const loadUnit = await LoadUnitFactory.createLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
|
|
42
90
|
this.app.moduleHandler.loadUnits.push(loadUnit);
|
|
43
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-plugin",
|
|
3
|
-
"version": "4.0.2-beta.
|
|
3
|
+
"version": "4.0.2-beta.11",
|
|
4
4
|
"description": "module plugin for egg",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -59,30 +59,31 @@
|
|
|
59
59
|
"await-first": "^1.0.0",
|
|
60
60
|
"extend2": "^4.0.0",
|
|
61
61
|
"sdk-base": "^5.0.1",
|
|
62
|
-
"@eggjs/background-task": "4.0.2-beta.
|
|
63
|
-
"@eggjs/core-decorator": "4.0.2-beta.
|
|
64
|
-
"@eggjs/dynamic-inject-runtime": "4.0.2-beta.
|
|
65
|
-
"@eggjs/
|
|
66
|
-
"@eggjs/
|
|
67
|
-
"@eggjs/
|
|
68
|
-
"@eggjs/
|
|
69
|
-
"@eggjs/tegg-
|
|
70
|
-
"@eggjs/tegg-
|
|
71
|
-
"@eggjs/tegg-
|
|
62
|
+
"@eggjs/background-task": "4.0.2-beta.11",
|
|
63
|
+
"@eggjs/core-decorator": "4.0.2-beta.11",
|
|
64
|
+
"@eggjs/dynamic-inject-runtime": "4.0.2-beta.11",
|
|
65
|
+
"@eggjs/metadata": "4.0.2-beta.11",
|
|
66
|
+
"@eggjs/lifecycle": "4.0.2-beta.11",
|
|
67
|
+
"@eggjs/module-common": "4.0.2-beta.11",
|
|
68
|
+
"@eggjs/tegg-common-util": "4.0.2-beta.11",
|
|
69
|
+
"@eggjs/tegg-types": "4.0.2-beta.11",
|
|
70
|
+
"@eggjs/tegg-runtime": "4.0.2-beta.11",
|
|
71
|
+
"@eggjs/tegg-loader": "4.0.2-beta.11"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/node": "^24.10.2",
|
|
75
75
|
"egg-logger": "^3.5.0",
|
|
76
76
|
"typescript": "^5.9.3",
|
|
77
|
-
"@eggjs/
|
|
78
|
-
"@eggjs/
|
|
79
|
-
"@eggjs/tegg": "4.0.2-beta.
|
|
80
|
-
"@eggjs/tracer": "4.0.2-beta.
|
|
81
|
-
"
|
|
77
|
+
"@eggjs/core": "7.0.2-beta.11",
|
|
78
|
+
"@eggjs/mock": "7.0.2-beta.11",
|
|
79
|
+
"@eggjs/tegg-config": "4.0.2-beta.11",
|
|
80
|
+
"@eggjs/tracer": "4.0.2-beta.11",
|
|
81
|
+
"@eggjs/tegg": "4.0.2-beta.11",
|
|
82
|
+
"egg": "4.1.2-beta.11"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"@eggjs/tegg-config": "4.0.2-beta.
|
|
85
|
-
"egg": "4.1.2-beta.
|
|
85
|
+
"@eggjs/tegg-config": "4.0.2-beta.11",
|
|
86
|
+
"egg": "4.1.2-beta.11"
|
|
86
87
|
},
|
|
87
88
|
"engines": {
|
|
88
89
|
"node": ">=22.18.0"
|