babel-node.js
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
var getV8Flags = require("v8flags");
var path = require("path");
var args = [path.join(__dirname, "_babel-node")];
var babelArgs = process.argv.slice(2);
var userArgs = void 0;
var argSeparator = babelArgs.indexOf("--");
if (argSeparator > -1) {
userArgs = babelArgs.slice(argSeparator);
babelArgs = babelArgs.slice(0, argSeparator);
}
function getNormalizedV8Flag(arg) {
var matches = arg.match(/--(.+)/);
if (matches) {
return "--" + matches[1].replace(/-/g, "_");
}
return arg;
}
getV8Flags(function (err, v8Flags) {
babelArgs.forEach(function (arg) {
var flag = arg.split("=")[0];
switch (flag) {
case "-d":
args.unshift("--debug");
break;
case "debug":
case "--debug":
case "--debug-brk":
case "--inspect":
case "--inspect-brk":
args.unshift(arg);
break;
case "-gc":
args.unshift("--expose-gc");
break;
case "--nolazy":
args.unshift(flag);
break;
default:
if (v8Flags.indexOf(getNormalizedV8Flag(flag)) >= 0 || arg.indexOf("--trace") === 0) {
args.unshift(arg);
} else {
args.push(arg);
}
break;
}
});
if (argSeparator > -1) {
args = args.concat(userArgs);
}
try {
var kexec = require("kexec");
kexec(process.argv[0], args);
} catch (err) {
if (err.code !== "MODULE_NOT_FOUND") throw err;
var child_process = require("child_process");
var proc = child_process.spawn(process.argv[0], args, { stdio: "inherit" });
proc.on("exit", function (code, signal) {
process.on("exit", function () {
if (signal) {
process.kill(process.pid, signal);
} else {
process.exit(code);
}
});
});
}
});