From d01af47bf61d070228fc8adbeb1c043fe5728635 Mon Sep 17 00:00:00 2001 From: Paul Bouchon Date: Tue, 13 Mar 2018 20:28:17 -0400 Subject: [PATCH] feat: support --build-delimiter for opt-in output delimiter (#192) (#340) --- bin/process-options.js | 7 ++++++- bin/webpack.js | 12 +++++++++++- test/binCases/stats/build-delimiter/index.js | 1 + test/binCases/stats/build-delimiter/stdin.js | 9 +++++++++ test/binCases/stats/build-delimiter/test.opts | 3 +++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/binCases/stats/build-delimiter/index.js create mode 100644 test/binCases/stats/build-delimiter/stdin.js create mode 100644 test/binCases/stats/build-delimiter/test.opts diff --git a/bin/process-options.js b/bin/process-options.js index 3c3f8e2705c..c766e3942f3 100644 --- a/bin/process-options.js +++ b/bin/process-options.js @@ -98,6 +98,10 @@ module.exports = function processOptions(yargs, argv) { if (bool) outputOptions.cachedAssets = true; }); + ifArg("build-delimiter", function(value) { + outputOptions.buildDelimiter = value; + }); + if (!outputOptions.exclude && !argv["display-modules"]) outputOptions.exclude = [ "node_modules", @@ -175,8 +179,9 @@ module.exports = function processOptions(yargs, argv) { ); } else if (stats.hash !== lastHash) { lastHash = stats.hash; + const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : ""; process.stdout.write("\n" + new Date() + "\n" + "\n"); - process.stdout.write(stats.toString(outputOptions) + "\n"); + process.stdout.write(`${stats.toString(outputOptions)}\n${delimiter}`); if (argv.s) lastHash = null; } if (!options.watch && stats.hasErrors()) { diff --git a/bin/webpack.js b/bin/webpack.js index 7bebb6abab9..7c6262e8574 100755 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -203,6 +203,11 @@ group: DISPLAY_GROUP, describe: "Controls the output of lifecycle messaging e.g. Started watching files..." + }, + "build-delimiter": { + type: "string", + group: DISPLAY_GROUP, + describe: "Display custom text after build output" } }); @@ -419,6 +424,10 @@ outputOptions.infoVerbosity = value; }); + ifArg("build-delimiter", function(value) { + outputOptions.buildDelimiter = value; + }); + const webpack = require("webpack"); let lastHash = null; @@ -473,7 +482,8 @@ } else if (stats.hash !== lastHash) { lastHash = stats.hash; const statsString = stats.toString(outputOptions); - if (statsString) stdout.write(statsString + "\n"); + const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` : ""; + if (statsString) stdout.write(`${statsString}\n${delimiter}`); } if (!options.watch && stats.hasErrors()) { process.exitCode = 2; diff --git a/test/binCases/stats/build-delimiter/index.js b/test/binCases/stats/build-delimiter/index.js new file mode 100644 index 00000000000..e7134e7006d --- /dev/null +++ b/test/binCases/stats/build-delimiter/index.js @@ -0,0 +1 @@ +module.exports = "foo"; diff --git a/test/binCases/stats/build-delimiter/stdin.js b/test/binCases/stats/build-delimiter/stdin.js new file mode 100644 index 00000000000..afa24083d1a --- /dev/null +++ b/test/binCases/stats/build-delimiter/stdin.js @@ -0,0 +1,9 @@ +"use strict"; + +module.exports = function testAssertions(code, stdout, stderr) { + const lastLines = stdout.slice(-2); + expect(code).toBe(0); + expect(lastLines[0]).toBe("success"); + expect(lastLines[1]).toBe(""); + expect(stderr).toHaveLength(0); +}; diff --git a/test/binCases/stats/build-delimiter/test.opts b/test/binCases/stats/build-delimiter/test.opts new file mode 100644 index 00000000000..979593c94c9 --- /dev/null +++ b/test/binCases/stats/build-delimiter/test.opts @@ -0,0 +1,3 @@ +--entry ./index.js +--display normal +--build-delimiter success