From 2250af02f639505938cafd4b28cd856aaf60d6d0 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Fri, 26 Apr 2019 11:47:37 +0530 Subject: [PATCH 01/11] fix(cli): error when no webpack and args found trows an error when webpack is not installed and no args passed to the cli --- bin/cli.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index aa7df4c2d9c..54d28553174 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -71,7 +71,12 @@ For more information, see https://webpack.js.org/api/cli/.`); options = require("./utils/convert-argv")(argv); } catch (err) { if (err.name !== "ValidationError") { - throw err; + console.error("\n\u001b[1m\u001b[31mWebpack not found, please install webpack"); + console.error( + "\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n" + ); + process.exitCode = 1; + return; } const stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message); @@ -93,7 +98,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout; From ff263f95ce7b4b87f69598a0e1cba0ef68b9193d Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Fri, 26 Apr 2019 11:53:12 +0530 Subject: [PATCH 02/11] chore(cli): fixes code indentation fixed spacing issues --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 54d28553174..e9a2b5b7410 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -98,7 +98,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout; From cc649559f7bd42c4ce00fdeb765f0e356b20f2d8 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 27 Apr 2019 01:28:31 +0530 Subject: [PATCH 03/11] fix(cli): improves error handling with args tells user to install webpack in order for futher procedures --- bin/cli.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index e9a2b5b7410..e566881ee43 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -70,15 +70,19 @@ For more information, see https://webpack.js.org/api/cli/.`); try { options = require("./utils/convert-argv")(argv); } catch (err) { - if (err.name !== "ValidationError") { - console.error("\n\u001b[1m\u001b[31mWebpack not found, please install webpack"); + // When webpack is not installed and no args passed to the CLI + if (err.code === "MODULE_NOT_FOUND" && err.message === "Cannot find module 'webpack-sources'") { console.error( - "\u001b[1m\u001b[31mAlternatively, run 'webpack(-cli) --help' for usage info.\u001b[39m\u001b[22m\n" + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n" ); - process.exitCode = 1; + return; } + if (err.name !== "ValidationError") { + throw err; + } + const stack = ErrorHelpers.cleanUpWebpackOptions(err.stack, err.message); const message = err.message + "\n" + stack; From a3ce273a97810ea115e8ab42a1c77d806a0e9776 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 27 Apr 2019 15:44:27 +0530 Subject: [PATCH 04/11] fix(cli): shows error message based on package manager shows different error message based on package manager --- bin/cli.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index e566881ee43..3f0a7503390 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -71,11 +71,18 @@ For more information, see https://webpack.js.org/api/cli/.`); options = require("./utils/convert-argv")(argv); } catch (err) { // When webpack is not installed and no args passed to the CLI - if (err.code === "MODULE_NOT_FOUND" && err.message === "Cannot find module 'webpack-sources'") { - console.error( - "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n" - ); + if (err.code === "MODULE_NOT_FOUND") { + let errorMessage = + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"; + + if (process.env.npm_execpath !== undefined) { + if (process.env.npm_execpath.indexOf("yarn") !== -1) { + errorMessage = + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n"; + } + } + console.error(errorMessage); return; } From a9bc0bd913080ddf6a48f99c72ac2b0d3ec83169 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Tue, 14 May 2019 18:07:27 +0530 Subject: [PATCH 05/11] fix(cli): err when no args passed, refactored nested conditional blocks combined nested conditional blocks into one --- bin/cli.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index d16f48efd55..4bab14a192a 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -75,11 +75,9 @@ For more information, see https://webpack.js.org/api/cli/.`); let errorMessage = "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"; - if (process.env.npm_execpath !== undefined) { - if (process.env.npm_execpath.indexOf("yarn") !== -1) { - errorMessage = - "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n"; - } + if (process.env.npm_execpath !== undefined && process.env.npm_execpath.includes("yarn")) { + errorMessage = + "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n"; } console.error(errorMessage); @@ -109,7 +107,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout; @@ -342,19 +340,14 @@ For more information, see https://webpack.js.org/api/cli/.`); const SIX_DAYS = 518400000; const now = new Date(); if (now.getDay() === MONDAY) { - const { - access, - constants, - statSync, - utimesSync, - } = require("fs"); + const { access, constants, statSync, utimesSync } = require("fs"); const lastPrint = statSync(openCollectivePath).atime; const lastPrintTS = new Date(lastPrint).getTime(); const timeSinceLastPrint = now.getTime() - lastPrintTS; if (timeSinceLastPrint > SIX_DAYS) { require(openCollectivePath); // On windows we need to manually update the atime - access(openCollectivePath, constants.W_OK, (e) => { + access(openCollectivePath, constants.W_OK, e => { if (!e) utimesSync(openCollectivePath, now, now); }); } From cfc011778138e90568d78d4c0efd5c61ea68c577 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Tue, 14 May 2019 19:01:13 +0530 Subject: [PATCH 06/11] fix(ci): fixes linting error in ci fixed linting error --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 4bab14a192a..64208689099 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -107,7 +107,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout; From 869024fa60bc21150104b3a33ba4e3e0886be433 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Thu, 30 May 2019 22:25:10 +0530 Subject: [PATCH 07/11] fix(cli): sets stack trace limit modified the default stack trace limit and made cli to exit with exit code 1 when no args passed and webpack is not installed --- bin/cli.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 74a932783b5..ea72c7700e3 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -73,14 +73,16 @@ For more information, see https://webpack.js.org/api/cli/.`); // When webpack is not installed and no args passed to the CLI if (err.code === "MODULE_NOT_FOUND") { let errorMessage = - "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33mnpm install --save-dev webpack\n"; + "\n\u001b[31mwebpack not found, \u001b[33mplease install webpack using\n\t\u001b[32mnpm install --save-dev webpack\n"; if (process.env.npm_execpath !== undefined && process.env.npm_execpath.includes("yarn")) { errorMessage = - "\n\u001b[31mwebpack not found, please install webpack using\n\t\u001b[33myarn add webpack --dev\n"; + "\n\u001b[31mwebpack not found, \u001b[33mplease install webpack using\n\t\u001b[32myarn add webpack --dev\n"; } console.error(errorMessage); + Error.stackTraceLimit = 1; + process.exitCode = 1; return; } From 7d31321fb27c80dc21ee99e0ba92ca448860c739 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Fri, 31 May 2019 00:01:38 +0530 Subject: [PATCH 08/11] fix(cli): removes func return in catch instance removes the return statement from the catch block --- bin/cli.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index ea72c7700e3..035f98f26fc 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -83,7 +83,6 @@ For more information, see https://webpack.js.org/api/cli/.`); console.error(errorMessage); Error.stackTraceLimit = 1; process.exitCode = 1; - return; } if (err.name !== "ValidationError") { From ac5a53f2d64cd45e1de119b2636dcf184284f912 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Fri, 31 May 2019 20:56:55 +0530 Subject: [PATCH 09/11] fix(cli): removes the comment before err handling block removed the comment as per the suggestions by even --- bin/cli.js | 1 - 1 file changed, 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 035f98f26fc..3172e6930d1 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -70,7 +70,6 @@ For more information, see https://webpack.js.org/api/cli/.`); try { options = require("./utils/convert-argv")(argv); } catch (err) { - // When webpack is not installed and no args passed to the CLI if (err.code === "MODULE_NOT_FOUND") { let errorMessage = "\n\u001b[31mwebpack not found, \u001b[33mplease install webpack using\n\t\u001b[32mnpm install --save-dev webpack\n"; From b5e19139c8c33d396778f35f2fdf088fbd44f3d2 Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 1 Jun 2019 21:47:38 +0530 Subject: [PATCH 10/11] fix(cli): updates err message updates the err message --- bin/cli.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 3172e6930d1..47a29643138 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -72,16 +72,17 @@ For more information, see https://webpack.js.org/api/cli/.`); } catch (err) { if (err.code === "MODULE_NOT_FOUND") { let errorMessage = - "\n\u001b[31mwebpack not found, \u001b[33mplease install webpack using\n\t\u001b[32mnpm install --save-dev webpack\n"; + "\n\u001b[31mwebpack not installed, consider installing it using \n\u001b[32mnpm install --save-dev webpack\n"; if (process.env.npm_execpath !== undefined && process.env.npm_execpath.includes("yarn")) { errorMessage = - "\n\u001b[31mwebpack not found, \u001b[33mplease install webpack using\n\t\u001b[32myarn add webpack --dev\n"; + "\n\u001b[31mwebpack not installed, consider installing it using \n\u001b[32myarn add webpack --dev\n"; } console.error(errorMessage); Error.stackTraceLimit = 1; process.exitCode = 1; + return; } if (err.name !== "ValidationError") { @@ -107,7 +108,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout; From 9f1deb2a85aaa1f98670065415c2461fd06544df Mon Sep 17 00:00:00 2001 From: Pranshu Chittora Date: Sat, 1 Jun 2019 21:52:24 +0530 Subject: [PATCH 11/11] chore(cli): fixes linting err fixes the linting err --- bin/cli.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/cli.js b/bin/cli.js index 47a29643138..bed161abea6 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -108,7 +108,7 @@ For more information, see https://webpack.js.org/api/cli/.`); */ const stdout = argv.silent ? { - write: () => {} + write: () => {} } // eslint-disable-line : process.stdout;