-
Notifications
You must be signed in to change notification settings - Fork 0
/
spawn.js
33 lines (29 loc) · 842 Bytes
/
spawn.js
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
const {spawn} = require('child_process')
const debuggerRe = /Debugger listening on ws:\/\/[^:]*:([^/]*)/
module.exports = function (execPath, args=[]) {
const info = {
port: -1
}
return new Promise((resolve, reject) => {
const proc = spawn(execPath, args, {
stdio: [process.stdin, process.stdout, 'pipe'],
env: process.env,
cwd: process.cwd()
});
proc.stderr.on('data', (outBuffer) => {
const outString = outBuffer.toString('utf8')
const match = outString.match(debuggerRe)
if (match && !info.url) {
info.port = Number(match[1])
return resolve(info)
} else {
console.error(outString)
}
})
proc.on('close', (code) => {
if (info.port === -1) {
return reject(Error('could not connect to inspector'))
}
})
})
}