| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e3533ab commit 8803d7e
8 files changed
| Original file line number | Diff line number | Diff 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,15 +30,15 @@ const runAsStandalone = typeof __dirname !== 'undefined'; | |||
| 30 | 30 | const [ InspectClient, createRepl ] = | |
| 31 | 31 | runAsStandalone ? | |
| 32 | 32 | // 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 | + ] : | ||
| 37 | 37 | // 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 | + ]; | ||
| 42 | 42 | ||
| 43 | 43 | const debuglog = util.debuglog('inspect'); | |
| 44 | 44 | ||
@@ -49,8 +49,8 @@ class StartupError extends Error { | |||
| 49 | 49 | } | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 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. | ||
| 54 | 54 | ||
| 55 | 55 | const retryDelay = 150; | |
| 56 | 56 | let didTimeOut = false; | |
@@ -96,9 +96,9 @@ function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { | |||
| 96 | 96 | return new Promise((resolve) => { | |
| 97 | 97 | const needDebugBrk = process.version.match(/^v(6|7)\./); | |
| 98 | 98 | 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); | ||
| 102 | 102 | const child = spawn(process.execPath, args); | |
| 103 | 103 | child.stdout.setEncoding('utf8'); | |
| 104 | 104 | child.stderr.setEncoding('utf8'); | |
@@ -154,11 +154,11 @@ class NodeInspector { | |||
| 154 | 154 | ||
| 155 | 155 | if (options.script) { | |
| 156 | 156 | 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)); | ||
| 162 | 162 | } else { | |
| 163 | 163 | this._runScript = | |
| 164 | 164 | () => Promise.resolve([null, options.port, options.host]); | |
@@ -333,8 +333,8 @@ function parseArgv([target, ...args]) { | |||
| 333 | 333 | } | |
| 334 | 334 | ||
| 335 | 335 | function startInspect(argv = process.argv.slice(2), | |
| 336 | - stdin = process.stdin, | ||
| 337 | - stdout = process.stdout) { | ||
| 336 | + stdin = process.stdin, | ||
| 337 | + stdout = process.stdout) { | ||
| 338 | 338 | /* eslint-disable no-console */ | |
| 339 | 339 | if (argv.length < 1) { | |
| 340 | 340 | const invokedAs = runAsStandalone ? | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,9 +85,16 @@ function extractFunctionName(description) { | |||
| 85 | 85 | return fnNameMatch ? `: ${fnNameMatch[1]}` : ''; | |
| 86 | 86 | } | |
| 87 | 87 | ||
| 88 | - const NATIVES = process.binding('natives'); | ||
| 88 | + const PUBLIC_BUILTINS = require('module').builtinModules; | ||
| 89 | + const NATIVES = PUBLIC_BUILTINS ? process.binding('natives') : {}; | ||
| 89 | 90 | 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'; | ||
| 91 | 98 | } | |
| 92 | 99 | ||
| 93 | 100 | function getRelativePath(filenameOrURL) { | |
@@ -775,6 +782,14 @@ function createRepl(inspector) { | |||
| 775 | 782 | } | |
| 776 | 783 | ||
| 777 | 784 | 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 | + | ||
| 778 | 793 | // Save execution context's data | |
| 779 | 794 | currentBacktrace = Backtrace.from(callFrames); | |
| 780 | 795 | selectedFrame = currentBacktrace[0]; | |
| 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.6", | ||
| 3 | + "version": "2.0.0", | ||
| 4 | 4 | "description": "Node Inspect", | |
| 5 | 5 | "license": "MIT", | |
| 6 | 6 | "main": "lib/_inspect.js", | |
@@ -27,7 +27,7 @@ | |||
| 27 | 27 | }, | |
| 28 | 28 | "dependencies": {}, | |
| 29 | 29 | "devDependencies": { | |
| 30 | - "eslint": "^3.10.2", | ||
| 30 | + "eslint": "^6.8.0", | ||
| 31 | 31 | "nlm": "^3.0.0", | |
| 32 | 32 | "tap": "^10.7.0" | |
| 33 | 33 | }, | |
| Original file line number | Diff line number | Diff 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ test('launch w/ invalid host:port', (t) => { | |||
| 27 | 27 | }); | |
| 28 | 28 | }); | |
| 29 | 29 | ||
| 30 | - test('launch w/ unavailable port', async (t) => { | ||
| 30 | + test('launch w/ unavailable port', async(t) => { | ||
| 31 | 31 | const blocker = createServer((socket) => socket.end()); | |
| 32 | 32 | const port = await new Promise((resolve, reject) => { | |
| 33 | 33 | blocker.on('error', reject); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,3 +174,23 @@ test('run after quit / restart', (t) => { | |||
| 174 | 174 | .then(() => cli.quit()) | |
| 175 | 175 | .then(null, onFatal); | |
| 176 | 176 | }); | |
| 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 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,8 +8,8 @@ tap.test('startCLI', (t) => t.end()); | |||
| 8 | 8 | ||
| 9 | 9 | const CLI = | |
| 10 | 10 | process.env.USE_EMBEDDED_NODE_INSPECT === '1' ? | |
| 11 | - 'inspect' : | ||
| 12 | - require.resolve('../../cli.js'); | ||
| 11 | + 'inspect' : | ||
| 12 | + require.resolve('../../cli.js'); | ||
| 13 | 13 | ||
| 14 | 14 | const BREAK_MESSAGE = new RegExp('(?:' + [ | |
| 15 | 15 | 'assert', 'break', 'break on start', 'debugCommand', | |
@@ -20,8 +20,8 @@ function isPreBreak(output) { | |||
| 20 | 20 | return /Break on start/.test(output) && /1 \(function \(exports/.test(output); | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 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); | ||
| 25 | 25 | let isFirstStdoutChunk = true; | |
| 26 | 26 | ||
| 27 | 27 | const outputBuffer = []; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments