@eggjs/bin 7.0.0-beta.3 → 7.0.0

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.
Files changed (78) hide show
  1. package/README.md +5 -10
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +8 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +5 -0
  6. package/dist/commonjs/baseCommand.d.ts +49 -0
  7. package/dist/commonjs/baseCommand.js +370 -0
  8. package/dist/commonjs/commands/cov.d.ts +22 -0
  9. package/dist/commonjs/commands/cov.js +97 -0
  10. package/dist/commonjs/commands/dev.d.ts +21 -0
  11. package/dist/commonjs/commands/dev.js +95 -0
  12. package/dist/commonjs/commands/test.d.ts +23 -0
  13. package/dist/commonjs/commands/test.js +204 -0
  14. package/dist/commonjs/index.d.ts +7 -0
  15. package/dist/commonjs/index.js +30 -0
  16. package/dist/commonjs/package.json +3 -0
  17. package/dist/commonjs/types.d.ts +9 -0
  18. package/dist/commonjs/types.js +3 -0
  19. package/dist/commonjs/utils.d.ts +4 -0
  20. package/dist/commonjs/utils.js +45 -0
  21. package/dist/esm/baseCommand.d.ts +49 -0
  22. package/dist/esm/baseCommand.js +362 -0
  23. package/dist/esm/commands/cov.d.ts +22 -0
  24. package/dist/esm/commands/cov.js +91 -0
  25. package/dist/esm/commands/dev.d.ts +21 -0
  26. package/dist/esm/commands/dev.js +92 -0
  27. package/dist/esm/commands/test.d.ts +23 -0
  28. package/dist/esm/commands/test.js +198 -0
  29. package/dist/esm/index.d.ts +7 -5
  30. package/dist/esm/index.js +8 -6
  31. package/dist/esm/types.d.ts +9 -0
  32. package/dist/esm/types.js +2 -0
  33. package/dist/esm/utils.d.ts +0 -1
  34. package/dist/esm/utils.js +1 -11
  35. package/dist/package.json +1 -1
  36. package/dist/scripts/start-cluster.cjs +15 -0
  37. package/package.json +23 -27
  38. package/scripts/start-cluster.cjs +15 -0
  39. package/src/baseCommand.ts +392 -0
  40. package/src/commands/cov.ts +100 -0
  41. package/src/commands/dev.ts +99 -0
  42. package/src/commands/test.ts +216 -0
  43. package/src/index.ts +9 -5
  44. package/src/types.ts +9 -0
  45. package/src/utils.ts +0 -10
  46. package/dist/esm/bin/cli.d.ts +0 -2
  47. package/dist/esm/bin/cli.js +0 -34
  48. package/dist/esm/cmd/base.d.ts +0 -12
  49. package/dist/esm/cmd/base.js +0 -135
  50. package/dist/esm/cmd/cov.d.ts +0 -8
  51. package/dist/esm/cmd/cov.js +0 -103
  52. package/dist/esm/cmd/debug.d.ts +0 -5
  53. package/dist/esm/cmd/debug.js +0 -28
  54. package/dist/esm/cmd/dev.d.ts +0 -17
  55. package/dist/esm/cmd/dev.js +0 -118
  56. package/dist/esm/cmd/test.d.ts +0 -15
  57. package/dist/esm/cmd/test.js +0 -237
  58. package/dist/esm/config/framework.d.ts +0 -4
  59. package/dist/esm/config/framework.js +0 -4
  60. package/dist/esm/config/plugin.d.ts +0 -11
  61. package/dist/esm/config/plugin.js +0 -11
  62. package/dist/esm/middleware/global_options.d.ts +0 -5
  63. package/dist/esm/middleware/global_options.js +0 -182
  64. package/dist/esm/middleware/handle_error.d.ts +0 -5
  65. package/dist/esm/middleware/handle_error.js +0 -47
  66. package/dist/esm/middleware/inspect.d.ts +0 -5
  67. package/dist/esm/middleware/inspect.js +0 -69
  68. package/src/bin/cli.ts +0 -37
  69. package/src/cmd/base.ts +0 -133
  70. package/src/cmd/cov.ts +0 -89
  71. package/src/cmd/debug.ts +0 -14
  72. package/src/cmd/dev.ts +0 -102
  73. package/src/cmd/test.ts +0 -219
  74. package/src/config/framework.ts +0 -3
  75. package/src/config/plugin.ts +0 -10
  76. package/src/middleware/global_options.ts +0 -169
  77. package/src/middleware/handle_error.ts +0 -30
  78. package/src/middleware/inspect.ts +0 -54
@@ -1,47 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { debuglog } from 'node:util';
11
- import { Inject, LifecycleHook, LifecycleHookUnit, Program, ArtusCliError, } from '@artus-cli/artus-cli';
12
- const debug = debuglog('@eggjs/bin/middleware/handle_error');
13
- let default_1 = class {
14
- program;
15
- async configDidLoad() {
16
- this.program.use(async (_, next) => {
17
- debug('enter next');
18
- try {
19
- await next();
20
- debug('after next');
21
- }
22
- catch (err) {
23
- debug('next error: %o', err);
24
- // let artus cli to handle it
25
- if (err instanceof ArtusCliError)
26
- throw err;
27
- console.error(err);
28
- process.exit(typeof err.code === 'number' ? err.code : 1);
29
- }
30
- });
31
- }
32
- };
33
- __decorate([
34
- Inject(),
35
- __metadata("design:type", Program)
36
- ], default_1.prototype, "program", void 0);
37
- __decorate([
38
- LifecycleHook(),
39
- __metadata("design:type", Function),
40
- __metadata("design:paramtypes", []),
41
- __metadata("design:returntype", Promise)
42
- ], default_1.prototype, "configDidLoad", null);
43
- default_1 = __decorate([
44
- LifecycleHookUnit()
45
- ], default_1);
46
- export default default_1;
47
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaGFuZGxlX2Vycm9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL21pZGRsZXdhcmUvaGFuZGxlX2Vycm9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7OztBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTU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VBQUU7Ozs7OENBZWY7QUFuQlk7SUFEZCxpQkFBaUIsRUFBRTthQXFCbkIifQ==
@@ -1,5 +0,0 @@
1
- import { ApplicationLifecycle } from '@artus-cli/artus-cli';
2
- export default class implements ApplicationLifecycle {
3
- private readonly program;
4
- configDidLoad(): Promise<void>;
5
- }
@@ -1,69 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { debuglog } from 'node:util';
11
- import { Inject, LifecycleHook, LifecycleHookUnit, Program, } from '@artus-cli/artus-cli';
12
- import { addNodeOptionsToEnv } from '../utils.js';
13
- const debug = debuglog('@eggjs/bin/middleware/inspect');
14
- let default_1 = class {
15
- program;
16
- async configDidLoad() {
17
- // add global options
18
- // https://nodejs.org/dist/latest-v18.x/docs/api/cli.html#--inspect-brkhostport
19
- this.program.option({
20
- 'inspect-brk': {
21
- description: 'Activate inspector and break at start of user script',
22
- type: 'boolean',
23
- },
24
- inspect: {
25
- description: 'Activate inspector',
26
- type: 'boolean',
27
- },
28
- });
29
- this.program.use(async (ctx, next) => {
30
- debug('before next');
31
- let hasInspectOption = false;
32
- if (ctx.args.inspect === true) {
33
- addNodeOptionsToEnv('--inspect', ctx.env);
34
- hasInspectOption = true;
35
- }
36
- if (ctx.args['inspect-brk'] === true) {
37
- addNodeOptionsToEnv('--inspect-brk', ctx.env);
38
- hasInspectOption = true;
39
- }
40
- if (hasInspectOption) {
41
- ctx.args.timeout = false;
42
- debug('set timeout = false when inspect enable, set env.NODE_OPTIONS=%o', ctx.env.NODE_OPTIONS);
43
- }
44
- else if (process.env.JB_DEBUG_FILE) {
45
- // others like WebStorm 2019 will pass NODE_OPTIONS, and egg-bin itself will be debug, so could detect `process.env.JB_DEBUG_FILE`.
46
- ctx.args.timeout = false;
47
- debug('set timeout = false when process.env.JB_DEBUG_FILE=%o', process.env.JB_DEBUG_FILE);
48
- }
49
- debug('enter next');
50
- await next();
51
- debug('after next');
52
- });
53
- }
54
- };
55
- __decorate([
56
- Inject(),
57
- __metadata("design:type", Program)
58
- ], default_1.prototype, "program", void 0);
59
- __decorate([
60
- LifecycleHook(),
61
- __metadata("design:type", Function),
62
- __metadata("design:paramtypes", []),
63
- __metadata("design:returntype", Promise)
64
- ], default_1.prototype, "configDidLoad", null);
65
- default_1 = __decorate([
66
- LifecycleHookUnit()
67
- ], default_1);
68
- export default default_1;
69
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5zcGVjdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9taWRkbGV3YXJlL2luc3BlY3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7O0FBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLFdBQVcsQ0FBQztBQUNyQyxPQUFPLEVBQ0wsTUFBTSxFQUF3QixhQUFhLEVBQUUsaUJBQWlCLEVBQzlELE9BQU8sR0FDUixNQUFNLHNCQUFzQixDQUFDO0FBQzlCLE9BQU8sRUFBRSxtQkFBbUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUVsRCxNQUFNLEtBQUssR0FBRyxRQUFRLENBQUMsK0JBQStCLENBQUMsQ0FBQztBQUd6QyxnQkFBQTtJQUVJLE9BQU8sQ0FBVTtJQUc1QixBQUFOLEtBQUssQ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csQ0FBQyxZQUFZLENBQUMsQ0FBQztZQUNsRyxDQUFDO2lCQUFNLElBQUksT0FBTyxDQUFDLEdBQUcsQ0FBQyxhQUFhLEVBQUUsQ0FBQztnQkFDckMsbUlBQW1JO2dCQUNuSSxHQUFHLENBQUMsSUFBSSxDQUFDLE9BQU8sR0FBRyxLQUFLLENBQUM7Z0JBQ3pCLEtBQUssQ0FBQyx1REFBdUQsRUFBRSxPQUFPLENBQUMsR0FBRyxDQUFDLGFBQWEsQ0FBQyxDQUFDO1lBQzVGLENBQUM7WUFDRCxLQUFLLENBQUMsWUFBWSxDQUFDLENBQUM7WUFDcEIsTUFBTSxJQUFJLEVBQUUsQ0FBQztZQUNiLEtBQUssQ0FBQyxZQUFZLENBQUMsQ0FBQztRQUN0QixDQUFDLENBQUMsQ0FBQztJQUNMLENBQUM7Q0FDRixDQUFBO0FBekNrQjtJQURoQixNQUFNLEVBQUU7OEJBQ2lCLE9BQU87MENBQUM7QUFHNUI7SUFETCxhQUFhLEVBQUU7Ozs7OENBc0NmO0FBMUNZO0lBRGQsaUJBQWlCLEVBQUU7YUE0Q25CIn0=
package/src/bin/cli.ts DELETED
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import { start } from '@artus-cli/artus-cli';
6
-
7
- function getCurrentFilename() {
8
- if (typeof __filename === 'string') {
9
- return __filename;
10
- }
11
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
12
- // @ts-ignore
13
- return fileURLToPath(import.meta.url);
14
- }
15
-
16
- function main() {
17
- const currentFilename = getCurrentFilename();
18
- // src/bin/cli.ts => src/
19
- let baseDir = path.dirname(path.dirname(currentFilename));
20
- const isBuildJavascriptFile = getCurrentFilename().endsWith('.js');
21
- const exclude = [ 'scripts', 'bin', 'test', 'coverage' ];
22
- if (isBuildJavascriptFile) {
23
- // dist/esm/bin/cli.js => dist/
24
- baseDir = path.dirname(baseDir);
25
- exclude.push('*.ts');
26
- } else {
27
- exclude.push('dist');
28
- }
29
-
30
- start({
31
- binName: 'egg-bin',
32
- exclude,
33
- baseDir,
34
- });
35
- }
36
-
37
- main();
package/src/cmd/base.ts DELETED
@@ -1,133 +0,0 @@
1
- import { debuglog } from 'node:util';
2
- import { fork, ForkOptions, ChildProcess } from 'node:child_process';
3
- import {
4
- DefineCommand,
5
- Option, Command,
6
- CommandContext,
7
- Inject,
8
- Utils,
9
- } from '@artus-cli/artus-cli';
10
-
11
- const debug = debuglog('@eggjs/bin/base');
12
-
13
- // only hook once and only when ever start any child.
14
- const children = new Set<ChildProcess>();
15
- let hadHook = false;
16
- function graceful(proc: ChildProcess) {
17
- // save child ref
18
- children.add(proc);
19
-
20
- // only hook once
21
- /* c8 ignore else */
22
- if (!hadHook) {
23
- hadHook = true;
24
- let signal: NodeJS.Signals;
25
- [ 'SIGINT', 'SIGQUIT', 'SIGTERM' ].forEach(event => {
26
- process.once(event, () => {
27
- signal = event as NodeJS.Signals;
28
- process.exit(0);
29
- });
30
- });
31
-
32
- process.once('exit', (code: number) => {
33
- for (const child of children) {
34
- debug('process exit code: %o, kill child %o with %o', code, child.pid, signal);
35
- child.kill(signal);
36
- }
37
- });
38
- }
39
- }
40
-
41
- class ForkError extends Error {
42
- code: number | null;
43
- constructor(message: string, code: number | null) {
44
- super(message);
45
- this.code = code;
46
- }
47
- }
48
-
49
- @DefineCommand()
50
- export abstract class BaseCommand extends Command {
51
- @Option({
52
- description: 'whether show full command script only, default is false',
53
- alias: 'd',
54
- type: 'boolean',
55
- default: false,
56
- })
57
- dryRun: boolean;
58
-
59
- @Option({
60
- description: 'require the given module',
61
- alias: 'r',
62
- array: true,
63
- default: [],
64
- })
65
- require: string[];
66
-
67
- @Inject()
68
- ctx: CommandContext;
69
-
70
- @Inject()
71
- utils: Utils;
72
-
73
- // FIXME: should has a better way to init global args default value
74
- protected get base() {
75
- return this.ctx.args.base;
76
- }
77
-
78
- async run() {
79
- await this.utils.redirect([ '--help' ]);
80
- }
81
-
82
- protected async formatRequires() {
83
- const requires = this.require ?? [];
84
- const eggRequire = this.ctx.args.pkgEgg.require;
85
- if (Array.isArray(eggRequire)) {
86
- for (const r of eggRequire) {
87
- requires.push(r);
88
- }
89
- } else if (typeof eggRequire === 'string' && eggRequire) {
90
- requires.push(eggRequire);
91
- }
92
- return requires;
93
- }
94
-
95
- protected async forkNode(modulePath: string, args: string[], options: ForkOptions = {}) {
96
- if (this.dryRun) {
97
- console.log('dry run: $ %o', `${process.execPath} ${modulePath} ${args.join(' ')}`);
98
- return;
99
- }
100
- const forkExecArgv = [
101
- ...this.ctx.args.execArgv || [],
102
- ...options.execArgv || [],
103
- ];
104
-
105
- options = {
106
- stdio: 'inherit',
107
- env: this.ctx.env,
108
- cwd: this.base,
109
- ...options,
110
- execArgv: forkExecArgv,
111
- };
112
- const proc = fork(modulePath, args, options);
113
- debug('Run fork pid: %o\n\n$ %s%s %s %s\n\n',
114
- proc.pid,
115
- options.env?.NODE_OPTIONS ? `NODE_OPTIONS='${options.env.NODE_OPTIONS}' ` : '',
116
- process.execPath,
117
- modulePath, args.map(a => `'${a}'`).join(' '));
118
- graceful(proc);
119
-
120
- return new Promise<void>((resolve, reject) => {
121
- proc.once('exit', code => {
122
- debug('fork pid: %o exit code %o', proc.pid, code);
123
- children.delete(proc);
124
- if (code !== 0) {
125
- const err = new ForkError(modulePath + ' ' + args.join(' ') + ' exit with code ' + code, code);
126
- reject(err);
127
- } else {
128
- resolve();
129
- }
130
- });
131
- });
132
- }
133
- }
package/src/cmd/cov.ts DELETED
@@ -1,89 +0,0 @@
1
- import path from 'node:path';
2
- import fs from 'node:fs/promises';
3
- import { DefineCommand, Option } from '@artus-cli/artus-cli';
4
- import { importResolve } from '@eggjs/utils';
5
- import { TestCommand } from './test.js';
6
-
7
- @DefineCommand({
8
- command: 'cov [files...]',
9
- description: 'Run the test with coverage',
10
- alias: [ 'c' ],
11
- })
12
- export class CovCommand extends TestCommand {
13
- // will use on egg-mock https://github.com/eggjs/egg-mock/blob/84a64bd19d0569ec94664c898fb1b28367b95d60/index.js#L7
14
- @Option({
15
- description: 'prerequire files for coverage instrument',
16
- type: 'boolean',
17
- default: false,
18
- })
19
- prerequire: boolean;
20
-
21
- @Option({
22
- description: 'coverage ignore, one or more files patterns`',
23
- array: true,
24
- default: [],
25
- })
26
- x: string[];
27
-
28
- @Option({
29
- description: 'c8 instruments passthrough`',
30
- default: '--temp-directory node_modules/.c8_output -r text-summary -r json-summary -r json -r lcov -r cobertura',
31
- })
32
- c8: string;
33
-
34
- get defaultExcludes() {
35
- return [
36
- 'example/',
37
- 'examples/',
38
- 'mocks**/',
39
- 'docs/',
40
- // https://github.com/JaKXz/test-exclude/blob/620a7be412d4fc2070d50f0f63e3228314066fc9/index.js#L73
41
- 'test/**',
42
- 'test{,-*}.js',
43
- '**/*.test.js',
44
- '**/__tests__/**',
45
- '**/node_modules/**',
46
- 'typings',
47
- '**/*.d.ts',
48
- ];
49
- }
50
-
51
- protected async forkNode(modulePath: string, args: string[]) {
52
- if (this.prerequire) {
53
- this.ctx.env.EGG_BIN_PREREQUIRE = 'true';
54
- }
55
- // append cobertura
56
- if (this.c8) {
57
- this.c8 += ' -r cobertura';
58
- }
59
-
60
- // add c8 args
61
- // https://github.com/eggjs/egg/issues/3930
62
- const c8Args = [
63
- // '--show-process-tree',
64
- ...this.c8.split(' ').filter(a => a.trim()),
65
- ];
66
- if (this.ctx.args.typescript) {
67
- this.ctx.env.SPAWN_WRAP_SHIM_ROOT = path.join(this.base, 'node_modules');
68
- c8Args.push('--extension');
69
- c8Args.push('.ts');
70
- }
71
-
72
- const excludes = new Set([
73
- ...process.env.COV_EXCLUDES?.split(',') ?? [],
74
- ...this.defaultExcludes,
75
- ...this.x,
76
- ]);
77
- for (const exclude of excludes) {
78
- c8Args.push('-x');
79
- c8Args.push(exclude);
80
- }
81
- const c8File = importResolve('c8/bin/c8.js');
82
- const outputDir = path.join(this.base, 'node_modules/.c8_output');
83
- await fs.rm(outputDir, { force: true, recursive: true });
84
- const coverageDir = path.join(this.base, 'coverage');
85
- await fs.rm(coverageDir, { force: true, recursive: true });
86
-
87
- await super.forkNode(c8File, [ ...c8Args, process.execPath, ...this.ctx.args.execArgv || [], modulePath, ...args ]);
88
- }
89
- }
package/src/cmd/debug.ts DELETED
@@ -1,14 +0,0 @@
1
- import { DefineCommand, Command, Utils, Inject } from '@artus-cli/artus-cli';
2
-
3
- @DefineCommand({
4
- command: 'debug',
5
- description: 'Alias to `egg-bin dev --inspect`',
6
- })
7
- export class DebugCommand extends Command {
8
- @Inject()
9
- utils: Utils;
10
-
11
- async run() {
12
- await this.utils.redirect([ 'dev', '--inspect' ]);
13
- }
14
- }
package/src/cmd/dev.ts DELETED
@@ -1,102 +0,0 @@
1
- import { debuglog } from 'node:util';
2
- import { DefineCommand, Option } from '@artus-cli/artus-cli';
3
- import utils from '@eggjs/utils';
4
- import detect from 'detect-port';
5
- import { BaseCommand } from './base.js';
6
- import { getSourceFilename } from '../utils.js';
7
-
8
- const debug = debuglog('egg-bin:dev');
9
-
10
- @DefineCommand({
11
- command: 'dev',
12
- description: 'Start server at local dev mode',
13
- alias: [ 'd' ],
14
- })
15
- export class DevCommand extends BaseCommand {
16
- @Option({
17
- description: 'listening port, default to 7001',
18
- alias: 'p',
19
- })
20
- port: number;
21
-
22
- @Option({
23
- description: 'numbers of app workers, default to 1 at local mode',
24
- alias: [ 'c', 'cluster' ],
25
- default: 1,
26
- })
27
- workers: number;
28
-
29
- @Option({
30
- description: 'specify framework that can be absolute path or npm package, default is egg',
31
- })
32
- framework: string;
33
-
34
- @Option({
35
- description: 'start a sticky cluster server, default to false',
36
- type: 'boolean',
37
- default: false,
38
- })
39
- sticky: boolean;
40
-
41
- async run() {
42
- debug('run dev: %o', this.ctx.args);
43
- this.ctx.env.NODE_ENV = this.ctx.env.NODE_ENV ?? 'development';
44
- this.ctx.env.EGG_MASTER_CLOSE_TIMEOUT = '1000';
45
- const serverBin = getSourceFilename('../scripts/start-cluster.mjs');
46
- const eggStartOptions = await this.formatEggStartOptions();
47
- const args = [ JSON.stringify(eggStartOptions) ];
48
- const requires = await this.formatRequires();
49
- const execArgv: string[] = [];
50
- for (const r of requires) {
51
- execArgv.push('--require');
52
- execArgv.push(r);
53
- }
54
- await this.forkNode(serverBin, args, { execArgv });
55
- }
56
-
57
- protected async formatEggStartOptions() {
58
- this.framework = utils.getFrameworkPath({
59
- framework: this.framework,
60
- baseDir: this.base,
61
- });
62
-
63
- if (!this.port) {
64
- let configuredPort: number | undefined;
65
- try {
66
- const configuration = await utils.getConfig({
67
- framework: this.framework,
68
- baseDir: this.base,
69
- env: 'local',
70
- });
71
- configuredPort = configuration?.cluster?.listen?.port;
72
- } catch (err) {
73
- /** skip when failing to read the configuration */
74
- debug('getConfig error: %s, framework: %o, baseDir: %o, env: local',
75
- err, this.framework, this.base);
76
- }
77
- if (configuredPort) {
78
- this.port = configuredPort;
79
- debug(`use port ${this.port} from configuration file`);
80
- } else {
81
- const defaultPort = process.env.EGG_BIN_DEFAULT_PORT ?? 7001;
82
- debug('detect available port');
83
- this.port = await detect(defaultPort);
84
- if (this.port !== defaultPort) {
85
- console.warn('[egg-bin] server port %s is in use, now using port %o',
86
- defaultPort, this.port);
87
- }
88
- debug(`use available port ${this.port}`);
89
- }
90
- }
91
-
92
- return {
93
- baseDir: this.base,
94
- workers: this.workers,
95
- port: this.port,
96
- framework: this.framework,
97
- typescript: this.ctx.args.typescript,
98
- tscompiler: this.ctx.args.tscompiler,
99
- sticky: this.sticky,
100
- };
101
- }
102
- }