1 | #!/usr/bin/env node
|
2 |
|
3 | 'use strict';
|
4 |
|
5 | const inspectPattern = /^(--inspect|--inspect-brk)(=\d+)?$/;
|
6 | const inspectArg = process.argv.find((argument) => {
|
7 |
|
8 | return inspectPattern.test(argument);
|
9 | });
|
10 |
|
11 | if (process.env.NODE_DEBUG_OPTION || inspectArg) {
|
12 | const ChildProcess = require('child_process');
|
13 |
|
14 | const node = process.argv[0];
|
15 | const lab = process.argv[1];
|
16 | const args = [];
|
17 |
|
18 | if (process.env.NODE_DEBUG_OPTION) { // WebStorm debugger
|
19 | args.push.apply(args, process.env.NODE_DEBUG_OPTION.split(' '));
|
20 | delete process.env.NODE_DEBUG_OPTION;
|
21 | }
|
22 | else { // V8 inspector
|
23 | args.push(inspectArg);
|
24 | args.push('--debug-brk');
|
25 | }
|
26 |
|
27 | args.push(lab);
|
28 |
|
29 | // Remove node, lab, and the --inspect that might have been provided in the options
|
30 | args.push.apply(args, process.argv.slice(2).filter((argument) => !inspectPattern.test(argument)));
|
31 |
|
32 | const options = {
|
33 | stdio: 'inherit'
|
34 | };
|
35 |
|
36 | const childLab = ChildProcess.spawn(
|
37 | node,
|
38 | args,
|
39 | options
|
40 | );
|
41 |
|
42 | childLab.on('close', (code) => {
|
43 |
|
44 | process.exit(code);
|
45 | });
|
46 |
|
47 | return;
|
48 | }
|
49 |
|
50 | const main = async () => {
|
51 |
|
52 | let { code } = await require('../lib/cli').run();
|
53 | if (typeof code !== 'number') {
|
54 | code = code[Object.keys(code)[0]];
|
55 | }
|
56 | process.exit(code);
|
57 | };
|
58 |
|
59 | main();
|
60 |
|
61 |
|