Skip to content

Commit f4ccb9d

Browse files
Jan KremsMylesBorins
Jan Krems
authored andcommitted
deps: update node-inspect to 1.11.3
Highlights: * Using a random port works (`node inspect --port=0 script.js`) * `takeHeapSnapshot()` creates valid snapshots again PR-URL: #18354 Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent 9f158ac commit f4ccb9d

10 files changed

+118
-40
lines changed

deps/node-inspect/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 1.11.3
2+
3+
* [`93caa0f`](https://github.com/nodejs/node-inspect/commit/93caa0f5267c7ab452b258d3b03329a0bb5ac7f7) **docs:** Add missing oc in protocol
4+
* [`2d87cbe`](https://github.com/nodejs/node-inspect/commit/2d87cbe76aa968dfc1ac69d9571af1be81abd8e0) **fix:** Make --inspect-port=0 work
5+
* [`ebfd02e`](https://github.com/nodejs/node-inspect/commit/ebfd02ece9b642586023f7791da71defeb13d746) **chore:** Bump tap to 10.7
6+
* [`c07adb1`](https://github.com/nodejs/node-inspect/commit/c07adb17b164c1cf3da8d38659ea9f5d7ff42e9c) **test:** Use useful break location
7+
* [`94f0bf9`](https://github.com/nodejs/node-inspect/commit/94f0bf97d24c376baf3ecced2088d81715a73464) **fix:** Fix `takeHeapSnapshot()` truncation bug
8+
9+
110
### 1.11.2
211

312
* [`42e0cd1`](https://github.com/nodejs/node-inspect/commit/42e0cd111d89ed09faba1c0ec45089b0b44de011) **fix:** look for generic hint text

deps/node-inspect/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ node has two options:
1010
1. `node --debug <file>`: Start `file` with remote debugging enabled.
1111
2. `node debug <file>`: Start an interactive CLI debugger for `<file>`.
1212

13-
But for the Chrome inspector protol,
13+
But for the Chrome inspector protocol,
1414
there's only one: `node --inspect <file>`.
1515

1616
This project tries to provide the missing second option

deps/node-inspect/lib/_inspect.js

+12-19
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,9 @@ const [ InspectClient, createRepl ] =
4242

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

45-
const DEBUG_PORT_PATTERN = /^--(?:debug|inspect)(?:-port|-brk)?=(\d{1,5})$/;
46-
function getDefaultPort() {
47-
for (const arg of process.execArgv) {
48-
const match = arg.match(DEBUG_PORT_PATTERN);
49-
if (match) {
50-
return +match[1];
51-
}
52-
}
53-
return 9229;
54-
}
55-
5645
function portIsFree(host, port, timeout = 2000) {
46+
if (port === 0) return Promise.resolve(); // Binding to a random port.
47+
5748
const retryDelay = 150;
5849
let didTimeOut = false;
5950

@@ -110,9 +101,11 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) {
110101
let output = '';
111102
function waitForListenHint(text) {
112103
output += text;
113-
if (/Debugger listening on/.test(output)) {
104+
if (/Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//.test(output)) {
105+
const host = RegExp.$1;
106+
const port = Number.parseInt(RegExp.$2);
114107
child.stderr.removeListener('data', waitForListenHint);
115-
resolve(child);
108+
resolve([child, port, host]);
116109
}
117110
}
118111

@@ -160,10 +153,11 @@ class NodeInspector {
160153
options.port,
161154
this.childPrint.bind(this));
162155
} else {
163-
this._runScript = () => Promise.resolve(null);
156+
this._runScript =
157+
() => Promise.resolve([null, options.port, options.host]);
164158
}
165159

166-
this.client = new InspectClient(options.port, options.host);
160+
this.client = new InspectClient();
167161

168162
this.domainNames = ['Debugger', 'HeapProfiler', 'Profiler', 'Runtime'];
169163
this.domainNames.forEach((domain) => {
@@ -223,17 +217,16 @@ class NodeInspector {
223217

224218
run() {
225219
this.killChild();
226-
const { host, port } = this.options;
227220

228-
return this._runScript().then((child) => {
221+
return this._runScript().then(([child, port, host]) => {
229222
this.child = child;
230223

231224
let connectionAttempts = 0;
232225
const attemptConnect = () => {
233226
++connectionAttempts;
234227
debuglog('connection attempt #%d', connectionAttempts);
235228
this.stdout.write('.');
236-
return this.client.connect()
229+
return this.client.connect(port, host)
237230
.then(() => {
238231
debuglog('connection established');
239232
this.stdout.write(' ok');
@@ -288,7 +281,7 @@ class NodeInspector {
288281

289282
function parseArgv([target, ...args]) {
290283
let host = '127.0.0.1';
291-
let port = getDefaultPort();
284+
let port = 9229;
292285
let isRemote = false;
293286
let script = target;
294287
let scriptArgs = args;

deps/node-inspect/lib/internal/inspect_client.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ function decodeFrameHybi17(data) {
164164
}
165165

166166
class Client extends EventEmitter {
167-
constructor(port, host) {
167+
constructor() {
168168
super();
169169
this.handleChunk = this._handleChunk.bind(this);
170170

171-
this._port = port;
172-
this._host = host;
171+
this._port = undefined;
172+
this._host = undefined;
173173

174174
this.reset();
175175
}
@@ -284,7 +284,9 @@ class Client extends EventEmitter {
284284
});
285285
}
286286

287-
connect() {
287+
connect(port, host) {
288+
this._port = port;
289+
this._host = host;
288290
return this._discoverWebsocketPath()
289291
.then((urlPath) => this._connectWebsocket(urlPath));
290292
}

deps/node-inspect/lib/internal/inspect_repl.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,8 @@ function createRepl(inspector) {
900900
return new Promise((resolve, reject) => {
901901
const absoluteFile = Path.resolve(filename);
902902
const writer = FS.createWriteStream(absoluteFile);
903-
let totalSize;
904903
let sizeWritten = 0;
905904
function onProgress({ done, total, finished }) {
906-
totalSize = total;
907905
if (finished) {
908906
print('Heap snaphost prepared.');
909907
} else {
@@ -913,13 +911,18 @@ function createRepl(inspector) {
913911
function onChunk({ chunk }) {
914912
sizeWritten += chunk.length;
915913
writer.write(chunk);
916-
print(`Writing snapshot: ${sizeWritten}/${totalSize}`, true);
917-
if (sizeWritten >= totalSize) {
918-
writer.end();
914+
print(`Writing snapshot: ${sizeWritten}`, true);
915+
}
916+
function onResolve() {
917+
writer.end(() => {
919918
teardown();
920919
print(`Wrote snapshot: ${absoluteFile}`);
921920
resolve();
922-
}
921+
});
922+
}
923+
function onReject(error) {
924+
teardown();
925+
reject(error);
923926
}
924927
function teardown() {
925928
HeapProfiler.removeListener(
@@ -932,10 +935,7 @@ function createRepl(inspector) {
932935

933936
print('Heap snapshot: 0/0', true);
934937
HeapProfiler.takeHeapSnapshot({ reportProgress: true })
935-
.then(null, (error) => {
936-
teardown();
937-
reject(error);
938-
});
938+
.then(onResolve, onReject);
939939
});
940940
},
941941

deps/node-inspect/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-inspect",
3-
"version": "1.11.2",
3+
"version": "1.11.3",
44
"description": "Node Inspect",
55
"license": "MIT",
66
"main": "lib/_inspect.js",
@@ -29,7 +29,7 @@
2929
"devDependencies": {
3030
"eslint": "^3.10.2",
3131
"nlm": "^3.0.0",
32-
"tap": "^7.1.2"
32+
"tap": "^10.7.0"
3333
},
3434
"author": {
3535
"name": "Jan Krems",

deps/node-inspect/test/cli/break.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ test('sb before loading file', (t) => {
134134

135135
return cli.waitForInitialBreak()
136136
.then(() => cli.waitForPrompt())
137-
.then(() => cli.command('sb("other.js", 3)'))
137+
.then(() => cli.command('sb("other.js", 2)'))
138138
.then(() => {
139139
t.match(
140140
cli.output,
@@ -145,7 +145,7 @@ test('sb before loading file', (t) => {
145145
.then(() => {
146146
t.match(
147147
cli.output,
148-
`break in ${otherScript}:3`,
148+
`break in ${otherScript}:2`,
149149
'found breakpoint in file that was not loaded yet');
150150
})
151151
.then(() => cli.quit())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
const { test } = require('tap');
3+
const { readFileSync, unlinkSync } = require('fs');
4+
5+
const startCLI = require('./start-cli');
6+
const filename = 'node.heapsnapshot';
7+
8+
function cleanup() {
9+
try {
10+
unlinkSync(filename);
11+
} catch (_) {
12+
// Ignore.
13+
}
14+
}
15+
16+
cleanup();
17+
18+
test('Heap profiler take snapshot', (t) => {
19+
const cli = startCLI(['examples/empty.js']);
20+
21+
function onFatal(error) {
22+
cli.quit();
23+
throw error;
24+
}
25+
26+
// Check that the snapshot is valid JSON.
27+
return cli.waitForInitialBreak()
28+
.then(() => cli.waitForPrompt())
29+
.then(() => cli.command('takeHeapSnapshot()'))
30+
.then(() => JSON.parse(readFileSync(filename, 'utf8')))
31+
.then(() => cleanup())
32+
.then(() => cli.quit())
33+
.then(null, onFatal);
34+
});

deps/node-inspect/test/cli/launch.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,46 @@ test('custom port', (t) => {
2626
});
2727
});
2828

29+
test('random port', (t) => {
30+
const script = Path.join('examples', 'three-lines.js');
31+
32+
const cli = startCLI(['--port=0', script]);
33+
34+
return cli.waitForInitialBreak()
35+
.then(() => cli.waitForPrompt())
36+
.then(() => {
37+
t.match(cli.output, 'debug>', 'prints a prompt');
38+
t.match(
39+
cli.output,
40+
/< Debugger listening on /,
41+
'forwards child output');
42+
})
43+
.then(() => cli.quit())
44+
.then((code) => {
45+
t.equal(code, 0, 'exits with success');
46+
});
47+
});
48+
49+
test('random port with --inspect-port=0', (t) => {
50+
const script = Path.join('examples', 'three-lines.js');
51+
52+
const cli = startCLI([script], ['--inspect-port=0']);
53+
54+
return cli.waitForInitialBreak()
55+
.then(() => cli.waitForPrompt())
56+
.then(() => {
57+
t.match(cli.output, 'debug>', 'prints a prompt');
58+
t.match(
59+
cli.output,
60+
/< Debugger listening on /,
61+
'forwards child output');
62+
})
63+
.then(() => cli.quit())
64+
.then((code) => {
65+
t.equal(code, 0, 'exits with success');
66+
});
67+
});
68+
2969
test('examples/three-lines.js', (t) => {
3070
const script = Path.join('examples', 'three-lines.js');
3171
const cli = startCLI([script]);

deps/node-inspect/test/cli/start-cli.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const BREAK_MESSAGE = new RegExp('(?:' + [
1616
'exception', 'other', 'promiseRejection',
1717
].join('|') + ') in', 'i');
1818

19-
function startCLI(args) {
20-
const child = spawn(process.execPath, [CLI, ...args]);
19+
function startCLI(args, flags = []) {
20+
const child = spawn(process.execPath, [...flags, CLI, ...args]);
2121
let isFirstStdoutChunk = true;
2222

2323
const outputBuffer = [];

0 commit comments

Comments
 (0)