Skip to content

Commit 8803d7e

Browse files
jkremscodebytere
authored andcommitted
deps: update node-inspect to v2.0.0
Highlights: * Remove use of `process.binding` on modern node (@addaleax) * Increase timeout for port checking (@yilmazdurmaz) * Auto-resume on start when `NODE_INSPECT_RESUME_ON_START` is set (@dolsem) Compare: nodejs/node-inspect@v1.11.6...v2.0.0 PR-URL: #33447 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent e3533ab commit 8803d7e

File tree

8 files changed

+166
-29
lines changed

8 files changed

+166
-29
lines changed
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Node CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
node-version:
14+
# See https://github.com/nodejs/node-inspect/pull/78
15+
# - 10.x
16+
- 12.x
17+
- 13.x
18+
19+
steps:
20+
- uses: actions/checkout@v2
21+
- name: Use Node.js ${{ matrix.node-version }}
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: ${{ matrix.node-version }}
25+
- name: npm install, build, and test
26+
run: |
27+
npm install
28+
npm run build --if-present
29+
npm test
30+
env:
31+
CI: true

deps/node-inspect/lib/_inspect.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ const runAsStandalone = typeof __dirname !== 'undefined';
3030
const [ InspectClient, createRepl ] =
3131
runAsStandalone ?
3232
// This copy of node-inspect is on-disk, relative paths make sense.
33-
[
34-
require('./internal/inspect_client'),
35-
require('./internal/inspect_repl')
36-
] :
33+
[
34+
require('./internal/inspect_client'),
35+
require('./internal/inspect_repl')
36+
] :
3737
// This copy of node-inspect is built into the node executable.
38-
[
39-
require('node-inspect/lib/internal/inspect_client'),
40-
require('node-inspect/lib/internal/inspect_repl')
41-
];
38+
[
39+
require('node-inspect/lib/internal/inspect_client'),
40+
require('node-inspect/lib/internal/inspect_repl')
41+
];
4242

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

@@ -49,8 +49,8 @@ class StartupError extends Error {
4949
}
5050
}
5151

52-
function portIsFree(host, port, timeout = 2000) {
53-
if (port === 0) return Promise.resolve(); // Binding to a random port.
52+
function portIsFree(host, port, timeout = 9999) {
53+
if (port === 0) return Promise.resolve(); // Binding to a random port.
5454

5555
const retryDelay = 150;
5656
let didTimeOut = false;
@@ -96,9 +96,9 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) {
9696
return new Promise((resolve) => {
9797
const needDebugBrk = process.version.match(/^v(6|7)\./);
9898
const args = (needDebugBrk ?
99-
['--inspect', `--debug-brk=${inspectPort}`] :
100-
[`--inspect-brk=${inspectPort}`])
101-
.concat([script], scriptArgs);
99+
['--inspect', `--debug-brk=${inspectPort}`] :
100+
[`--inspect-brk=${inspectPort}`])
101+
.concat([script], scriptArgs);
102102
const child = spawn(process.execPath, args);
103103
child.stdout.setEncoding('utf8');
104104
child.stderr.setEncoding('utf8');
@@ -154,11 +154,11 @@ class NodeInspector {
154154

155155
if (options.script) {
156156
this._runScript = runScript.bind(null,
157-
options.script,
158-
options.scriptArgs,
159-
options.host,
160-
options.port,
161-
this.childPrint.bind(this));
157+
options.script,
158+
options.scriptArgs,
159+
options.host,
160+
options.port,
161+
this.childPrint.bind(this));
162162
} else {
163163
this._runScript =
164164
() => Promise.resolve([null, options.port, options.host]);
@@ -333,8 +333,8 @@ function parseArgv([target, ...args]) {
333333
}
334334

335335
function startInspect(argv = process.argv.slice(2),
336-
stdin = process.stdin,
337-
stdout = process.stdout) {
336+
stdin = process.stdin,
337+
stdout = process.stdout) {
338338
/* eslint-disable no-console */
339339
if (argv.length < 1) {
340340
const invokedAs = runAsStandalone ?

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,16 @@ function extractFunctionName(description) {
8585
return fnNameMatch ? `: ${fnNameMatch[1]}` : '';
8686
}
8787

88-
const NATIVES = process.binding('natives');
88+
const PUBLIC_BUILTINS = require('module').builtinModules;
89+
const NATIVES = PUBLIC_BUILTINS ? process.binding('natives') : {};
8990
function isNativeUrl(url) {
90-
return url.replace('.js', '') in NATIVES || url === 'bootstrap_node.js';
91+
url = url.replace(/\.js$/, '');
92+
if (PUBLIC_BUILTINS) {
93+
if (url.startsWith('internal/') || PUBLIC_BUILTINS.includes(url))
94+
return true;
95+
}
96+
97+
return url in NATIVES || url === 'bootstrap_node';
9198
}
9299

93100
function getRelativePath(filenameOrURL) {
@@ -775,6 +782,14 @@ function createRepl(inspector) {
775782
}
776783

777784
Debugger.on('paused', ({ callFrames, reason /* , hitBreakpoints */ }) => {
785+
if (process.env.NODE_INSPECT_RESUME_ON_START === '1' &&
786+
reason === 'Break on start') {
787+
debuglog('Paused on start, but NODE_INSPECT_RESUME_ON_START' +
788+
' environment variable is set to 1, resuming');
789+
inspector.client.callMethod('Debugger.resume');
790+
return;
791+
}
792+
778793
// Save execution context's data
779794
currentBacktrace = Backtrace.from(callFrames);
780795
selectedFrame = currentBacktrace[0];

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.6",
3+
"version": "2.0.0",
44
"description": "Node Inspect",
55
"license": "MIT",
66
"main": "lib/_inspect.js",
@@ -27,7 +27,7 @@
2727
},
2828
"dependencies": {},
2929
"devDependencies": {
30-
"eslint": "^3.10.2",
30+
"eslint": "^6.8.0",
3131
"nlm": "^3.0.0",
3232
"tap": "^10.7.0"
3333
},
+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use strict';
2+
const { spawn } = require('child_process');
3+
const Path = require('path');
4+
const { test } = require('tap');
5+
6+
const startCLI = require('./start-cli');
7+
8+
// NOTE(oyyd): We might want to import this regexp from "lib/_inspect.js"?
9+
const kDebuggerMsgReg = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//;
10+
11+
function launchTarget(...args) {
12+
const childProc = spawn(process.execPath, args);
13+
return new Promise((resolve, reject) => {
14+
const onExit = () => {
15+
reject(new Error('Child process exits unexpectly'));
16+
};
17+
childProc.on('exit', onExit);
18+
childProc.stderr.setEncoding('utf8');
19+
childProc.stderr.on('data', (data) => {
20+
const ret = kDebuggerMsgReg.exec(data);
21+
childProc.removeListener('exit', onExit);
22+
if (ret) {
23+
resolve({
24+
childProc,
25+
host: ret[1],
26+
port: ret[2],
27+
});
28+
}
29+
});
30+
});
31+
}
32+
33+
// process.debugPort is our proxy for "the version of node used to run this
34+
// test suite doesn't support SIGUSR1 for enabling --inspect for a process".
35+
const defaultsToOldProtocol = process.debugPort === 5858;
36+
37+
test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => {
38+
const script = Path.join('examples', 'alive.js');
39+
let cli = null;
40+
let target = null;
41+
42+
function cleanup(error) {
43+
if (cli) {
44+
cli.quit();
45+
cli = null;
46+
}
47+
if (target) {
48+
target.kill();
49+
target = null;
50+
}
51+
if (error) throw error;
52+
}
53+
54+
return launchTarget('--inspect=0', script)
55+
.then(({ childProc, host, port }) => {
56+
target = childProc;
57+
cli = startCLI([`${host || '127.0.0.1'}:${port}`]);
58+
return cli.waitForPrompt();
59+
})
60+
.then(() => cli.command('sb("alive.js", 3)'))
61+
.then(() => cli.waitFor(/break/))
62+
.then(() => cli.waitForPrompt())
63+
.then(() => {
64+
t.match(
65+
cli.output,
66+
'> 3 ++x;',
67+
'marks the 3rd line');
68+
})
69+
.then(() => cleanup())
70+
.then(null, cleanup);
71+
});

deps/node-inspect/test/cli/invalid-args.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test('launch w/ invalid host:port', (t) => {
2727
});
2828
});
2929

30-
test('launch w/ unavailable port', async (t) => {
30+
test('launch w/ unavailable port', async(t) => {
3131
const blocker = createServer((socket) => socket.end());
3232
const port = await new Promise((resolve, reject) => {
3333
blocker.on('error', reject);

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

+20
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,23 @@ test('run after quit / restart', (t) => {
174174
.then(() => cli.quit())
175175
.then(null, onFatal);
176176
});
177+
178+
test('auto-resume on start if the environment variable is defined', (t) => {
179+
const script = Path.join('examples', 'break.js');
180+
181+
const cli = startCLI([script], [], {
182+
env: { NODE_INSPECT_RESUME_ON_START: '1' }
183+
});
184+
185+
return cli.waitForInitialBreak()
186+
.then(() => {
187+
t.match(
188+
cli.breakInfo,
189+
{ filename: script, line: 10 },
190+
'skips to the first breakpoint');
191+
})
192+
.then(() => cli.quit())
193+
.then((code) => {
194+
t.equal(code, 0, 'exits with success');
195+
});
196+
});

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ tap.test('startCLI', (t) => t.end());
88

99
const CLI =
1010
process.env.USE_EMBEDDED_NODE_INSPECT === '1' ?
11-
'inspect' :
12-
require.resolve('../../cli.js');
11+
'inspect' :
12+
require.resolve('../../cli.js');
1313

1414
const BREAK_MESSAGE = new RegExp('(?:' + [
1515
'assert', 'break', 'break on start', 'debugCommand',
@@ -20,8 +20,8 @@ function isPreBreak(output) {
2020
return /Break on start/.test(output) && /1 \(function \(exports/.test(output);
2121
}
2222

23-
function startCLI(args, flags = []) {
24-
const child = spawn(process.execPath, [...flags, CLI, ...args]);
23+
function startCLI(args, flags = [], spawnOpts = {}) {
24+
const child = spawn(process.execPath, [...flags, CLI, ...args], spawnOpts);
2525
let isFirstStdoutChunk = true;
2626

2727
const outputBuffer = [];

0 commit comments

Comments
 (0)