@eggjs/bin 7.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/dist/esm/bin/cli.d.ts +2 -0
- package/dist/esm/bin/cli.js +30 -0
- package/dist/esm/cmd/base.d.ts +12 -0
- package/dist/esm/cmd/base.js +135 -0
- package/dist/esm/cmd/cov.d.ts +8 -0
- package/dist/esm/cmd/cov.js +103 -0
- package/dist/esm/cmd/debug.d.ts +5 -0
- package/dist/esm/cmd/debug.js +28 -0
- package/dist/esm/cmd/dev.d.ts +17 -0
- package/dist/esm/cmd/dev.js +118 -0
- package/dist/esm/cmd/test.d.ts +15 -0
- package/dist/esm/cmd/test.js +237 -0
- package/dist/esm/config/framework.d.ts +4 -0
- package/dist/esm/config/framework.js +4 -0
- package/dist/esm/config/plugin.d.ts +11 -0
- package/dist/esm/config/plugin.js +11 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/middleware/global_options.d.ts +5 -0
- package/dist/esm/middleware/global_options.js +182 -0
- package/dist/esm/middleware/handle_error.d.ts +5 -0
- package/dist/esm/middleware/handle_error.js +47 -0
- package/dist/esm/middleware/inspect.d.ts +5 -0
- package/dist/esm/middleware/inspect.js +69 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/utils.d.ts +5 -0
- package/dist/esm/utils.js +46 -0
- package/dist/package.json +4 -0
- package/dist/scripts/postinstall.mjs +59 -0
- package/dist/scripts/start-cluster.mjs +14 -0
- package/package.json +123 -0
- package/scripts/postinstall.mjs +59 -0
- package/scripts/start-cluster.mjs +14 -0
- package/src/bin/cli.ts +33 -0
- package/src/cmd/base.ts +133 -0
- package/src/cmd/cov.ts +89 -0
- package/src/cmd/debug.ts +14 -0
- package/src/cmd/dev.ts +102 -0
- package/src/cmd/test.ts +219 -0
- package/src/config/framework.ts +3 -0
- package/src/config/plugin.ts +10 -0
- package/src/index.ts +5 -0
- package/src/middleware/global_options.ts +169 -0
- package/src/middleware/handle_error.ts +30 -0
- package/src/middleware/inspect.ts +54 -0
- package/src/utils.ts +47 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { debuglog } from 'node:util';
|
|
2
|
+
import {
|
|
3
|
+
Inject, ApplicationLifecycle, LifecycleHook, LifecycleHookUnit,
|
|
4
|
+
Program, CommandContext,
|
|
5
|
+
} from '@artus-cli/artus-cli';
|
|
6
|
+
import { addNodeOptionsToEnv } from '../utils.js';
|
|
7
|
+
|
|
8
|
+
const debug = debuglog('@eggjs/bin/middleware/inspect');
|
|
9
|
+
|
|
10
|
+
@LifecycleHookUnit()
|
|
11
|
+
export default class implements ApplicationLifecycle {
|
|
12
|
+
@Inject()
|
|
13
|
+
private readonly program: Program;
|
|
14
|
+
|
|
15
|
+
@LifecycleHook()
|
|
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
|
+
|
|
30
|
+
this.program.use(async (ctx: CommandContext, next) => {
|
|
31
|
+
debug('before next');
|
|
32
|
+
let hasInspectOption = false;
|
|
33
|
+
if (ctx.args.inspect === true) {
|
|
34
|
+
addNodeOptionsToEnv('--inspect', ctx.env);
|
|
35
|
+
hasInspectOption = true;
|
|
36
|
+
}
|
|
37
|
+
if (ctx.args['inspect-brk'] === true) {
|
|
38
|
+
addNodeOptionsToEnv('--inspect-brk', ctx.env);
|
|
39
|
+
hasInspectOption = true;
|
|
40
|
+
}
|
|
41
|
+
if (hasInspectOption) {
|
|
42
|
+
ctx.args.timeout = false;
|
|
43
|
+
debug('set timeout = false when inspect enable, set env.NODE_OPTIONS=%o', ctx.env.NODE_OPTIONS);
|
|
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
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
export function addNodeOptionsToEnv(options: string, env: Record<string, any>) {
|
|
6
|
+
if (env.NODE_OPTIONS) {
|
|
7
|
+
if (!env.NODE_OPTIONS.includes(options)) {
|
|
8
|
+
env.NODE_OPTIONS = `${env.NODE_OPTIONS} ${options}`;
|
|
9
|
+
}
|
|
10
|
+
} else {
|
|
11
|
+
env.NODE_OPTIONS = options;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function readPackageJSON(baseDir: string) {
|
|
16
|
+
const pkgFile = path.join(baseDir, 'package.json');
|
|
17
|
+
try {
|
|
18
|
+
const pkgJSON = await fs.readFile(pkgFile, 'utf8');
|
|
19
|
+
return JSON.parse(pkgJSON);
|
|
20
|
+
} catch {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function hasTsConfig(baseDir: string) {
|
|
26
|
+
const pkgFile = path.join(baseDir, 'tsconfig.json');
|
|
27
|
+
try {
|
|
28
|
+
await fs.access(pkgFile);
|
|
29
|
+
return true;
|
|
30
|
+
} catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function getSourceDirname() {
|
|
36
|
+
if (typeof __dirname === 'string') {
|
|
37
|
+
return __dirname;
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
42
|
+
return path.dirname(__filename);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function getSourceFilename(filename: string) {
|
|
46
|
+
return path.join(getSourceDirname(), filename);
|
|
47
|
+
}
|