Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Take --debug-port into account #26

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/_inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ const [ InspectClient, createRepl ] =

const debuglog = util.debuglog('inspect');

exports.port = 9229;
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)-port=(\d+)$/;
function getDefaultPort() {
for (const arg of process.execArgv) {
const match = arg.match(DEBUG_PORT_PATTERN);
if (match) {
return +match[1];
}
}
return 9229;
}

function runScript(script, scriptArgs, inspectPort, childPrint) {
return new Promise((resolve) => {
Expand Down Expand Up @@ -228,7 +237,7 @@ class NodeInspector {

function parseArgv([target, ...args]) {
let host = '127.0.0.1';
let port = exports.port;
let port = getDefaultPort();
let isRemote = false;
let script = target;
let scriptArgs = args;
Expand Down