Skip to content

Commit 6d481eb

Browse files
elrrrrrrrclaude
andcommitted
merge: resolve conflict with next branch
Use --legacy-peer-deps from next branch for cnpmcore E2E install. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 parents fadf12c + 36d126b commit 6d481eb

92 files changed

Lines changed: 701 additions & 81 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: cnpmcore
4848
node-version: 24
4949
command: |
50-
npm install --force
50+
npm install --legacy-peer-deps
5151
npm run typecheck
5252
npm run build
5353
npm run prepublishOnly

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eggjs/monorepo",
3-
"version": "4.1.2-beta.7",
3+
"version": "4.1.2-beta.9",
44
"private": true,
55
"description": "Eggjs framework monorepo",
66
"license": "MIT",

packages/cluster/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eggjs/cluster",
3-
"version": "4.0.2-beta.7",
3+
"version": "4.0.2-beta.9",
44
"description": "cluster manager for egg",
55
"keywords": [
66
"cluster",

packages/cluster/src/master.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'node:fs';
2+
import module from 'node:module';
23
import net from 'node:net';
34
import os from 'node:os';
45
import path from 'node:path';
@@ -57,6 +58,20 @@ export class Master extends ReadyEventEmitter {
5758

5859
async #start(options?: ClusterOptions) {
5960
this.options = await parseOptions(options);
61+
62+
// Enable compile cache — env vars propagate to forked workers automatically.
63+
// Duplicated from ManifestStore.enableCompileCache (@eggjs/core is not a dependency).
64+
if (!process.env.NODE_COMPILE_CACHE && !process.env.NODE_DISABLE_COMPILE_CACHE) {
65+
const cacheDir = path.join(this.options.baseDir, '.egg', 'compile-cache');
66+
process.env.NODE_COMPILE_CACHE = cacheDir;
67+
process.env.NODE_COMPILE_CACHE_PORTABLE = '1';
68+
try {
69+
module.enableCompileCache?.(cacheDir);
70+
} catch {
71+
/* non-fatal */
72+
}
73+
}
74+
6075
this.workerManager = new WorkerManager();
6176
this.messenger = new Messenger(this, this.workerManager);
6277
this.isProduction = isProduction(this.options);

packages/cookies/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eggjs/cookies",
3-
"version": "4.0.2-beta.7",
3+
"version": "4.0.2-beta.9",
44
"description": "cookies module for egg",
55
"homepage": "https://github.com/eggjs/egg/tree/next/packages/cookies",
66
"license": "MIT",

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eggjs/core",
3-
"version": "7.0.2-beta.7",
3+
"version": "7.0.2-beta.9",
44
"description": "A core plugin framework based on @eggjs/koa",
55
"keywords": [
66
"egg",

packages/core/src/egg.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ export interface EggCoreOptions {
3333
env?: string;
3434
/** Skip lifecycle hooks, only trigger loadMetadata for manifest generation */
3535
metadataOnly?: boolean;
36+
/**
37+
* When true, lifecycle stops after the `configWillLoad` phase.
38+
* `configDidLoad`, `didLoad`, `willReady`, `didReady`, and `serverDidReady`
39+
* are skipped. Used for V8 startup snapshot construction — SDKs typically
40+
* execute during `configDidLoad`, opening connections and starting timers
41+
* which are not serializable. Analogous to `metadataOnly` mode.
42+
*/
43+
snapshot?: boolean;
3644
}
3745

3846
export type EggCoreInitOptions = Partial<EggCoreOptions>;
@@ -191,6 +199,7 @@ export class EggCore extends KoaApplication {
191199
baseDir: options.baseDir,
192200
app: this,
193201
logger: this.console,
202+
snapshot: options.snapshot,
194203
});
195204
this.lifecycle.on('error', (err) => this.emit('error', err));
196205
this.lifecycle.on('ready_timeout', (id) => this.emit('ready_timeout', id));

packages/core/src/lifecycle.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ export interface LifecycleOptions {
6969
baseDir: string;
7070
app: EggCore;
7171
logger: EggConsoleLogger;
72+
/**
73+
* When true, the lifecycle stops after configWillLoad phase completes.
74+
* configDidLoad, didLoad, willReady, didReady, and serverDidReady hooks
75+
* are NOT called. Used for V8 startup snapshot construction — SDKs
76+
* typically execute during configDidLoad, opening connections and starting
77+
* timers which are not serializable. The handling is analogous to
78+
* metadataOnly mode: both short-circuit the lifecycle chain early.
79+
*/
80+
snapshot?: boolean;
7281
}
7382

7483
export type FunWithFullPath = Fun & { fullPath?: string };
@@ -119,7 +128,7 @@ export class Lifecycle extends EventEmitter {
119128
});
120129

121130
this.ready((err) => {
122-
if (!this.#metadataOnly) {
131+
if (!this.#metadataOnly && !this.options.snapshot) {
123132
void this.triggerDidReady(err);
124133
}
125134
debug('app ready');
@@ -251,6 +260,14 @@ export class Lifecycle extends EventEmitter {
251260
}
252261
}
253262
debug('trigger configWillLoad end');
263+
if (this.options.snapshot) {
264+
// Snapshot mode: stop AFTER configWillLoad, BEFORE configDidLoad.
265+
// SDKs typically execute during configDidLoad hooks — these open connections
266+
// and start timers which are not serializable in V8 startup snapshots.
267+
debug('snapshot mode: stopping after configWillLoad, skipping configDidLoad and later phases');
268+
this.ready(true);
269+
return;
270+
}
254271
this.triggerConfigDidLoad();
255272
}
256273

packages/core/src/loader/manifest.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createHash } from 'node:crypto';
22
import fs from 'node:fs';
33
import fsp from 'node:fs/promises';
4+
import module from 'node:module';
45
import path from 'node:path';
56
import { debuglog } from 'node:util';
67

@@ -240,6 +241,48 @@ export class ManifestStore {
240241
} catch (err: any) {
241242
if (err.code !== 'ENOENT') throw err;
242243
}
244+
ManifestStore.cleanCompileCache(baseDir);
245+
}
246+
247+
// --- Compile Cache ---
248+
249+
/**
250+
* Enable Node.js module compile cache for the current process.
251+
* Sets NODE_COMPILE_CACHE and NODE_COMPILE_CACHE_PORTABLE env vars
252+
* so forked child processes also inherit compile cache.
253+
*/
254+
static enableCompileCache(baseDir: string): void {
255+
if (process.env.NODE_COMPILE_CACHE || process.env.NODE_DISABLE_COMPILE_CACHE) return;
256+
const cacheDir = path.join(baseDir, '.egg', 'compile-cache');
257+
process.env.NODE_COMPILE_CACHE = cacheDir;
258+
process.env.NODE_COMPILE_CACHE_PORTABLE = '1';
259+
try {
260+
const result = module.enableCompileCache?.(cacheDir);
261+
debug('compile cache enabled: %o', result);
262+
} catch (err) {
263+
debug('compile cache enable failed: %o', err);
264+
}
265+
}
266+
267+
/**
268+
* Flush accumulated compile cache entries to disk.
269+
*/
270+
static flushCompileCache(): void {
271+
try {
272+
module.flushCompileCache?.();
273+
debug('compile cache flushed');
274+
} catch (err) {
275+
debug('compile cache flush failed: %o', err);
276+
}
277+
}
278+
279+
/**
280+
* Remove the compile cache directory.
281+
*/
282+
static cleanCompileCache(baseDir: string): void {
283+
const compileCacheDir = path.join(baseDir, '.egg', 'compile-cache');
284+
fs.rmSync(compileCacheDir, { recursive: true, force: true });
285+
debug('compile cache removed: %s', compileCacheDir);
243286
}
244287

245288
// --- Path Utilities ---
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = { compiled: true };

0 commit comments

Comments
 (0)