@eggjs/core 7.0.2-beta.7 → 7.0.2-beta.9
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/egg.d.ts +8 -0
- package/dist/egg.js +2 -1
- package/dist/lifecycle.d.ts +9 -0
- package/dist/lifecycle.js +6 -1
- package/dist/loader/manifest.d.ts +14 -0
- package/dist/loader/manifest.js +41 -0
- package/package.json +9 -9
package/dist/egg.d.ts
CHANGED
|
@@ -20,6 +20,14 @@ interface EggCoreOptions {
|
|
|
20
20
|
env?: string;
|
|
21
21
|
/** Skip lifecycle hooks, only trigger loadMetadata for manifest generation */
|
|
22
22
|
metadataOnly?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* When true, lifecycle stops after the `configWillLoad` phase.
|
|
25
|
+
* `configDidLoad`, `didLoad`, `willReady`, `didReady`, and `serverDidReady`
|
|
26
|
+
* are skipped. Used for V8 startup snapshot construction — SDKs typically
|
|
27
|
+
* execute during `configDidLoad`, opening connections and starting timers
|
|
28
|
+
* which are not serializable. Analogous to `metadataOnly` mode.
|
|
29
|
+
*/
|
|
30
|
+
snapshot?: boolean;
|
|
23
31
|
}
|
|
24
32
|
type EggCoreInitOptions = Partial<EggCoreOptions>;
|
|
25
33
|
declare class Request$1 extends KoaRequest {
|
package/dist/egg.js
CHANGED
|
@@ -107,7 +107,8 @@ var EggCore = class EggCore extends KoaApplication {
|
|
|
107
107
|
this.lifecycle = new Lifecycle({
|
|
108
108
|
baseDir: options.baseDir,
|
|
109
109
|
app: this,
|
|
110
|
-
logger: this.console
|
|
110
|
+
logger: this.console,
|
|
111
|
+
snapshot: options.snapshot
|
|
111
112
|
});
|
|
112
113
|
this.lifecycle.on("error", (err) => this.emit("error", err));
|
|
113
114
|
this.lifecycle.on("ready_timeout", (id) => this.emit("ready_timeout", id));
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -52,6 +52,15 @@ interface LifecycleOptions {
|
|
|
52
52
|
baseDir: string;
|
|
53
53
|
app: EggCore;
|
|
54
54
|
logger: EggConsoleLogger;
|
|
55
|
+
/**
|
|
56
|
+
* When true, the lifecycle stops after configWillLoad phase completes.
|
|
57
|
+
* configDidLoad, didLoad, willReady, didReady, and serverDidReady hooks
|
|
58
|
+
* are NOT called. Used for V8 startup snapshot construction — SDKs
|
|
59
|
+
* typically execute during configDidLoad, opening connections and starting
|
|
60
|
+
* timers which are not serializable. The handling is analogous to
|
|
61
|
+
* metadataOnly mode: both short-circuit the lifecycle chain early.
|
|
62
|
+
*/
|
|
63
|
+
snapshot?: boolean;
|
|
55
64
|
}
|
|
56
65
|
type FunWithFullPath = Fun & {
|
|
57
66
|
fullPath?: string;
|
package/dist/lifecycle.js
CHANGED
|
@@ -43,7 +43,7 @@ var Lifecycle = class extends EventEmitter {
|
|
|
43
43
|
this.logger.warn("[egg/core/lifecycle:ready_timeout] %s seconds later %s was still unable to finish.", this.readyTimeout / 1e3, id);
|
|
44
44
|
});
|
|
45
45
|
this.ready((err) => {
|
|
46
|
-
if (!this.#metadataOnly) this.triggerDidReady(err);
|
|
46
|
+
if (!this.#metadataOnly && !this.options.snapshot) this.triggerDidReady(err);
|
|
47
47
|
debug("app ready");
|
|
48
48
|
this.timing.end(`${this.options.app.type} Start`);
|
|
49
49
|
});
|
|
@@ -147,6 +147,11 @@ var Lifecycle = class extends EventEmitter {
|
|
|
147
147
|
boot.configWillLoad();
|
|
148
148
|
}
|
|
149
149
|
debug("trigger configWillLoad end");
|
|
150
|
+
if (this.options.snapshot) {
|
|
151
|
+
debug("snapshot mode: stopping after configWillLoad, skipping configDidLoad and later phases");
|
|
152
|
+
this.ready(true);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
150
155
|
this.triggerConfigDidLoad();
|
|
151
156
|
}
|
|
152
157
|
triggerConfigDidLoad() {
|
|
@@ -54,6 +54,20 @@ declare class ManifestStore {
|
|
|
54
54
|
generateManifest(options: ManifestGenerateOptions): StartupManifest;
|
|
55
55
|
static write(baseDir: string, manifest: StartupManifest): Promise<void>;
|
|
56
56
|
static clean(baseDir: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Enable Node.js module compile cache for the current process.
|
|
59
|
+
* Sets NODE_COMPILE_CACHE and NODE_COMPILE_CACHE_PORTABLE env vars
|
|
60
|
+
* so forked child processes also inherit compile cache.
|
|
61
|
+
*/
|
|
62
|
+
static enableCompileCache(baseDir: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Flush accumulated compile cache entries to disk.
|
|
65
|
+
*/
|
|
66
|
+
static flushCompileCache(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Remove the compile cache directory.
|
|
69
|
+
*/
|
|
70
|
+
static cleanCompileCache(baseDir: string): void;
|
|
57
71
|
}
|
|
58
72
|
interface ManifestGenerateOptions {
|
|
59
73
|
serverEnv: string;
|
package/dist/loader/manifest.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BuiltinModule from "node:module";
|
|
1
2
|
import fs from "node:fs";
|
|
2
3
|
import fsp from "node:fs/promises";
|
|
3
4
|
import path from "node:path";
|
|
@@ -182,6 +183,46 @@ var ManifestStore = class ManifestStore {
|
|
|
182
183
|
} catch (err) {
|
|
183
184
|
if (err.code !== "ENOENT") throw err;
|
|
184
185
|
}
|
|
186
|
+
ManifestStore.cleanCompileCache(baseDir);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Enable Node.js module compile cache for the current process.
|
|
190
|
+
* Sets NODE_COMPILE_CACHE and NODE_COMPILE_CACHE_PORTABLE env vars
|
|
191
|
+
* so forked child processes also inherit compile cache.
|
|
192
|
+
*/
|
|
193
|
+
static enableCompileCache(baseDir) {
|
|
194
|
+
if (process.env.NODE_COMPILE_CACHE || process.env.NODE_DISABLE_COMPILE_CACHE) return;
|
|
195
|
+
const cacheDir = path.join(baseDir, ".egg", "compile-cache");
|
|
196
|
+
process.env.NODE_COMPILE_CACHE = cacheDir;
|
|
197
|
+
process.env.NODE_COMPILE_CACHE_PORTABLE = "1";
|
|
198
|
+
try {
|
|
199
|
+
const result = BuiltinModule.enableCompileCache?.(cacheDir);
|
|
200
|
+
debug("compile cache enabled: %o", result);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
debug("compile cache enable failed: %o", err);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Flush accumulated compile cache entries to disk.
|
|
207
|
+
*/
|
|
208
|
+
static flushCompileCache() {
|
|
209
|
+
try {
|
|
210
|
+
BuiltinModule.flushCompileCache?.();
|
|
211
|
+
debug("compile cache flushed");
|
|
212
|
+
} catch (err) {
|
|
213
|
+
debug("compile cache flush failed: %o", err);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Remove the compile cache directory.
|
|
218
|
+
*/
|
|
219
|
+
static cleanCompileCache(baseDir) {
|
|
220
|
+
const compileCacheDir = path.join(baseDir, ".egg", "compile-cache");
|
|
221
|
+
fs.rmSync(compileCacheDir, {
|
|
222
|
+
recursive: true,
|
|
223
|
+
force: true
|
|
224
|
+
});
|
|
225
|
+
debug("compile cache removed: %s", compileCacheDir);
|
|
185
226
|
}
|
|
186
227
|
#toRelative(absPath) {
|
|
187
228
|
return (path.isAbsolute(absPath) ? path.relative(this.baseDir, absPath) : absPath).replaceAll(path.sep, "/");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/core",
|
|
3
|
-
"version": "7.0.2-beta.
|
|
3
|
+
"version": "7.0.2-beta.9",
|
|
4
4
|
"description": "A core plugin framework based on @eggjs/koa",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"ready-callback": "^4.0.0",
|
|
42
42
|
"tsconfig-paths": "^4.2.0",
|
|
43
43
|
"utility": "^2.5.0",
|
|
44
|
-
"@eggjs/extend2": "5.0.2-beta.
|
|
45
|
-
"@eggjs/
|
|
46
|
-
"@eggjs/
|
|
47
|
-
"@eggjs/
|
|
48
|
-
"@eggjs/utils": "5.0.2-beta.
|
|
44
|
+
"@eggjs/extend2": "5.0.2-beta.9",
|
|
45
|
+
"@eggjs/path-matching": "3.0.2-beta.9",
|
|
46
|
+
"@eggjs/router": "4.0.2-beta.9",
|
|
47
|
+
"@eggjs/koa": "3.1.2-beta.9",
|
|
48
|
+
"@eggjs/utils": "5.0.2-beta.9"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
"mm": "^4.0.2",
|
|
58
58
|
"typescript": "^5.9.3",
|
|
59
59
|
"urllib": "^4.8.2",
|
|
60
|
-
"@eggjs/mock": "7.0.2-beta.
|
|
61
|
-
"@eggjs/tsconfig": "3.1.2-beta.
|
|
62
|
-
"@eggjs/supertest": "9.0.2-beta.
|
|
60
|
+
"@eggjs/mock": "7.0.2-beta.9",
|
|
61
|
+
"@eggjs/tsconfig": "3.1.2-beta.9",
|
|
62
|
+
"@eggjs/supertest": "9.0.2-beta.9"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=22.18.0"
|