|
23 | 23 | const { spawn } = require('child_process'); |
24 | 24 | const { EventEmitter } = require('events'); |
25 | 25 | const net = require('net'); |
| 26 | +const semver = require('semver'); |
26 | 27 | const util = require('util'); |
27 | 28 |
|
28 | 29 | const runAsStandalone = typeof __dirname !== 'undefined'; |
@@ -94,30 +95,30 @@ function portIsFree(host, port, timeout = 2000) { |
94 | 95 |
|
95 | 96 | function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { |
96 | 97 | return portIsFree(inspectHost, inspectPort) |
97 | | - .then(() => { |
98 | | - return new Promise((resolve) => { |
99 | | - const args = [ |
100 | | - '--inspect', |
101 | | - `--inspect-brk=${inspectPort}`, |
102 | | - ].concat([script], scriptArgs); |
103 | | - const child = spawn(process.execPath, args); |
104 | | - child.stdout.setEncoding('utf8'); |
105 | | - child.stderr.setEncoding('utf8'); |
106 | | - child.stdout.on('data', childPrint); |
107 | | - child.stderr.on('data', childPrint); |
108 | | - |
109 | | - let output = ''; |
110 | | - function waitForListenHint(text) { |
111 | | - output += text; |
112 | | - if (/chrome-devtools:\/\//.test(output)) { |
113 | | - child.stderr.removeListener('data', waitForListenHint); |
114 | | - resolve(child); |
| 98 | + .then(() => { |
| 99 | + return new Promise((resolve) => { |
| 100 | + const args = (semver.satisfies(process.version, '>=7.6.0') ? |
| 101 | + [`--inspect-brk=${inspectPort}`] : |
| 102 | + ['--inspect', `--debug-brk=${inspectPort}`]) |
| 103 | + .concat([script], scriptArgs); |
| 104 | + const child = spawn(process.execPath, args); |
| 105 | + child.stdout.setEncoding('utf8'); |
| 106 | + child.stderr.setEncoding('utf8'); |
| 107 | + child.stdout.on('data', childPrint); |
| 108 | + child.stderr.on('data', childPrint); |
| 109 | + |
| 110 | + let output = ''; |
| 111 | + function waitForListenHint(text) { |
| 112 | + output += text; |
| 113 | + if (/chrome-devtools:\/\//.test(output)) { |
| 114 | + child.stderr.removeListener('data', waitForListenHint); |
| 115 | + resolve(child); |
| 116 | + } |
115 | 117 | } |
116 | | - } |
117 | 118 |
|
118 | | - child.stderr.on('data', waitForListenHint); |
| 119 | + child.stderr.on('data', waitForListenHint); |
| 120 | + }); |
119 | 121 | }); |
120 | | - }); |
121 | 122 | } |
122 | 123 |
|
123 | 124 | function createAgentProxy(domain, client) { |
|
0 commit comments