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

Commit 054d4b1

Browse files
author
Jan Krems
committed
fix: Take --debug-port into account
1 parent 37cc9b7 commit 054d4b1

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/_inspect.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ const [ InspectClient, createRepl ] =
4141

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

44-
exports.port = 9229;
44+
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)-port=(\d+)$/;
45+
function getDefaultPort() {
46+
for (const arg of process.execArgv) {
47+
const match = arg.match(DEBUG_PORT_PATTERN);
48+
if (match) {
49+
return +match[1];
50+
}
51+
}
52+
return 9229;
53+
}
4554

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

229238
function parseArgv([target, ...args]) {
230239
let host = '127.0.0.1';
231-
let port = exports.port;
240+
let port = getDefaultPort();
232241
let isRemote = false;
233242
let script = target;
234243
let scriptArgs = args;

0 commit comments

Comments
 (0)