| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 464df6d commit 442903f
10 files changed
| Original file line number | Diff line number | Diff 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 | + | ||
| 1 | 10 | ### 1.11.2 | |
| 2 | 11 | ||
| 3 | 12 | * [`42e0cd1`](https://github.com/nodejs/node-inspect/commit/42e0cd111d89ed09faba1c0ec45089b0b44de011) **fix:** look for generic hint text | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,7 @@ node has two options: | |||
| 10 | 10 | 1. `node --debug <file>`: Start `file` with remote debugging enabled. | |
| 11 | 11 | 2. `node debug <file>`: Start an interactive CLI debugger for `<file>`. | |
| 12 | 12 | ||
| 13 | - But for the Chrome inspector protol, | ||
| 13 | + But for the Chrome inspector protocol, | ||
| 14 | 14 | there's only one: `node --inspect <file>`. | |
| 15 | 15 | ||
| 16 | 16 | This project tries to provide the missing second option | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,18 +42,9 @@ const [ InspectClient, createRepl ] = | |||
| 42 | 42 | ||
| 43 | 43 | const debuglog = util.debuglog('inspect'); | |
| 44 | 44 | ||
| 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 | - | ||
| 56 | 45 | function portIsFree(host, port, timeout = 2000) { | |
| 46 | + if (port === 0) return Promise.resolve(); // Binding to a random port. | ||
| 47 | + | ||
| 57 | 48 | const retryDelay = 150; | |
| 58 | 49 | let didTimeOut = false; | |
| 59 | 50 | ||
@@ -110,9 +101,11 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { | |||
| 110 | 101 | let output = ''; | |
| 111 | 102 | function waitForListenHint(text) { | |
| 112 | 103 | 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); | ||
| 114 | 107 | child.stderr.removeListener('data', waitForListenHint); | |
| 115 | - resolve(child); | ||
| 108 | + resolve([child, port, host]); | ||
| 116 | 109 | } | |
| 117 | 110 | } | |
| 118 | 111 | ||
@@ -160,10 +153,11 @@ class NodeInspector { | |||
| 160 | 153 | options.port, | |
| 161 | 154 | this.childPrint.bind(this)); | |
| 162 | 155 | } else { | |
| 163 | - this._runScript = () => Promise.resolve(null); | ||
| 156 | + this._runScript = | ||
| 157 | + () => Promise.resolve([null, options.port, options.host]); | ||
| 164 | 158 | } | |
| 165 | 159 | ||
| 166 | - this.client = new InspectClient(options.port, options.host); | ||
| 160 | + this.client = new InspectClient(); | ||
| 167 | 161 | ||
| 168 | 162 | this.domainNames = ['Debugger', 'HeapProfiler', 'Profiler', 'Runtime']; | |
| 169 | 163 | this.domainNames.forEach((domain) => { | |
@@ -223,17 +217,16 @@ class NodeInspector { | |||
| 223 | 217 | ||
| 224 | 218 | run() { | |
| 225 | 219 | this.killChild(); | |
| 226 | - const { host, port } = this.options; | ||
| 227 | 220 | ||
| 228 | - return this._runScript().then((child) => { | ||
| 221 | + return this._runScript().then(([child, port, host]) => { | ||
| 229 | 222 | this.child = child; | |
| 230 | 223 | ||
| 231 | 224 | let connectionAttempts = 0; | |
| 232 | 225 | const attemptConnect = () => { | |
| 233 | 226 | ++connectionAttempts; | |
| 234 | 227 | debuglog('connection attempt #%d', connectionAttempts); | |
| 235 | 228 | this.stdout.write('.'); | |
| 236 | - return this.client.connect() | ||
| 229 | + return this.client.connect(port, host) | ||
| 237 | 230 | .then(() => { | |
| 238 | 231 | debuglog('connection established'); | |
| 239 | 232 | this.stdout.write(' ok'); | |
@@ -288,7 +281,7 @@ class NodeInspector { | |||
| 288 | 281 | ||
| 289 | 282 | function parseArgv([target, ...args]) { | |
| 290 | 283 | let host = '127.0.0.1'; | |
| 291 | - let port = getDefaultPort(); | ||
| 284 | + let port = 9229; | ||
| 292 | 285 | let isRemote = false; | |
| 293 | 286 | let script = target; | |
| 294 | 287 | let scriptArgs = args; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -164,12 +164,12 @@ function decodeFrameHybi17(data) { | |||
| 164 | 164 | } | |
| 165 | 165 | ||
| 166 | 166 | class Client extends EventEmitter { | |
| 167 | - constructor(port, host) { | ||
| 167 | + constructor() { | ||
| 168 | 168 | super(); | |
| 169 | 169 | this.handleChunk = this._handleChunk.bind(this); | |
| 170 | 170 | ||
| 171 | - this._port = port; | ||
| 172 | - this._host = host; | ||
| 171 | + this._port = undefined; | ||
| 172 | + this._host = undefined; | ||
| 173 | 173 | ||
| 174 | 174 | this.reset(); | |
| 175 | 175 | } | |
@@ -284,7 +284,9 @@ class Client extends EventEmitter { | |||
| 284 | 284 | }); | |
| 285 | 285 | } | |
| 286 | 286 | ||
| 287 | - connect() { | ||
| 287 | + connect(port, host) { | ||
| 288 | + this._port = port; | ||
| 289 | + this._host = host; | ||
| 288 | 290 | return this._discoverWebsocketPath() | |
| 289 | 291 | .then((urlPath) => this._connectWebsocket(urlPath)); | |
| 290 | 292 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -900,10 +900,8 @@ function createRepl(inspector) { | |||
| 900 | 900 | return new Promise((resolve, reject) => { | |
| 901 | 901 | const absoluteFile = Path.resolve(filename); | |
| 902 | 902 | const writer = FS.createWriteStream(absoluteFile); | |
| 903 | - let totalSize; | ||
| 904 | 903 | let sizeWritten = 0; | |
| 905 | 904 | function onProgress({ done, total, finished }) { | |
| 906 | - totalSize = total; | ||
| 907 | 905 | if (finished) { | |
| 908 | 906 | print('Heap snaphost prepared.'); | |
| 909 | 907 | } else { | |
@@ -913,13 +911,18 @@ function createRepl(inspector) { | |||
| 913 | 911 | function onChunk({ chunk }) { | |
| 914 | 912 | sizeWritten += chunk.length; | |
| 915 | 913 | 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(() => { | ||
| 919 | 918 | teardown(); | |
| 920 | 919 | print(`Wrote snapshot: ${absoluteFile}`); | |
| 921 | 920 | resolve(); | |
| 922 | - } | ||
| 921 | + }); | ||
| 922 | + } | ||
| 923 | + function onReject(error) { | ||
| 924 | + teardown(); | ||
| 925 | + reject(error); | ||
| 923 | 926 | } | |
| 924 | 927 | function teardown() { | |
| 925 | 928 | HeapProfiler.removeListener( | |
@@ -932,10 +935,7 @@ function createRepl(inspector) { | |||
| 932 | 935 | ||
| 933 | 936 | print('Heap snapshot: 0/0', true); | |
| 934 | 937 | HeapProfiler.takeHeapSnapshot({ reportProgress: true }) | |
| 935 | - .then(null, (error) => { | ||
| 936 | - teardown(); | ||
| 937 | - reject(error); | ||
| 938 | - }); | ||
| 938 | + .then(onResolve, onReject); | ||
| 939 | 939 | }); | |
| 940 | 940 | }, | |
| 941 | 941 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | { | |
| 2 | 2 | "name": "node-inspect", | |
| 3 | - "version": "1.11.2", | ||
| 3 | + "version": "1.11.3", | ||
| 4 | 4 | "description": "Node Inspect", | |
| 5 | 5 | "license": "MIT", | |
| 6 | 6 | "main": "lib/_inspect.js", | |
@@ -29,7 +29,7 @@ | |||
| 29 | 29 | "devDependencies": { | |
| 30 | 30 | "eslint": "^3.10.2", | |
| 31 | 31 | "nlm": "^3.0.0", | |
| 32 | - "tap": "^7.1.2" | ||
| 32 | + "tap": "^10.7.0" | ||
| 33 | 33 | }, | |
| 34 | 34 | "author": { | |
| 35 | 35 | "name": "Jan Krems", | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,7 +134,7 @@ test('sb before loading file', (t) => { | |||
| 134 | 134 | ||
| 135 | 135 | return cli.waitForInitialBreak() | |
| 136 | 136 | .then(() => cli.waitForPrompt()) | |
| 137 | - .then(() => cli.command('sb("other.js", 3)')) | ||
| 137 | + .then(() => cli.command('sb("other.js", 2)')) | ||
| 138 | 138 | .then(() => { | |
| 139 | 139 | t.match( | |
| 140 | 140 | cli.output, | |
@@ -145,7 +145,7 @@ test('sb before loading file', (t) => { | |||
| 145 | 145 | .then(() => { | |
| 146 | 146 | t.match( | |
| 147 | 147 | cli.output, | |
| 148 | - `break in ${otherScript}:3`, | ||
| 148 | + `break in ${otherScript}:2`, | ||
| 149 | 149 | 'found breakpoint in file that was not loaded yet'); | |
| 150 | 150 | }) | |
| 151 | 151 | .then(() => cli.quit()) | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -26,6 +26,46 @@ test('custom port', (t) => { | |||
| 26 | 26 | }); | |
| 27 | 27 | }); | |
| 28 | 28 | ||
| 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 | + | ||
| 29 | 69 | test('examples/three-lines.js', (t) => { | |
| 30 | 70 | const script = Path.join('examples', 'three-lines.js'); | |
| 31 | 71 | const cli = startCLI([script]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,8 +16,8 @@ const BREAK_MESSAGE = new RegExp('(?:' + [ | |||
| 16 | 16 | 'exception', 'other', 'promiseRejection', | |
| 17 | 17 | ].join('|') + ') in', 'i'); | |
| 18 | 18 | ||
| 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]); | ||
| 21 | 21 | let isFirstStdoutChunk = true; | |
| 22 | 22 | ||
| 23 | 23 | const outputBuffer = []; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments