@eggjs/bin 8.0.2-beta.5 → 8.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.
- package/dist/baseCommand.d.ts +1 -0
- package/dist/baseCommand.js +10 -0
- package/dist/commands/cov.d.ts +9 -9
- package/dist/commands/dev.d.ts +5 -5
- package/dist/commands/dev.js +1 -7
- package/dist/commands/manifest.d.ts +22 -0
- package/dist/commands/manifest.js +108 -0
- package/dist/commands/test.d.ts +9 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/scripts/manifest-generate.mjs +59 -0
- package/package.json +10 -8
- package/scripts/manifest-generate.mjs +59 -0
package/dist/baseCommand.d.ts
CHANGED
|
@@ -46,6 +46,7 @@ declare abstract class BaseCommand<T extends typeof Command> extends Command {
|
|
|
46
46
|
protected formatRequires(): Promise<string[]>;
|
|
47
47
|
protected formatImportModule(modulePath: string): string;
|
|
48
48
|
protected addNodeOptions(options: string): void;
|
|
49
|
+
protected buildRequiresExecArgv(): Promise<string[]>;
|
|
49
50
|
protected forkNode(modulePath: string, forkArgs: string[], options?: ForkNodeOptions): Promise<void>;
|
|
50
51
|
}
|
|
51
52
|
//#endregion
|
package/dist/baseCommand.js
CHANGED
|
@@ -235,6 +235,16 @@ var BaseCommand = class extends Command {
|
|
|
235
235
|
if (!this.env.NODE_OPTIONS.includes(options)) this.env.NODE_OPTIONS = `${this.env.NODE_OPTIONS} ${options}`;
|
|
236
236
|
} else this.env.NODE_OPTIONS = options;
|
|
237
237
|
}
|
|
238
|
+
async buildRequiresExecArgv() {
|
|
239
|
+
const requires = await this.formatRequires();
|
|
240
|
+
const execArgv = [];
|
|
241
|
+
for (const r of requires) {
|
|
242
|
+
const module = this.formatImportModule(r);
|
|
243
|
+
const splitIndex = module.indexOf(" ");
|
|
244
|
+
if (splitIndex !== -1) execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1));
|
|
245
|
+
}
|
|
246
|
+
return execArgv;
|
|
247
|
+
}
|
|
238
248
|
async forkNode(modulePath, forkArgs, options = {}) {
|
|
239
249
|
const env = {
|
|
240
250
|
...this.env,
|
package/dist/commands/cov.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import Test from "./test.js";
|
|
2
2
|
import { InlineConfig } from "vitest/node";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _oclif_core_interfaces0 from "@oclif/core/interfaces";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/cov.d.ts
|
|
6
6
|
declare class Cov<T extends typeof Cov> extends Test<T> {
|
|
7
7
|
static description: string;
|
|
8
8
|
static examples: string[];
|
|
9
9
|
static flags: {
|
|
10
|
-
exclude:
|
|
11
|
-
bail:
|
|
12
|
-
timeout:
|
|
13
|
-
'no-timeout':
|
|
14
|
-
grep:
|
|
15
|
-
changed:
|
|
16
|
-
watch:
|
|
17
|
-
pool:
|
|
10
|
+
exclude: _oclif_core_interfaces0.OptionFlag<string[] | undefined, _oclif_core_interfaces0.CustomOptions>;
|
|
11
|
+
bail: _oclif_core_interfaces0.BooleanFlag<boolean>;
|
|
12
|
+
timeout: _oclif_core_interfaces0.OptionFlag<number, _oclif_core_interfaces0.CustomOptions>;
|
|
13
|
+
'no-timeout': _oclif_core_interfaces0.BooleanFlag<boolean>;
|
|
14
|
+
grep: _oclif_core_interfaces0.OptionFlag<string | undefined, _oclif_core_interfaces0.CustomOptions>;
|
|
15
|
+
changed: _oclif_core_interfaces0.BooleanFlag<boolean>;
|
|
16
|
+
watch: _oclif_core_interfaces0.BooleanFlag<boolean>;
|
|
17
|
+
pool: _oclif_core_interfaces0.OptionFlag<string, _oclif_core_interfaces0.CustomOptions>;
|
|
18
18
|
};
|
|
19
19
|
protected get defaultCoverageExcludes(): string[];
|
|
20
20
|
/**
|
package/dist/commands/dev.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { BaseCommand } from "../baseCommand.js";
|
|
2
|
-
import * as
|
|
2
|
+
import * as _oclif_core_interfaces11 from "@oclif/core/interfaces";
|
|
3
3
|
|
|
4
4
|
//#region src/commands/dev.d.ts
|
|
5
5
|
declare class Dev<T extends typeof Dev> extends BaseCommand<T> {
|
|
6
6
|
static description: string;
|
|
7
7
|
static examples: string[];
|
|
8
8
|
static flags: {
|
|
9
|
-
port:
|
|
10
|
-
workers:
|
|
11
|
-
framework:
|
|
12
|
-
sticky:
|
|
9
|
+
port: _oclif_core_interfaces11.OptionFlag<number | undefined, _oclif_core_interfaces11.CustomOptions>;
|
|
10
|
+
workers: _oclif_core_interfaces11.OptionFlag<number, _oclif_core_interfaces11.CustomOptions>;
|
|
11
|
+
framework: _oclif_core_interfaces11.OptionFlag<string | undefined, _oclif_core_interfaces11.CustomOptions>;
|
|
12
|
+
sticky: _oclif_core_interfaces11.BooleanFlag<boolean>;
|
|
13
13
|
};
|
|
14
14
|
run(): Promise<void>;
|
|
15
15
|
protected formatEggStartOptions(): Promise<{
|
package/dist/commands/dev.js
CHANGED
|
@@ -31,13 +31,7 @@ var Dev = class extends BaseCommand {
|
|
|
31
31
|
const serverBin = getSourceFilename(`../scripts/start-cluster.${this.isESM ? "mjs" : "cjs"}`);
|
|
32
32
|
const eggStartOptions = await this.formatEggStartOptions();
|
|
33
33
|
const args = [JSON.stringify(eggStartOptions)];
|
|
34
|
-
const
|
|
35
|
-
const execArgv = [];
|
|
36
|
-
for (const r of requires) {
|
|
37
|
-
const module = this.formatImportModule(r);
|
|
38
|
-
const splitIndex = module.indexOf(" ");
|
|
39
|
-
if (splitIndex !== -1) execArgv.push(module.slice(0, splitIndex), module.slice(splitIndex + 2, -1));
|
|
40
|
-
}
|
|
34
|
+
const execArgv = await this.buildRequiresExecArgv();
|
|
41
35
|
await this.forkNode(serverBin, args, { execArgv });
|
|
42
36
|
}
|
|
43
37
|
async formatEggStartOptions() {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { BaseCommand } from "../baseCommand.js";
|
|
2
|
+
import * as _oclif_core_interfaces18 from "@oclif/core/interfaces";
|
|
3
|
+
|
|
4
|
+
//#region src/commands/manifest.d.ts
|
|
5
|
+
declare class Manifest<T extends typeof Manifest> extends BaseCommand<T> {
|
|
6
|
+
static description: string;
|
|
7
|
+
static examples: string[];
|
|
8
|
+
static args: {
|
|
9
|
+
action: _oclif_core_interfaces18.Arg<string, Record<string, unknown>>;
|
|
10
|
+
};
|
|
11
|
+
static flags: {
|
|
12
|
+
framework: _oclif_core_interfaces18.OptionFlag<string | undefined, _oclif_core_interfaces18.CustomOptions>;
|
|
13
|
+
env: _oclif_core_interfaces18.OptionFlag<string, _oclif_core_interfaces18.CustomOptions>;
|
|
14
|
+
scope: _oclif_core_interfaces18.OptionFlag<string, _oclif_core_interfaces18.CustomOptions>;
|
|
15
|
+
};
|
|
16
|
+
run(): Promise<void>;
|
|
17
|
+
private runGenerate;
|
|
18
|
+
private runValidate;
|
|
19
|
+
private runClean;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Manifest as default };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { getSourceFilename } from "../utils.js";
|
|
2
|
+
import { BaseCommand } from "../baseCommand.js";
|
|
3
|
+
import { debuglog } from "node:util";
|
|
4
|
+
import { getFrameworkPath } from "@eggjs/utils";
|
|
5
|
+
import { Args, Flags } from "@oclif/core";
|
|
6
|
+
|
|
7
|
+
//#region src/commands/manifest.ts
|
|
8
|
+
const debug = debuglog("egg/bin/commands/manifest");
|
|
9
|
+
var Manifest = class extends BaseCommand {
|
|
10
|
+
static description = "Manage the startup manifest for faster cold starts";
|
|
11
|
+
static examples = [
|
|
12
|
+
"<%= config.bin %> <%= command.id %> generate",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> generate --env=prod",
|
|
14
|
+
"<%= config.bin %> <%= command.id %> validate --env=prod",
|
|
15
|
+
"<%= config.bin %> <%= command.id %> clean"
|
|
16
|
+
];
|
|
17
|
+
static args = { action: Args.string({
|
|
18
|
+
required: true,
|
|
19
|
+
description: "Action to perform",
|
|
20
|
+
options: [
|
|
21
|
+
"generate",
|
|
22
|
+
"validate",
|
|
23
|
+
"clean"
|
|
24
|
+
]
|
|
25
|
+
}) };
|
|
26
|
+
static flags = {
|
|
27
|
+
framework: Flags.string({ description: "specify framework that can be absolute path or npm package" }),
|
|
28
|
+
env: Flags.string({
|
|
29
|
+
description: "server environment for manifest generation/validation",
|
|
30
|
+
default: "prod"
|
|
31
|
+
}),
|
|
32
|
+
scope: Flags.string({
|
|
33
|
+
description: "server scope for manifest validation",
|
|
34
|
+
default: ""
|
|
35
|
+
})
|
|
36
|
+
};
|
|
37
|
+
async run() {
|
|
38
|
+
const { action } = this.args;
|
|
39
|
+
switch (action) {
|
|
40
|
+
case "generate":
|
|
41
|
+
await this.runGenerate();
|
|
42
|
+
break;
|
|
43
|
+
case "validate":
|
|
44
|
+
await this.runValidate();
|
|
45
|
+
break;
|
|
46
|
+
case "clean":
|
|
47
|
+
await this.runClean();
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async runGenerate() {
|
|
52
|
+
const { flags } = this;
|
|
53
|
+
const framework = getFrameworkPath({
|
|
54
|
+
framework: flags.framework,
|
|
55
|
+
baseDir: flags.base
|
|
56
|
+
});
|
|
57
|
+
debug("generate manifest: baseDir=%s, framework=%s, env=%s, scope=%s", flags.base, framework, flags.env, flags.scope);
|
|
58
|
+
const options = {
|
|
59
|
+
baseDir: flags.base,
|
|
60
|
+
framework,
|
|
61
|
+
env: flags.env,
|
|
62
|
+
scope: flags.scope
|
|
63
|
+
};
|
|
64
|
+
const serverBin = getSourceFilename("../scripts/manifest-generate.mjs");
|
|
65
|
+
const args = [JSON.stringify(options)];
|
|
66
|
+
const execArgv = await this.buildRequiresExecArgv();
|
|
67
|
+
await this.forkNode(serverBin, args, { execArgv });
|
|
68
|
+
}
|
|
69
|
+
async runValidate() {
|
|
70
|
+
const { flags } = this;
|
|
71
|
+
debug("validate manifest: baseDir=%s, env=%s, scope=%s", flags.base, flags.env, flags.scope);
|
|
72
|
+
const savedEggManifest = process.env.EGG_MANIFEST;
|
|
73
|
+
process.env.EGG_MANIFEST = "true";
|
|
74
|
+
try {
|
|
75
|
+
const { ManifestStore } = await import("@eggjs/core");
|
|
76
|
+
const store = ManifestStore.load(flags.base, flags.env, flags.scope);
|
|
77
|
+
if (!store) {
|
|
78
|
+
console.error("[manifest] Manifest is invalid or does not exist");
|
|
79
|
+
return this.exit(1);
|
|
80
|
+
}
|
|
81
|
+
const { data } = store;
|
|
82
|
+
const resolveCacheCount = Object.keys(data.resolveCache ?? {}).length;
|
|
83
|
+
const fileDiscoveryCount = Object.keys(data.fileDiscovery ?? {}).length;
|
|
84
|
+
const extensionCount = Object.keys(data.extensions ?? {}).length;
|
|
85
|
+
console.log("[manifest] Manifest is valid");
|
|
86
|
+
console.log("[manifest] version: %d", data.version);
|
|
87
|
+
console.log("[manifest] generatedAt: %s", data.generatedAt);
|
|
88
|
+
console.log("[manifest] serverEnv: %s", data.invalidation.serverEnv);
|
|
89
|
+
console.log("[manifest] serverScope: %s", data.invalidation.serverScope);
|
|
90
|
+
console.log("[manifest] resolveCache entries: %d", resolveCacheCount);
|
|
91
|
+
console.log("[manifest] fileDiscovery entries: %d", fileDiscoveryCount);
|
|
92
|
+
console.log("[manifest] extension entries: %d", extensionCount);
|
|
93
|
+
} finally {
|
|
94
|
+
if (savedEggManifest === void 0) delete process.env.EGG_MANIFEST;
|
|
95
|
+
else process.env.EGG_MANIFEST = savedEggManifest;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async runClean() {
|
|
99
|
+
const { flags } = this;
|
|
100
|
+
debug("clean manifest: baseDir=%s", flags.base);
|
|
101
|
+
const { ManifestStore } = await import("@eggjs/core");
|
|
102
|
+
ManifestStore.clean(flags.base);
|
|
103
|
+
console.log("[manifest] Manifest cleaned");
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
export { Manifest as default };
|
package/dist/commands/test.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { BaseCommand } from "../baseCommand.js";
|
|
2
2
|
import { InlineConfig } from "vitest/node";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _oclif_core_interfaces25 from "@oclif/core/interfaces";
|
|
4
4
|
|
|
5
5
|
//#region src/commands/test.d.ts
|
|
6
6
|
declare class Test<T extends typeof Test> extends BaseCommand<T> {
|
|
7
7
|
static args: {
|
|
8
|
-
file:
|
|
8
|
+
file: _oclif_core_interfaces25.Arg<string | undefined, Record<string, unknown>>;
|
|
9
9
|
};
|
|
10
10
|
static description: string;
|
|
11
11
|
static examples: string[];
|
|
12
12
|
static flags: {
|
|
13
|
-
bail:
|
|
14
|
-
timeout:
|
|
15
|
-
'no-timeout':
|
|
16
|
-
grep:
|
|
17
|
-
changed:
|
|
18
|
-
watch:
|
|
19
|
-
pool:
|
|
13
|
+
bail: _oclif_core_interfaces25.BooleanFlag<boolean>;
|
|
14
|
+
timeout: _oclif_core_interfaces25.OptionFlag<number, _oclif_core_interfaces25.CustomOptions>;
|
|
15
|
+
'no-timeout': _oclif_core_interfaces25.BooleanFlag<boolean>;
|
|
16
|
+
grep: _oclif_core_interfaces25.OptionFlag<string | undefined, _oclif_core_interfaces25.CustomOptions>;
|
|
17
|
+
changed: _oclif_core_interfaces25.BooleanFlag<boolean>;
|
|
18
|
+
watch: _oclif_core_interfaces25.BooleanFlag<boolean>;
|
|
19
|
+
pool: _oclif_core_interfaces25.OptionFlag<string, _oclif_core_interfaces25.CustomOptions>;
|
|
20
20
|
};
|
|
21
21
|
run(): Promise<void>;
|
|
22
22
|
protected buildVitestConfig(files: string[]): Promise<InlineConfig>;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ import { BaseCommand, ForkError, ForkNodeOptions } from "./baseCommand.js";
|
|
|
3
3
|
import Test from "./commands/test.js";
|
|
4
4
|
import Cov from "./commands/cov.js";
|
|
5
5
|
import Dev from "./commands/dev.js";
|
|
6
|
+
import Manifest from "./commands/manifest.js";
|
|
6
7
|
export * from "@oclif/core";
|
|
7
|
-
export { BaseCommand, Cov, Dev, ForkError, ForkNodeOptions, PackageEgg, Test };
|
|
8
|
+
export { BaseCommand, Cov, Dev, ForkError, ForkNodeOptions, Manifest, PackageEgg, Test };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,8 @@ import { BaseCommand, ForkError } from "./baseCommand.js";
|
|
|
2
2
|
import Test from "./commands/test.js";
|
|
3
3
|
import Cov from "./commands/cov.js";
|
|
4
4
|
import Dev from "./commands/dev.js";
|
|
5
|
+
import Manifest from "./commands/manifest.js";
|
|
5
6
|
|
|
6
7
|
export * from "@oclif/core"
|
|
7
8
|
|
|
8
|
-
export { BaseCommand, Cov, Dev, ForkError, Test };
|
|
9
|
+
export { BaseCommand, Cov, Dev, ForkError, Manifest, Test };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { debuglog } from 'node:util';
|
|
2
|
+
|
|
3
|
+
import { importModule } from '@eggjs/utils';
|
|
4
|
+
|
|
5
|
+
const debug = debuglog('egg/bin/scripts/manifest-generate');
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
debug('argv: %o', process.argv);
|
|
9
|
+
const options = JSON.parse(process.argv[2]);
|
|
10
|
+
debug('manifest generate options: %o', options);
|
|
11
|
+
|
|
12
|
+
// Set server env/scope before importing framework
|
|
13
|
+
if (options.env) {
|
|
14
|
+
process.env.EGG_SERVER_ENV = options.env;
|
|
15
|
+
}
|
|
16
|
+
if (options.scope) {
|
|
17
|
+
process.env.EGG_SERVER_SCOPE = options.scope;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Clean any existing manifest before generation to ensure the collector
|
|
21
|
+
// captures all lookups (not just cache misses from a stale manifest).
|
|
22
|
+
const { ManifestStore } = await importModule('@eggjs/core', {
|
|
23
|
+
paths: [options.framework],
|
|
24
|
+
});
|
|
25
|
+
ManifestStore.clean(options.baseDir);
|
|
26
|
+
|
|
27
|
+
const framework = await importModule(options.framework);
|
|
28
|
+
const app = await framework.start({
|
|
29
|
+
baseDir: options.baseDir,
|
|
30
|
+
framework: options.framework,
|
|
31
|
+
env: options.env,
|
|
32
|
+
metadataOnly: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Generate manifest from collected metadata
|
|
36
|
+
const manifest = app.loader.generateManifest();
|
|
37
|
+
|
|
38
|
+
// Write manifest to .egg/manifest.json
|
|
39
|
+
await ManifestStore.write(options.baseDir, manifest);
|
|
40
|
+
|
|
41
|
+
// Log stats
|
|
42
|
+
const resolveCacheCount = Object.keys(manifest.resolveCache).length;
|
|
43
|
+
const fileDiscoveryCount = Object.keys(manifest.fileDiscovery).length;
|
|
44
|
+
const extensionCount = Object.keys(manifest.extensions).length;
|
|
45
|
+
console.log('[manifest] Generated manifest v%d at %s', manifest.version, manifest.generatedAt);
|
|
46
|
+
console.log('[manifest] resolveCache entries: %d', resolveCacheCount);
|
|
47
|
+
console.log('[manifest] fileDiscovery entries: %d', fileDiscoveryCount);
|
|
48
|
+
console.log('[manifest] extension entries: %d', extensionCount);
|
|
49
|
+
console.log('[manifest] Written to %s/.egg/manifest.json', options.baseDir);
|
|
50
|
+
|
|
51
|
+
// Clean up and exit
|
|
52
|
+
await app.close();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
main().catch((err) => {
|
|
57
|
+
console.error('[manifest] Generation failed:', err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/bin",
|
|
3
|
-
"version": "8.0.2-beta.
|
|
3
|
+
"version": "8.0.2-beta.7",
|
|
4
4
|
"description": "egg developer tool",
|
|
5
5
|
"homepage": "https://github.com/eggjs/egg/tree/next/tools/egg-bin",
|
|
6
6
|
"bugs": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"./baseCommand": "./dist/baseCommand.js",
|
|
31
31
|
"./commands/cov": "./dist/commands/cov.js",
|
|
32
32
|
"./commands/dev": "./dist/commands/dev.js",
|
|
33
|
+
"./commands/manifest": "./dist/commands/manifest.js",
|
|
33
34
|
"./commands/test": "./dist/commands/test.js",
|
|
34
35
|
"./types": "./dist/types.js",
|
|
35
36
|
"./utils": "./dist/utils.js",
|
|
@@ -49,8 +50,9 @@
|
|
|
49
50
|
"tsconfig-paths": "^4.2.0",
|
|
50
51
|
"utility": "^2.5.0",
|
|
51
52
|
"vitest": "^4.0.15",
|
|
52
|
-
"@eggjs/tegg-vitest": "4.0.2-beta.
|
|
53
|
-
"@eggjs/utils": "5.0.2-beta.
|
|
53
|
+
"@eggjs/tegg-vitest": "4.0.2-beta.7",
|
|
54
|
+
"@eggjs/utils": "5.0.2-beta.7",
|
|
55
|
+
"@eggjs/core": "7.0.2-beta.7"
|
|
54
56
|
},
|
|
55
57
|
"devDependencies": {
|
|
56
58
|
"@swc-node/register": "^1.11.1",
|
|
@@ -66,13 +68,13 @@
|
|
|
66
68
|
"runscript": "^2.0.1",
|
|
67
69
|
"sdk-base": "^5.0.1",
|
|
68
70
|
"typescript": "^5.9.3",
|
|
69
|
-
"@eggjs/mock": "7.0.2-beta.
|
|
70
|
-
"@eggjs/
|
|
71
|
-
"
|
|
72
|
-
"
|
|
71
|
+
"@eggjs/mock": "7.0.2-beta.7",
|
|
72
|
+
"@eggjs/supertest": "9.0.2-beta.7",
|
|
73
|
+
"egg": "4.1.2-beta.7",
|
|
74
|
+
"@eggjs/tsconfig": "3.1.2-beta.7"
|
|
73
75
|
},
|
|
74
76
|
"peerDependencies": {
|
|
75
|
-
"@eggjs/mock": "7.0.2-beta.
|
|
77
|
+
"@eggjs/mock": "7.0.2-beta.7"
|
|
76
78
|
},
|
|
77
79
|
"peerDependenciesMeta": {
|
|
78
80
|
"@eggjs/mock": {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { debuglog } from 'node:util';
|
|
2
|
+
|
|
3
|
+
import { importModule } from '@eggjs/utils';
|
|
4
|
+
|
|
5
|
+
const debug = debuglog('egg/bin/scripts/manifest-generate');
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
debug('argv: %o', process.argv);
|
|
9
|
+
const options = JSON.parse(process.argv[2]);
|
|
10
|
+
debug('manifest generate options: %o', options);
|
|
11
|
+
|
|
12
|
+
// Set server env/scope before importing framework
|
|
13
|
+
if (options.env) {
|
|
14
|
+
process.env.EGG_SERVER_ENV = options.env;
|
|
15
|
+
}
|
|
16
|
+
if (options.scope) {
|
|
17
|
+
process.env.EGG_SERVER_SCOPE = options.scope;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Clean any existing manifest before generation to ensure the collector
|
|
21
|
+
// captures all lookups (not just cache misses from a stale manifest).
|
|
22
|
+
const { ManifestStore } = await importModule('@eggjs/core', {
|
|
23
|
+
paths: [options.framework],
|
|
24
|
+
});
|
|
25
|
+
ManifestStore.clean(options.baseDir);
|
|
26
|
+
|
|
27
|
+
const framework = await importModule(options.framework);
|
|
28
|
+
const app = await framework.start({
|
|
29
|
+
baseDir: options.baseDir,
|
|
30
|
+
framework: options.framework,
|
|
31
|
+
env: options.env,
|
|
32
|
+
metadataOnly: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Generate manifest from collected metadata
|
|
36
|
+
const manifest = app.loader.generateManifest();
|
|
37
|
+
|
|
38
|
+
// Write manifest to .egg/manifest.json
|
|
39
|
+
await ManifestStore.write(options.baseDir, manifest);
|
|
40
|
+
|
|
41
|
+
// Log stats
|
|
42
|
+
const resolveCacheCount = Object.keys(manifest.resolveCache).length;
|
|
43
|
+
const fileDiscoveryCount = Object.keys(manifest.fileDiscovery).length;
|
|
44
|
+
const extensionCount = Object.keys(manifest.extensions).length;
|
|
45
|
+
console.log('[manifest] Generated manifest v%d at %s', manifest.version, manifest.generatedAt);
|
|
46
|
+
console.log('[manifest] resolveCache entries: %d', resolveCacheCount);
|
|
47
|
+
console.log('[manifest] fileDiscovery entries: %d', fileDiscoveryCount);
|
|
48
|
+
console.log('[manifest] extension entries: %d', extensionCount);
|
|
49
|
+
console.log('[manifest] Written to %s/.egg/manifest.json', options.baseDir);
|
|
50
|
+
|
|
51
|
+
// Clean up and exit
|
|
52
|
+
await app.close();
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
main().catch((err) => {
|
|
57
|
+
console.error('[manifest] Generation failed:', err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
});
|