UNPKG

1.28 kBPlain TextView Raw
1#!/usr/bin/env node
2
3'use strict';
4
5const inspectPattern = /^(--inspect|--inspect-brk)(=\d+)?$/;
6const inspectArg = process.argv.find((argument) => {
7
8 return inspectPattern.test(argument);
9});
10
11if (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 }
25
26 args.push(lab);
27
28 // Remove node, lab, and the --inspect that might have been provided in the options
29 args.push.apply(args, process.argv.slice(2).filter((argument) => !inspectPattern.test(argument)));
30
31 const options = {
32 stdio: 'inherit'
33 };
34
35 const childLab = ChildProcess.spawn(
36 node,
37 args,
38 options
39 );
40
41 childLab.on('close', (code) => {
42
43 process.exit(code);
44 });
45
46 process.on('SIGTERM', () => {
47
48 childLab.kill();
49 });
50
51 return;
52}
53
54const main = async () => {
55
56 let { code } = await require('../lib/cli').run();
57 process.exit(code);
58};
59
60main();
61
62