-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: switch to stderr and default port (#7)
- Loading branch information
Showing
3 changed files
with
39 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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')) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters