-
-
Notifications
You must be signed in to change notification settings - Fork 533
/
bin.ts
69 lines (60 loc) · 1.48 KB
/
bin.ts
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
#!/usr/bin/env node
import { spawn } from 'child_process'
import { join } from 'path'
import v8flags = require('v8flags')
const argv = process.argv.slice(2)
v8flags(function (err, v8flags) {
if (err) {
console.error(err.stack)
process.exit(1)
return
}
const nodeArgs: string[] = []
const scriptArgs: string[] = []
const knownFlags = v8flags.concat([
'debug',
'--debug',
'--debug-brk',
'--inspect',
'--inspect-brk',
'--nolazy',
'--no-deprecation',
'--log-timer-events',
'--throw-deprecation',
'--trace-deprecation',
'--allow-natives-syntax',
'--perf-basic-prof',
'--preserve-symlinks'
])
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]
const flag = arg.split('=', 1)[0]
if (flag === '-d') {
nodeArgs.push('--debug')
} else if (flag === '-gc') {
nodeArgs.push('--expose-gc')
} else if (knownFlags.indexOf(flag) > -1) {
nodeArgs.push(arg)
} else if (/^-/.test(flag)) {
scriptArgs.push(arg)
} else {
// Break when we encounter a "script".
scriptArgs.push(...argv.slice(i))
break
}
}
const proc = spawn(
process.execPath,
nodeArgs.concat(join(__dirname, '_bin.js'), scriptArgs),
{ stdio: 'inherit' }
)
proc.on('exit', function (code: number, signal: string) {
process.on('exit', function () {
if (signal) {
process.kill(process.pid, signal)
} else {
process.exit(code)
}
})
})
})