From 92eba60805f0b96a070c802d5e488093a4316eb5 Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Thu, 25 Jul 2019 02:00:34 +0400 Subject: [PATCH 1/5] Dev server: Dont hand over the terminal pipe to script --- src/commands/dev/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 7d5afb9..4c5d72f 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -159,7 +159,6 @@ function startDevServer(settings, log) { settings.command === "npm" ? ["run", ...settings.args] : settings.args; const ps = execa(settings.command, args, { env: settings.env, - stdio: "inherit" }); ps.on("close", code => process.exit(code)); ps.on("SIGINT", process.exit); From e48711b2dbc10fb6b568f22d5b8911af0cb74697 Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Thu, 25 Jul 2019 02:01:08 +0400 Subject: [PATCH 2/5] Strip ANSI before displaying child output --- package.json | 1 + src/commands/dev/index.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/package.json b/package.json index 47168c6..6461d85 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "resolve": "^1.10.0", "safe-join": "^0.1.2", "static-server": "^2.2.1", + "strip-ansi": "^5.2.0", "wait-port": "^0.2.2", "wrap-ansi": "^5.1.0" }, diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 4c5d72f..9371439 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -5,6 +5,7 @@ const httpProxy = require("http-proxy"); const waitPort = require("wait-port"); const getPort = require("get-port"); const chokidar = require("chokidar"); +const stripAnsi = require("strip-ansi") const { serveFunctions } = require("../../utils/serve-functions"); const { serverSettings } = require("../../detect-server"); const { detectFunctionsBuilder } = require("../../detect-functions-builder"); @@ -160,6 +161,12 @@ function startDevServer(settings, log) { const ps = execa(settings.command, args, { env: settings.env, }); + ps.stdout.on('data', function(buffer) { + process.stdout.write(stripAnsi(buffer.toString('utf8'))) + }) + ps.stderr.on('data', function(buffer) { + process.stderr.write(stripAnsi(buffer.toString('utf8'))) + }) ps.on("close", code => process.exit(code)); ps.on("SIGINT", process.exit); ps.on("SIGTERM", process.exit); From bd6f53baa1d80c50c8e62a529659aaac0c0b8401 Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Thu, 25 Jul 2019 21:52:11 +0400 Subject: [PATCH 3/5] Remove strip-ansi --- package.json | 1 - src/commands/dev/index.js | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 6461d85..47168c6 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "resolve": "^1.10.0", "safe-join": "^0.1.2", "static-server": "^2.2.1", - "strip-ansi": "^5.2.0", "wait-port": "^0.2.2", "wrap-ansi": "^5.1.0" }, diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 9371439..56ff2de 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -5,7 +5,6 @@ const httpProxy = require("http-proxy"); const waitPort = require("wait-port"); const getPort = require("get-port"); const chokidar = require("chokidar"); -const stripAnsi = require("strip-ansi") const { serveFunctions } = require("../../utils/serve-functions"); const { serverSettings } = require("../../detect-server"); const { detectFunctionsBuilder } = require("../../detect-functions-builder"); @@ -159,14 +158,14 @@ function startDevServer(settings, log) { const args = settings.command === "npm" ? ["run", ...settings.args] : settings.args; const ps = execa(settings.command, args, { - env: settings.env, + env: settings.env + }); + ps.stdout.on("data", function(buffer) { + process.stdout.write(buffer.toString("utf8")); + }); + ps.stderr.on("data", function(buffer) { + process.stderr.write(buffer.toString("utf8")); }); - ps.stdout.on('data', function(buffer) { - process.stdout.write(stripAnsi(buffer.toString('utf8'))) - }) - ps.stderr.on('data', function(buffer) { - process.stderr.write(stripAnsi(buffer.toString('utf8'))) - }) ps.on("close", code => process.exit(code)); ps.on("SIGINT", process.exit); ps.on("SIGTERM", process.exit); @@ -324,7 +323,8 @@ DevCommand.flags = { }), port: flags.integer({ char: "p", - description: "port of netlify dev" }), + description: "port of netlify dev" + }), dir: flags.string({ char: "d", description: "dir with static files" From f6118eb32dc442df9f5698ae3a6f1d1eeaaf4bb3 Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Thu, 25 Jul 2019 22:28:47 +0400 Subject: [PATCH 4/5] ChildProcess: Inherit stdin --- src/commands/dev/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index 56ff2de..f253117 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -158,7 +158,8 @@ function startDevServer(settings, log) { const args = settings.command === "npm" ? ["run", ...settings.args] : settings.args; const ps = execa(settings.command, args, { - env: settings.env + env: settings.env, + stdio: ["inherit", "pipe", "pipe"] }); ps.stdout.on("data", function(buffer) { process.stdout.write(buffer.toString("utf8")); From 24908b90cc5e475023e6eecbdf2f92b99b3b4a0e Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Mon, 29 Jul 2019 17:20:49 +0500 Subject: [PATCH 5/5] dev: Force Chalk color --- src/commands/dev/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/dev/index.js b/src/commands/dev/index.js index f253117..2a5519c 100644 --- a/src/commands/dev/index.js +++ b/src/commands/dev/index.js @@ -158,7 +158,7 @@ function startDevServer(settings, log) { const args = settings.command === "npm" ? ["run", ...settings.args] : settings.args; const ps = execa(settings.command, args, { - env: settings.env, + env: { ...settings.env, FORCE_COLOR: "true" }, stdio: ["inherit", "pipe", "pipe"] }); ps.stdout.on("data", function(buffer) {