From 5c1d7716523b73e26f98f4f594ee34b7daa920a0 Mon Sep 17 00:00:00 2001 From: oyyd Date: Mon, 13 May 2019 16:52:28 +0800 Subject: [PATCH 1/3] fix: replace the deprecated "repl.cli" with "repl" "REPLServer.rli" is deprecated and it's the reference of the instance. So that we can replace the "repl.cli" with "repl" to remove the deprecation warning in Node.js 12. Refs: https://github.com/nodejs/node/pull/26260 --- lib/_inspect.js | 4 ++-- lib/internal/inspect_repl.js | 24 ++++++++++++------------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/_inspect.js b/lib/_inspect.js index 305e499..4d931f7 100644 --- a/lib/_inspect.js +++ b/lib/_inspect.js @@ -198,7 +198,7 @@ class NodeInspector { suspendReplWhile(fn) { if (this.repl) { - this.repl.rli.pause(); + this.repl.pause(); } this.stdin.pause(); this.paused = true; @@ -207,7 +207,7 @@ class NodeInspector { }).then(() => { this.paused = false; if (this.repl) { - this.repl.rli.resume(); + this.repl.resume(); this.repl.displayPrompt(); } this.stdin.resume(); diff --git a/lib/internal/inspect_repl.js b/lib/internal/inspect_repl.js index 38fe468..985df0d 100644 --- a/lib/internal/inspect_repl.js +++ b/lib/internal/inspect_repl.js @@ -958,8 +958,8 @@ function createRepl(inspector) { get repl() { // Don't display any default messages - const listeners = repl.rli.listeners('SIGINT').slice(0); - repl.rli.removeAllListeners('SIGINT'); + const listeners = repl.listeners('SIGINT').slice(0); + repl.removeAllListeners('SIGINT'); const oldContext = repl.context; @@ -967,7 +967,7 @@ function createRepl(inspector) { // Restore all listeners process.nextTick(() => { listeners.forEach((listener) => { - repl.rli.on('SIGINT', listener); + repl.on('SIGINT', listener); }); }); @@ -975,21 +975,21 @@ function createRepl(inspector) { repl.eval = controlEval; // Swap history - history.debug = repl.rli.history; - repl.rli.history = history.control; + history.debug = repl.history; + repl.history = history.control; repl.context = oldContext; - repl.rli.setPrompt('debug> '); + repl.setPrompt('debug> '); repl.displayPrompt(); - repl.rli.removeListener('SIGINT', exitDebugRepl); + repl.removeListener('SIGINT', exitDebugRepl); repl.removeListener('exit', exitDebugRepl); exitDebugRepl = null; }; // Exit debug repl on SIGINT - repl.rli.on('SIGINT', exitDebugRepl); + repl.on('SIGINT', exitDebugRepl); // Exit debug repl on repl exit repl.on('exit', exitDebugRepl); @@ -999,10 +999,10 @@ function createRepl(inspector) { repl.context = {}; // Swap history - history.control = repl.rli.history; - repl.rli.history = history.debug; + history.control = repl.history; + repl.history = history.debug; - repl.rli.setPrompt('> '); + repl.setPrompt('> '); print('Press Ctrl + C to leave debug repl'); repl.displayPrompt(); @@ -1077,7 +1077,7 @@ function createRepl(inspector) { repl.defineCommand('interrupt', () => { // We want this for testing purposes where sending CTRL-C can be tricky. - repl.rli.emit('SIGINT'); + repl.emit('SIGINT'); }); // Init once for the initial connection From 5b3511ef21d0eba8304d8b2fed33f33aae22f308 Mon Sep 17 00:00:00 2001 From: Jan Krems Date: Thu, 16 May 2019 12:39:45 -0700 Subject: [PATCH 2/3] fix: Address regressions due to changes in node --- lib/internal/inspect_repl.js | 6 +++++- test/cli/break.test.js | 6 +++--- test/cli/exceptions.test.js | 8 ++++---- test/cli/launch.test.js | 16 ++++++++-------- test/cli/low-level.test.js | 2 +- test/cli/preserve-breaks.test.js | 8 ++++---- test/cli/scripts.test.js | 4 ++-- test/cli/start-cli.js | 31 ++++++++++++++++++++++++++----- test/cli/use-strict.test.js | 5 +++-- 9 files changed, 56 insertions(+), 30 deletions(-) diff --git a/lib/internal/inspect_repl.js b/lib/internal/inspect_repl.js index 985df0d..d9d3f89 100644 --- a/lib/internal/inspect_repl.js +++ b/lib/internal/inspect_repl.js @@ -25,6 +25,7 @@ const Path = require('path'); const Repl = require('repl'); const util = require('util'); const vm = require('vm'); +const fileURLToPath = require('url').fileURLToPath; const debuglog = util.debuglog('inspect'); @@ -89,9 +90,12 @@ function isNativeUrl(url) { return url.replace('.js', '') in NATIVES || url === 'bootstrap_node.js'; } -function getRelativePath(filename) { +function getRelativePath(filenameOrURL) { const dir = Path.join(Path.resolve(), 'x').slice(0, -1); + const filename = filenameOrURL.startsWith('file://') ? + fileURLToPath(filenameOrURL) : filenameOrURL; + // Change path to relative, if possible if (filename.indexOf(dir) === 0) { return filename.slice(dir.length); diff --git a/test/cli/break.test.js b/test/cli/break.test.js index ce8c8d6..ff71a36 100644 --- a/test/cli/break.test.js +++ b/test/cli/break.test.js @@ -18,12 +18,12 @@ test('stepping through breakpoints', (t) => { .then(() => cli.waitForPrompt()) .then(() => { t.match( - cli.output, - `break in ${script}:1`, + cli.breakInfo, + { filename: script, line: 1 }, 'pauses in the first line of the script'); t.match( cli.output, - /> 1 \(function \([^)]+\) \{ const x = 10;/, + /> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/, 'shows the source and marks the current line'); }) .then(() => cli.stepCommand('n')) diff --git a/test/cli/exceptions.test.js b/test/cli/exceptions.test.js index 18b7f18..69d42d0 100644 --- a/test/cli/exceptions.test.js +++ b/test/cli/exceptions.test.js @@ -17,7 +17,7 @@ test('break on (uncaught) exceptions', (t) => { return cli.waitForInitialBreak() .then(() => cli.waitForPrompt()) .then(() => { - t.match(cli.output, `break in ${script}:1`); + t.match(cli.breakInfo, { filename: script, line: 1 }); }) // making sure it will die by default: .then(() => cli.command('c')) @@ -28,7 +28,7 @@ test('break on (uncaught) exceptions', (t) => { .then(() => cli.stepCommand('r')) .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.output, `break in ${script}:1`); + t.match(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.command('breakOnException')) .then(() => cli.stepCommand('c')) @@ -45,7 +45,7 @@ test('break on (uncaught) exceptions', (t) => { .then(() => cli.stepCommand('r')) // also, the setting survives the restart .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.output, `break in ${script}:1`); + t.match(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.stepCommand('c')) .then(() => { @@ -57,7 +57,7 @@ test('break on (uncaught) exceptions', (t) => { .then(() => cli.stepCommand('r')) .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.output, `break in ${script}:1`); + t.match(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.command('c')) // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore diff --git a/test/cli/launch.test.js b/test/cli/launch.test.js index 8808d47..087a46c 100644 --- a/test/cli/launch.test.js +++ b/test/cli/launch.test.js @@ -137,23 +137,23 @@ test('run after quit / restart', (t) => { .then(() => cli.waitForPrompt()) .then(() => { t.match( - cli.output, - `break in ${script}:1`, + cli.breakInfo, + { filename: script, line: 1 }, 'is back at the beginning'); }) .then(() => cli.stepCommand('n')) .then(() => { t.match( - cli.output, - `break in ${script}:2`, + cli.breakInfo, + { filename: script, line: 2 }, 'steps to the 2nd line'); }) .then(() => cli.stepCommand('restart')) .then(() => cli.waitForInitialBreak()) .then(() => { t.match( - cli.output, - `break in ${script}:1`, + cli.breakInfo, + { filename: script, line: 1 }, 'is back at the beginning'); }) .then(() => cli.command('kill')) @@ -167,8 +167,8 @@ test('run after quit / restart', (t) => { .then(() => cli.waitForPrompt()) .then(() => { t.match( - cli.output, - `break in ${script}:1`, + cli.breakInfo, + { filename: script, line: 1 }, 'is back at the beginning'); }) .then(() => cli.quit()) diff --git a/test/cli/low-level.test.js b/test/cli/low-level.test.js index 77e3fc2..2a41359 100644 --- a/test/cli/low-level.test.js +++ b/test/cli/low-level.test.js @@ -24,7 +24,7 @@ test('Debugger agent direct access', (t) => { .then(() => { t.match( cli.output, - /scriptSource: '\(function \(/); + /scriptSource:[ \n]*'(?:\(function \(|let x = 1)/); t.match( cli.output, /let x = 1;/); diff --git a/test/cli/preserve-breaks.test.js b/test/cli/preserve-breaks.test.js index 94f6140..affa3ad 100644 --- a/test/cli/preserve-breaks.test.js +++ b/test/cli/preserve-breaks.test.js @@ -30,20 +30,20 @@ test('run after quit / restart', (t) => { .then(() => cli.stepCommand('c')) // hit line 2 .then(() => cli.stepCommand('c')) // hit line 3 .then(() => { - t.match(cli.output, `break in ${script}:3`); + t.match(cli.breakInfo, { filename: script, line: 3 }); }) .then(() => cli.command('restart')) .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.output, `break in ${script}:1`); + t.match(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.stepCommand('c')) .then(() => { - t.match(cli.output, `break in ${script}:2`); + t.match(cli.breakInfo, { filename: script, line: 2 }); }) .then(() => cli.stepCommand('c')) .then(() => { - t.match(cli.output, `break in ${script}:3`); + t.match(cli.breakInfo, { filename: script, line: 3 }); }) .then(() => cli.command('breakpoints')) .then(() => { diff --git a/test/cli/scripts.test.js b/test/cli/scripts.test.js index 1546b80..f6e3f30 100644 --- a/test/cli/scripts.test.js +++ b/test/cli/scripts.test.js @@ -24,7 +24,7 @@ test('list scripts', (t) => { 'lists the user script'); t.notMatch( cli.output, - /\d+: module\.js /, + /\d+: buffer\.js /, 'omits node-internal scripts'); }) .then(() => cli.command('scripts(true)')) @@ -35,7 +35,7 @@ test('list scripts', (t) => { 'lists the user script'); t.match( cli.output, - /\d+: module\.js /, + /\d+: buffer\.js /, 'includes node-internal scripts'); }) .then(() => cli.quit()) diff --git a/test/cli/start-cli.js b/test/cli/start-cli.js index b086dcd..e2fa5fe 100644 --- a/test/cli/start-cli.js +++ b/test/cli/start-cli.js @@ -16,6 +16,10 @@ const BREAK_MESSAGE = new RegExp('(?:' + [ 'exception', 'other', 'promiseRejection', ].join('|') + ') in', 'i'); +function isPreBreak(output) { + return /Break on start/.test(output) && /1 \(function \(exports/.test(output); +} + function startCLI(args, flags = []) { const child = spawn(process.execPath, [...flags, CLI, ...args]); let isFirstStdoutChunk = true; @@ -101,13 +105,25 @@ function startCLI(args, flags = []) { waitForInitialBreak(timeout = 2000) { return this.waitFor(/break (?:on start )?in/i, timeout) .then(() => { - if (/Break on start/.test(this.output)) { + if (isPreBreak(this.output)) { return this.command('next', false) .then(() => this.waitFor(/break in/, timeout)); } }); }, + get breakInfo() { + const output = this.output; + const breakMatch = + output.match(/break (?:on start )?in ([^\n]+):(\d+)\n/i); + + if (breakMatch === null) { + throw new Error( + `Could not find breakpoint info in ${JSON.stringify(output)}`); + } + return { filename: breakMatch[1], line: +breakMatch[2] }; + }, + ctrlC() { return this.command('.interrupt'); }, @@ -127,19 +143,24 @@ function startCLI(args, flags = []) { .map((match) => +match[1]); }, - command(input, flush = true) { + writeLine(input, flush = true) { if (flush) { this.flushOutput(); } + if (process.env.VERBOSE === '1') { + process.stderr.write(`< ${input}\n`); + } child.stdin.write(input); child.stdin.write('\n'); + }, + + command(input, flush = true) { + this.writeLine(input, flush); return this.waitForPrompt(); }, stepCommand(input) { - this.flushOutput(); - child.stdin.write(input); - child.stdin.write('\n'); + this.writeLine(input, true); return this .waitFor(BREAK_MESSAGE) .then(() => this.waitForPrompt()); diff --git a/test/cli/use-strict.test.js b/test/cli/use-strict.test.js index 780802a..c6dc8f3 100644 --- a/test/cli/use-strict.test.js +++ b/test/cli/use-strict.test.js @@ -17,9 +17,10 @@ test('for whiles that starts with strict directive', (t) => { return cli.waitForInitialBreak() .then(() => cli.waitForPrompt()) .then(() => { + const brk = cli.breakInfo; t.match( - cli.output, - /break in [^:]+:(?:1|2)[^\d]/, + `${brk.line}`, + /^(1|2)$/, 'pauses either on strict directive or first "real" line'); }) .then(() => cli.quit()) From 680e73839e42e3559132c5fce57948b6c1890780 Mon Sep 17 00:00:00 2001 From: nlm Date: Mon, 3 Jun 2019 09:59:27 +0200 Subject: [PATCH 3/3] v1.11.6 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44ae510..73aeb4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### 1.11.6 + +* fix: replace the deprecated "repl.cli" with "repl" - **[@oyyd](https://github.com/oyyd)** [#66](https://github.com/nodejs/node-inspect/pull/66) + - [`5c1d771`](https://github.com/nodejs/node-inspect/commit/5c1d7716523b73e26f98f4f594ee34b7daa920a0) **fix:** replace the deprecated "repl.cli" with "repl" - see: [26260](Refs: https://github.com/nodejs/node/pull/26260) +* Address regressions due to changes in node - **[@jkrems](https://github.com/jkrems)** [#67](https://github.com/nodejs/node-inspect/pull/67) + - [`5b3511e`](https://github.com/nodejs/node-inspect/commit/5b3511ef21d0eba8304d8b2fed33f33aae22f308) **fix:** Address regressions due to changes in node + + ### 1.11.5 * Fix eslint issues - **[@jkrems](https://github.com/jkrems)** [#63](https://github.com/nodejs/node-inspect/pull/63) diff --git a/package.json b/package.json index eddc14d..c645827 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-inspect", - "version": "1.11.5", + "version": "1.11.6", "description": "Node Inspect", "license": "MIT", "main": "lib/_inspect.js",