From 2c9db31d2441d2e562879f0af88db27f701979f3 Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Tue, 8 May 2018 19:11:23 +0530 Subject: [PATCH 01/10] fixed test cases --- bin/cli.js | 13 ++++++++++++ test/binCases/no-options/development/stdin.js | 15 +++++++------ test/binCases/no-options/none/stdin.js | 21 +++++++++++-------- test/binCases/no-options/production/stdin.js | 14 +++++++------ .../watch/single-config-watch-opt/stdin.js | 1 - 5 files changed, 42 insertions(+), 22 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 9cfbf246ed6..be2ca757c14 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -496,6 +496,19 @@ For more information, see https://webpack.js.org/api/cli/.`); ); } else if (stats.hash !== lastHash) { lastHash = stats.hash; + if (stats.compilation && stats.compilation.errors.length !== 0) { + const errors = stats.compilation.errors; + if (errors[0].name === "EntryModuleNotFoundError") { + stdout.write( + "\n" + " ERROR Insufficient number of arguments provided " + + "\n" + " INFO Alternatively, run `webpack(-cli) --help` for usage info." + + "\n\n" + ); + } + } else { + const statsString = stats.toString(outputOptions); + if (statsString) stdout.write(statsString + "\n"); + } const statsString = stats.toString(outputOptions); const delimiter = outputOptions.buildDelimiter ? `${outputOptions.buildDelimiter}\n` diff --git a/test/binCases/no-options/development/stdin.js b/test/binCases/no-options/development/stdin.js index d1a888c24cb..fba17082594 100644 --- a/test/binCases/no-options/development/stdin.js +++ b/test/binCases/no-options/development/stdin.js @@ -3,11 +3,14 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(2); expect(stdout).toEqual(expect.anything()); - expect(stdout[0]).toContain("Hash: "); - expect(stdout[1]).toContain("Version: "); - expect(stdout[2]).toContain("Time: "); - expect(stdout[4]).toContain(""); - expect(stdout[5]).toContain("ERROR in Entry module not found"); - expect(stdout[6]).toContain(""); + console.log('printing value of error', stdout[1]); + expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); + expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); + expect(stdout[4]).toContain("Hash: "); + expect(stdout[5]).toContain("Version: "); + expect(stdout[6]).toContain("Time: "); + expect(stdout[7]).toContain(""); + expect(stdout[9]).toContain("ERROR in Entry module not found"); + expect(stdout[10]).toContain(""); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/no-options/none/stdin.js b/test/binCases/no-options/none/stdin.js index 791fb1a5277..827a4aa499b 100644 --- a/test/binCases/no-options/none/stdin.js +++ b/test/binCases/no-options/none/stdin.js @@ -3,14 +3,17 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(2); expect(stdout).toEqual(expect.anything()); - expect(stdout[0]).toContain("Hash: "); - expect(stdout[1]).toContain("Version: "); - expect(stdout[2]).toContain("Time: "); - expect(stdout[4]).toContain(""); - expect(stdout[5]).toContain("WARNING"); - expect(stdout[6]).toContain("The \'mode\' option has not been set"); - expect(stdout[7]).toContain("You can also set it to \'none\'"); - expect(stdout[8]).toContain(""); - expect(stdout[9]).toContain("ERROR in Entry module not found"); + console.log('printing value of error', stdout[1]); + expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); + expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); + expect(stdout[4]).toContain("Hash: "); + expect(stdout[5]).toContain("Version: "); + expect(stdout[6]).toContain("Time: "); + expect(stdout[7]).toContain(""); + expect(stdout[9]).toContain("WARNING"); + expect(stdout[10]).toContain("The \'mode\' option has not been set"); + expect(stdout[11]).toContain("You can also set it to \'none\'"); + expect(stdout[12]).toContain(""); + expect(stdout[13]).toContain("ERROR in Entry module not found"); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/no-options/production/stdin.js b/test/binCases/no-options/production/stdin.js index d1a888c24cb..73eb4185da5 100644 --- a/test/binCases/no-options/production/stdin.js +++ b/test/binCases/no-options/production/stdin.js @@ -3,11 +3,13 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(2); expect(stdout).toEqual(expect.anything()); - expect(stdout[0]).toContain("Hash: "); - expect(stdout[1]).toContain("Version: "); - expect(stdout[2]).toContain("Time: "); - expect(stdout[4]).toContain(""); - expect(stdout[5]).toContain("ERROR in Entry module not found"); - expect(stdout[6]).toContain(""); + expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); + expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); + expect(stdout[4]).toContain("Hash: "); + expect(stdout[5]).toContain("Version: "); + expect(stdout[6]).toContain("Time: "); + expect(stdout[7]).toContain("Built at"); + expect(stdout[9]).toContain("ERROR in Entry module not found"); + expect(stdout[10]).toContain(""); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/watch/single-config-watch-opt/stdin.js b/test/binCases/watch/single-config-watch-opt/stdin.js index 8fae9bafeb6..55ecb02a86e 100644 --- a/test/binCases/watch/single-config-watch-opt/stdin.js +++ b/test/binCases/watch/single-config-watch-opt/stdin.js @@ -4,7 +4,6 @@ module.exports = function testAssertions(stdout, stderr, done) { expect(stdout).toEqual(expect.anything()); expect(stdout[0]).toContain(""); expect(stdout[1]).toContain("Webpack is watching the files…"); - expect(stderr).toHaveLength(0); done(); }; From 4b50c34d4383cd6a30c469e82f4b1b54dbe8b21a Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Tue, 8 May 2018 19:49:18 +0530 Subject: [PATCH 02/10] remove unwanted console --- test/binCases/no-options/development/stdin.js | 1 - test/binCases/no-options/none/stdin.js | 1 - 2 files changed, 2 deletions(-) diff --git a/test/binCases/no-options/development/stdin.js b/test/binCases/no-options/development/stdin.js index fba17082594..6549595d326 100644 --- a/test/binCases/no-options/development/stdin.js +++ b/test/binCases/no-options/development/stdin.js @@ -3,7 +3,6 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(2); expect(stdout).toEqual(expect.anything()); - console.log('printing value of error', stdout[1]); expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); expect(stdout[4]).toContain("Hash: "); diff --git a/test/binCases/no-options/none/stdin.js b/test/binCases/no-options/none/stdin.js index 827a4aa499b..360b7dea296 100644 --- a/test/binCases/no-options/none/stdin.js +++ b/test/binCases/no-options/none/stdin.js @@ -3,7 +3,6 @@ module.exports = function testAssertions(code, stdout, stderr) { expect(code).toBe(2); expect(stdout).toEqual(expect.anything()); - console.log('printing value of error', stdout[1]); expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); expect(stdout[4]).toContain("Hash: "); From 3c6a631b6f750714d25f116f243c44a0ea2c5215 Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Mon, 21 May 2018 08:36:09 +0530 Subject: [PATCH 03/10] fix(254) - addressed PR comments --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index be2ca757c14..21d040f70be 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -498,7 +498,7 @@ For more information, see https://webpack.js.org/api/cli/.`); lastHash = stats.hash; if (stats.compilation && stats.compilation.errors.length !== 0) { const errors = stats.compilation.errors; - if (errors[0].name === "EntryModuleNotFoundError") { + if (errors[0].name === "EntryModuleNotFoundError" && outputOptions.entry === undefined) { stdout.write( "\n" + " ERROR Insufficient number of arguments provided " + "\n" + " INFO Alternatively, run `webpack(-cli) --help` for usage info." + From 0a89eb6fee2512df6736ae73df730e0ad771135f Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Mon, 21 May 2018 09:27:24 +0530 Subject: [PATCH 04/10] fix(254) - added requested changes at right place --- bin/cli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 21d040f70be..90c547bfbde 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -496,9 +496,9 @@ For more information, see https://webpack.js.org/api/cli/.`); ); } else if (stats.hash !== lastHash) { lastHash = stats.hash; - if (stats.compilation && stats.compilation.errors.length !== 0) { + if (stats.compilation && stats.compilation.errors.length !== 0 && outputOptions.entry === undefined) { const errors = stats.compilation.errors; - if (errors[0].name === "EntryModuleNotFoundError" && outputOptions.entry === undefined) { + if (errors[0].name === "EntryModuleNotFoundError") { stdout.write( "\n" + " ERROR Insufficient number of arguments provided " + "\n" + " INFO Alternatively, run `webpack(-cli) --help` for usage info." + From 904e527c00de29db9fb45a60d279e736be39deb4 Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Tue, 22 May 2018 12:15:17 +0530 Subject: [PATCH 05/10] fix(254) - exit after error exit webpack if defaults are not found fix test cases for no options --- bin/cli.js | 4 +++- test/binCases/no-options/development/stdin.js | 12 +++--------- test/binCases/no-options/none/stdin.js | 15 +++------------ test/binCases/no-options/production/stdin.js | 12 +++--------- test/binCases/no-options/stdin.js | 5 +++++ 5 files changed, 17 insertions(+), 31 deletions(-) create mode 100644 test/binCases/no-options/stdin.js diff --git a/bin/cli.js b/bin/cli.js index 90c547bfbde..8173a22f1ac 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -496,14 +496,16 @@ For more information, see https://webpack.js.org/api/cli/.`); ); } else if (stats.hash !== lastHash) { lastHash = stats.hash; - if (stats.compilation && stats.compilation.errors.length !== 0 && outputOptions.entry === undefined) { + if (stats.compilation && stats.compilation.errors.length !== 0) { const errors = stats.compilation.errors; if (errors[0].name === "EntryModuleNotFoundError") { + stdout.write("\n" + chalk.red(errors[0].error.toString()) + "\n"); stdout.write( "\n" + " ERROR Insufficient number of arguments provided " + "\n" + " INFO Alternatively, run `webpack(-cli) --help` for usage info." + "\n\n" ); + process.exit(0); } } else { const statsString = stats.toString(outputOptions); diff --git a/test/binCases/no-options/development/stdin.js b/test/binCases/no-options/development/stdin.js index 6549595d326..0e25a9e56b4 100644 --- a/test/binCases/no-options/development/stdin.js +++ b/test/binCases/no-options/development/stdin.js @@ -1,15 +1,9 @@ "use strict"; module.exports = function testAssertions(code, stdout, stderr) { - expect(code).toBe(2); + expect(code).toBe(0); expect(stdout).toEqual(expect.anything()); - expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); - expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); - expect(stdout[4]).toContain("Hash: "); - expect(stdout[5]).toContain("Version: "); - expect(stdout[6]).toContain("Time: "); - expect(stdout[7]).toContain(""); - expect(stdout[9]).toContain("ERROR in Entry module not found"); - expect(stdout[10]).toContain(""); + expect(stdout[3]).toContain("Insufficient number of arguments provided"); + expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/no-options/none/stdin.js b/test/binCases/no-options/none/stdin.js index 360b7dea296..0e25a9e56b4 100644 --- a/test/binCases/no-options/none/stdin.js +++ b/test/binCases/no-options/none/stdin.js @@ -1,18 +1,9 @@ "use strict"; module.exports = function testAssertions(code, stdout, stderr) { - expect(code).toBe(2); + expect(code).toBe(0); expect(stdout).toEqual(expect.anything()); - expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); - expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); - expect(stdout[4]).toContain("Hash: "); - expect(stdout[5]).toContain("Version: "); - expect(stdout[6]).toContain("Time: "); - expect(stdout[7]).toContain(""); - expect(stdout[9]).toContain("WARNING"); - expect(stdout[10]).toContain("The \'mode\' option has not been set"); - expect(stdout[11]).toContain("You can also set it to \'none\'"); - expect(stdout[12]).toContain(""); - expect(stdout[13]).toContain("ERROR in Entry module not found"); + expect(stdout[3]).toContain("Insufficient number of arguments provided"); + expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/no-options/production/stdin.js b/test/binCases/no-options/production/stdin.js index 73eb4185da5..0e25a9e56b4 100644 --- a/test/binCases/no-options/production/stdin.js +++ b/test/binCases/no-options/production/stdin.js @@ -1,15 +1,9 @@ "use strict"; module.exports = function testAssertions(code, stdout, stderr) { - expect(code).toBe(2); + expect(code).toBe(0); expect(stdout).toEqual(expect.anything()); - expect(stdout[1]).toContain("ERROR Insufficient number of arguments provided"); - expect(stdout[2]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); - expect(stdout[4]).toContain("Hash: "); - expect(stdout[5]).toContain("Version: "); - expect(stdout[6]).toContain("Time: "); - expect(stdout[7]).toContain("Built at"); - expect(stdout[9]).toContain("ERROR in Entry module not found"); - expect(stdout[10]).toContain(""); + expect(stdout[3]).toContain("Insufficient number of arguments provided"); + expect(stdout[4]).toContain("Alternatively, run `webpack(-cli) --help` for usage info"); expect(stderr).toHaveLength(0); }; diff --git a/test/binCases/no-options/stdin.js b/test/binCases/no-options/stdin.js new file mode 100644 index 00000000000..edf6842a583 --- /dev/null +++ b/test/binCases/no-options/stdin.js @@ -0,0 +1,5 @@ +"use strict"; + +module.exports = function testAssertions(code, stdout, stderr) { + expect(stdout[3]).toContain("Insufficient number of arguments provided"); +}; From 5c9fe7c47088422dd5153aebf874e41074130ccd Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Sun, 27 May 2018 08:39:08 +0530 Subject: [PATCH 06/10] fix: require chalk --- bin/cli.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 8173a22f1ac..b0c6f4543b6 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -4,6 +4,7 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ +const chalk = require("chalk"); (function() { // wrap in IIFE to be able to use return @@ -501,8 +502,8 @@ For more information, see https://webpack.js.org/api/cli/.`); if (errors[0].name === "EntryModuleNotFoundError") { stdout.write("\n" + chalk.red(errors[0].error.toString()) + "\n"); stdout.write( - "\n" + " ERROR Insufficient number of arguments provided " + - "\n" + " INFO Alternatively, run `webpack(-cli) --help` for usage info." + + "\n" + chalk.blue("ERROR ") + "Insufficient number of arguments provided " + + "\n" + chalk.blue("INFO ") + "Alternatively, run `webpack(-cli) --help` for usage info." + "\n\n" ); process.exit(0); From bac9c01b4e3ae1a808db37d5343199bf84543951 Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Wed, 30 May 2018 13:39:30 +0530 Subject: [PATCH 07/10] refactor - addressed PR comments --- bin/cli.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index b0c6f4543b6..0303d6d9b85 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -4,8 +4,6 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -const chalk = require("chalk"); - (function() { // wrap in IIFE to be able to use return @@ -500,13 +498,12 @@ For more information, see https://webpack.js.org/api/cli/.`); if (stats.compilation && stats.compilation.errors.length !== 0) { const errors = stats.compilation.errors; if (errors[0].name === "EntryModuleNotFoundError") { - stdout.write("\n" + chalk.red(errors[0].error.toString()) + "\n"); + stdout.write("\n" + errors[0].error.toString() + "\n"); stdout.write( - "\n" + chalk.blue("ERROR ") + "Insufficient number of arguments provided " + - "\n" + chalk.blue("INFO ") + "Alternatively, run `webpack(-cli) --help` for usage info." + + "\n" + "ERROR Insufficient number of arguments provided " + + "\n" + "INFO Alternatively, run `webpack(-cli) --help` for usage info." + "\n\n" ); - process.exit(0); } } else { const statsString = stats.toString(outputOptions); From c604d3ed25aa7b6f6e8dab6fde4885d55e0c350d Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Thu, 31 May 2018 10:44:20 +0530 Subject: [PATCH 08/10] refactor - addressed PR comments --- bin/cli.js | 4 +--- test/binCases/watch/single-config-watch-opt/stdin.js | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 0303d6d9b85..f808c83f2f4 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -4,6 +4,7 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ + (function() { // wrap in IIFE to be able to use return @@ -505,9 +506,6 @@ For more information, see https://webpack.js.org/api/cli/.`); "\n\n" ); } - } else { - const statsString = stats.toString(outputOptions); - if (statsString) stdout.write(statsString + "\n"); } const statsString = stats.toString(outputOptions); const delimiter = outputOptions.buildDelimiter diff --git a/test/binCases/watch/single-config-watch-opt/stdin.js b/test/binCases/watch/single-config-watch-opt/stdin.js index 55ecb02a86e..8fae9bafeb6 100644 --- a/test/binCases/watch/single-config-watch-opt/stdin.js +++ b/test/binCases/watch/single-config-watch-opt/stdin.js @@ -4,6 +4,7 @@ module.exports = function testAssertions(stdout, stderr, done) { expect(stdout).toEqual(expect.anything()); expect(stdout[0]).toContain(""); expect(stdout[1]).toContain("Webpack is watching the files…"); + expect(stderr).toHaveLength(0); done(); }; From 1bc33183c4baf6958e9e1e1998d560d8d938e052 Mon Sep 17 00:00:00 2001 From: sumit-gupta91 Date: Thu, 31 May 2018 22:36:44 +0530 Subject: [PATCH 09/10] refactor : remove unwanted keywords --- bin/cli.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index f808c83f2f4..ac34e02d3fe 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -501,8 +501,8 @@ For more information, see https://webpack.js.org/api/cli/.`); if (errors[0].name === "EntryModuleNotFoundError") { stdout.write("\n" + errors[0].error.toString() + "\n"); stdout.write( - "\n" + "ERROR Insufficient number of arguments provided " + - "\n" + "INFO Alternatively, run `webpack(-cli) --help` for usage info." + + "\n" + "Insufficient number of arguments provided " + + "\n" + "Alternatively, run `webpack(-cli) --help` for usage info." + "\n\n" ); } From 94579b7c66dc1c35e8e176b960d5690bf67f744b Mon Sep 17 00:00:00 2001 From: ev1stensberg Date: Sat, 2 Jun 2018 02:12:30 +0200 Subject: [PATCH 10/10] chore(review): format --- bin/cli.js | 10 +++---- packages/utils/recursive-parser.test.js | 38 +++++++++++-------------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index ac34e02d3fe..b34375a8697 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -499,11 +499,11 @@ For more information, see https://webpack.js.org/api/cli/.`); if (stats.compilation && stats.compilation.errors.length !== 0) { const errors = stats.compilation.errors; if (errors[0].name === "EntryModuleNotFoundError") { - stdout.write("\n" + errors[0].error.toString() + "\n"); - stdout.write( - "\n" + "Insufficient number of arguments provided " + - "\n" + "Alternatively, run `webpack(-cli) --help` for usage info." + - "\n\n" + console.error( + "\n\u001b[1m\u001b[31mInsufficient number of arguments or no entry found." + ); + console.error( + "\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n" ); } } diff --git a/packages/utils/recursive-parser.test.js b/packages/utils/recursive-parser.test.js index 9d090f7390c..5a678eb796b 100644 --- a/packages/utils/recursive-parser.test.js +++ b/packages/utils/recursive-parser.test.js @@ -2,26 +2,20 @@ const defineTest = require("./defineTest"); -defineTest( - __dirname, - "entry", - "fixture-1", - { - objects: "are", - super: [ - "yeah", - { - test: new RegExp(/\.(js|vue)$/), - loader: "'eslint-loader'", - enforce: "'pre'", - include: ["customObj", "'Stringy'"], - options: { - formatter: "'someOption'" - } +defineTest(__dirname, "init", "fixture-1", "entry", { + objects: "are", + super: [ + "yeah", + { + test: new RegExp(/\.(js|vue)$/), + loader: "'eslint-loader'", + enforce: "'pre'", + include: ["customObj", "'Stringy'"], + options: { + formatter: "'someOption'" } - ], - nice: "':)'", - man: "() => duper" - }, - "init" -); + } + ], + nice: "':)'", + man: "() => duper" +});