Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 57dd9f7

Browse files
committed
Preserve original output from subprocess.
This will keep the format and color from the subprocess, although we cannot modify mentions to local urls by doing this. Signed-off-by: David Calavera <[email protected]>
1 parent ed2a52f commit 57dd9f7

File tree

5 files changed

+88
-50
lines changed

5 files changed

+88
-50
lines changed

package-lock.json

Lines changed: 77 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
"bugs": "https://github.com/netlify/netlify-dev-plugin/issues",
77
"dependencies": {
88
"@netlify/cli-utils": "^1.0.0",
9+
"@netlify/rules-proxy": "0.1.0",
910
"@netlify/zip-it-and-ship-it": "^0.1.3",
1011
"@oclif/command": "^1",
1112
"@oclif/config": "^1",
1213
"ascii-table": "0.0.9",
1314
"copy-template-dir": "^1.4.0",
15+
"execa": "^1.0.0",
1416
"fs-extra": "^7.0.1",
1517
"fuzzy": "^0.1.3",
1618
"get-port": "^4.1.0",
1719
"http-proxy": "^1.17.0",
1820
"inquirer": "^6.2.2",
1921
"inquirer-autocomplete-prompt": "^1.0.1",
2022
"netlify": "2.4.1",
21-
"@netlify/rules-proxy": "0.1.0",
2223
"node-fetch": "^2.3.0",
2324
"opn": "^5.5.0",
2425
"safe-join": "^0.1.2",

src/commands/dev/exec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { spawn } = require('child_process')
1+
const execa = require('execa')
22
const Command = require('@netlify/cli-utils')
33
const { getAddons } = require('netlify/src/addons')
44

@@ -15,7 +15,7 @@ class ExecCommand extends Command {
1515
}
1616
})
1717
}
18-
spawn(this.argv[0], this.argv.slice(1), { env: process.env, stdio: 'inherit' })
18+
execa(this.argv[0], this.argv.slice(1), { env: process.env, stdio: 'inherit' })
1919
}
2020
}
2121

src/commands/dev/index.js

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { flags } = require('@oclif/command')
2-
const { spawn } = require('child_process')
2+
const execa = require('execa')
33
const http = require('http')
44
const httpProxy = require('http-proxy')
55
const waitPort = require('wait-port')
@@ -10,10 +10,6 @@ const openBrowser = require('../../utils/openBrowser')
1010
const Command = require('@netlify/cli-utils')
1111
const { getAddons } = require('netlify/src/addons')
1212

13-
function cleanExit() {
14-
process.exit()
15-
}
16-
1713
function isFunction(settings, req) {
1814
return settings.functionsPort && req.url.match(/^\/.netlify\/functions\/.+/)
1915
}
@@ -98,22 +94,10 @@ function startDevServer(settings, log, error) {
9894
return
9995
}
10096

101-
const ps = spawn(settings.cmd, settings.args, { env: settings.env })
102-
103-
ps.stdout.on('data', data => {
104-
log(`${data}`.replace(settings.urlRegexp, `$1$2${settings.port}$3`))
105-
})
106-
107-
ps.stderr.on('data', data => {
108-
log(`Error reading data: ${data}`)
109-
})
110-
111-
ps.on('close', code => {
112-
process.exit(code)
113-
})
114-
115-
ps.on('SIGINT', cleanExit)
116-
ps.on('SIGTERM', cleanExit)
97+
const ps = execa(settings.cmd, settings.args, { env: settings.env, stdio: 'inherit', shell: true })
98+
ps.on('close', code => process.exit(code))
99+
ps.on('SIGINT', process.exit)
100+
ps.on('SIGTERM', process.exit)
117101
}
118102

119103
class DevCommand extends Command {

src/utils/openBrowser.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
var chalk = require('chalk')
66
var execSync = require('child_process').execSync
7-
var spawn = require('cross-spawn')
7+
var execa = require('execa')
88
var opn = require('opn')
99

1010
// https://github.com/sindresorhus/opn#app
@@ -37,9 +37,7 @@ function getBrowserEnv() {
3737

3838
function executeNodeScript(scriptPath, url) {
3939
const extraArgs = process.argv.slice(2)
40-
const child = spawn('node', [scriptPath, ...extraArgs, url], {
41-
stdio: 'inherit'
42-
})
40+
const child = spawn('node', [scriptPath, ...extraArgs, url], { stdio: 'inherit' })
4341
child.on('close', code => {
4442
if (code !== 0) {
4543
console.log()

0 commit comments

Comments
 (0)