From e5e8d9f540026f22bccc64cee971e8448802186b Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 21 Mar 2019 15:00:30 +0530 Subject: [PATCH 1/6] chore(cli): move constants to a separate file moved all constants to a separate file for CLI scopre and imported from there. ISSUES CLOSED: #772 --- bin/cli.js | 14 ++++---------- bin/config/config-yargs.js | 11 +++-------- bin/constants.js | 28 ++++++++++++++++++++++++++++ bin/utils/errorHelpers.js | 2 +- 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 bin/constants.js diff --git a/bin/cli.js b/bin/cli.js index 9a34f7e6f7f..47bf3f39029 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -18,17 +18,10 @@ const ErrorHelpers = require("./utils/errorHelpers"); - const NON_COMPILATION_ARGS = [ - "init", - "migrate", - "add", - "remove", - "serve", - "generate-loader", - "generate-plugin", - "info" - ]; + const { NON_COMPILATION_ARGS } = require("./constants") + + console.log(NON_COMPILATION_ARGS) const NON_COMPILATION_CMD = process.argv.find(arg => { if (arg === "serve") { global.process.argv = global.process.argv.filter(a => a !== "serve"); @@ -131,6 +124,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const statsPresetToOptions = require("webpack").Stats.presetToOptions; let outputOptions = options.stats; + console.log(outputOptions) if (typeof outputOptions === "boolean" || typeof outputOptions === "string") { outputOptions = statsPresetToOptions(outputOptions); } else if (!outputOptions) { diff --git a/bin/config/config-yargs.js b/bin/config/config-yargs.js index 19a3c489e68..0487e93795c 100644 --- a/bin/config/config-yargs.js +++ b/bin/config/config-yargs.js @@ -52,14 +52,9 @@ const getSchemaInfo = (path, property, subProperty) => { return findPropertyInSchema(current, property, subProperty); }; -const CONFIG_GROUP = "Config options:"; -const BASIC_GROUP = "Basic options:"; -const MODULE_GROUP = "Module options:"; -const OUTPUT_GROUP = "Output options:"; -const ADVANCED_GROUP = "Advanced options:"; -const RESOLVE_GROUP = "Resolving options:"; -const OPTIMIZE_GROUP = "Optimizing options:"; -const DISPLAY_GROUP = "Stats options:"; +const { GROUPS } = require("../constants"); + +const { CONFIG_GROUP, BASIC_GROUP, MODULE_GROUP, OUTPUT_GROUP, ADVANCED_GROUP, RESOLVE_GROUP, OPTIMIZE_GROUP, DISPLAY_GROUP } = GROUPS; module.exports = function(yargs) { yargs diff --git a/bin/constants.js b/bin/constants.js new file mode 100644 index 00000000000..7ccb96d78a3 --- /dev/null +++ b/bin/constants.js @@ -0,0 +1,28 @@ +const NON_COMPILATION_ARGS = [ + "init", + "migrate", + "add", + "remove", + "serve", + "generate-loader", + "generate-plugin", + "info" +]; + +const CONFIG_GROUP = "Config options:"; +const BASIC_GROUP = "Basic options:"; +const MODULE_GROUP = "Module options:"; +const OUTPUT_GROUP = "Output options:"; +const ADVANCED_GROUP = "Advanced options:"; +const RESOLVE_GROUP = "Resolving options:"; +const OPTIMIZE_GROUP = "Optimizing options:"; +const DISPLAY_GROUP = "Stats options:"; +const GROUPS = { CONFIG_GROUP, BASIC_GROUP, MODULE_GROUP, OUTPUT_GROUP, ADVANCED_GROUP, RESOLVE_GROUP, OPTIMIZE_GROUP, DISPLAY_GROUP } + +const webpackOptionsFlag = "WEBPACK_OPTIONS"; + +module.exports = { + NON_COMPILATION_ARGS, + GROUPS, + webpackOptionsFlag, +} \ No newline at end of file diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index 5098f4ca14d..f3f7e5df228 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const webpackOptionsFlag = "WEBPACK_OPTIONS"; +const { webpackOptionsFlag } = require('../constants') exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n"); From ee04bead48750d1cab56858327989a9caa32d1f3 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 21 Mar 2019 15:04:26 +0530 Subject: [PATCH 2/6] chore(cli): lint files, rm console.log Format all code using prettier, remove console.log ISSUES CLOSED: #772 --- bin/cli.js | 9 +++------ bin/constants.js | 19 ++++++++++++++----- bin/opencollective.js | 6 +++++- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 47bf3f39029..ee4aa696550 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -18,10 +18,8 @@ const ErrorHelpers = require("./utils/errorHelpers"); - const { NON_COMPILATION_ARGS } = require("./constants") + const { NON_COMPILATION_ARGS } = require("./constants"); - - console.log(NON_COMPILATION_ARGS) const NON_COMPILATION_CMD = process.argv.find(arg => { if (arg === "serve") { global.process.argv = global.process.argv.filter(a => a !== "serve"); @@ -45,7 +43,6 @@ For more information, see https://webpack.js.org/api/cli/.`); require("./config/config-yargs")(yargs); - // yargs will terminate the process early when the user uses help or version. // This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process). // To prevent this we use the yargs.parse API and exit the process normally @@ -97,7 +94,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const stdout = argv.silent ? { write: () => {} - } // eslint-disable-line + } // eslint-disable-line : process.stdout; function ifArg(name, fn, init) { @@ -124,7 +121,7 @@ For more information, see https://webpack.js.org/api/cli/.`); const statsPresetToOptions = require("webpack").Stats.presetToOptions; let outputOptions = options.stats; - console.log(outputOptions) + console.log(outputOptions); if (typeof outputOptions === "boolean" || typeof outputOptions === "string") { outputOptions = statsPresetToOptions(outputOptions); } else if (!outputOptions) { diff --git a/bin/constants.js b/bin/constants.js index 7ccb96d78a3..d08b42cac9c 100644 --- a/bin/constants.js +++ b/bin/constants.js @@ -17,12 +17,21 @@ const ADVANCED_GROUP = "Advanced options:"; const RESOLVE_GROUP = "Resolving options:"; const OPTIMIZE_GROUP = "Optimizing options:"; const DISPLAY_GROUP = "Stats options:"; -const GROUPS = { CONFIG_GROUP, BASIC_GROUP, MODULE_GROUP, OUTPUT_GROUP, ADVANCED_GROUP, RESOLVE_GROUP, OPTIMIZE_GROUP, DISPLAY_GROUP } +const GROUPS = { + CONFIG_GROUP, + BASIC_GROUP, + MODULE_GROUP, + OUTPUT_GROUP, + ADVANCED_GROUP, + RESOLVE_GROUP, + OPTIMIZE_GROUP, + DISPLAY_GROUP +}; const webpackOptionsFlag = "WEBPACK_OPTIONS"; module.exports = { - NON_COMPILATION_ARGS, - GROUPS, - webpackOptionsFlag, -} \ No newline at end of file + NON_COMPILATION_ARGS, + GROUPS, + webpackOptionsFlag +}; diff --git a/bin/opencollective.js b/bin/opencollective.js index a6266a25b4e..16207dc7575 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -26,7 +26,11 @@ function printBadge() { print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`); print("to help us maintain this package."); console.log("\n\n"); - print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`); + print( + `${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow( + "https://opencollective.com/webpack/donate" + )}` + ); console.log("\n"); } From bada5f54e27665d89545566c8d5a165c42161a0e Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 21 Mar 2019 15:17:23 +0530 Subject: [PATCH 3/6] chore(cli): codacy fix codacy fix --- bin/utils/errorHelpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index f3f7e5df228..d5096042a7f 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const { webpackOptionsFlag } = require('../constants') +const { webpackOptionsFlag } = require("../constants"); exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n"); From fb8f4205cda4a5a6d9ec6de4cee21795a92fd907 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Thu, 21 Mar 2019 16:05:19 +0530 Subject: [PATCH 4/6] chore(cli): split destructuring into multiple lines split constants destructuring to multiple lines in config-yargs --- bin/config/config-yargs.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/config/config-yargs.js b/bin/config/config-yargs.js index 0487e93795c..3db49f43946 100644 --- a/bin/config/config-yargs.js +++ b/bin/config/config-yargs.js @@ -54,7 +54,16 @@ const getSchemaInfo = (path, property, subProperty) => { const { GROUPS } = require("../constants"); -const { CONFIG_GROUP, BASIC_GROUP, MODULE_GROUP, OUTPUT_GROUP, ADVANCED_GROUP, RESOLVE_GROUP, OPTIMIZE_GROUP, DISPLAY_GROUP } = GROUPS; +const { + CONFIG_GROUP, + BASIC_GROUP, + MODULE_GROUP, + OUTPUT_GROUP, + ADVANCED_GROUP, + RESOLVE_GROUP, + OPTIMIZE_GROUP, + DISPLAY_GROUP +} = GROUPS; module.exports = function(yargs) { yargs From 350bc644a9cea8655887b973c14fa26bb7266e8f Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Fri, 22 Mar 2019 03:49:32 +0530 Subject: [PATCH 5/6] chore(cli): update var name, revert oc update var name, revert oc --- bin/cli.js | 5 ++--- bin/constants.js | 4 ++-- bin/opencollective.js | 6 +----- bin/utils/errorHelpers.js | 4 ++-- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index ee4aa696550..b278d5f673e 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -5,6 +5,8 @@ Author Tobias Koppers @sokra */ +const { NON_COMPILATION_ARGS } = require("./constants"); + (function() { // wrap in IIFE to be able to use return @@ -18,8 +20,6 @@ const ErrorHelpers = require("./utils/errorHelpers"); - const { NON_COMPILATION_ARGS } = require("./constants"); - const NON_COMPILATION_CMD = process.argv.find(arg => { if (arg === "serve") { global.process.argv = global.process.argv.filter(a => a !== "serve"); @@ -121,7 +121,6 @@ For more information, see https://webpack.js.org/api/cli/.`); const statsPresetToOptions = require("webpack").Stats.presetToOptions; let outputOptions = options.stats; - console.log(outputOptions); if (typeof outputOptions === "boolean" || typeof outputOptions === "string") { outputOptions = statsPresetToOptions(outputOptions); } else if (!outputOptions) { diff --git a/bin/constants.js b/bin/constants.js index d08b42cac9c..28a36c88a74 100644 --- a/bin/constants.js +++ b/bin/constants.js @@ -28,10 +28,10 @@ const GROUPS = { DISPLAY_GROUP }; -const webpackOptionsFlag = "WEBPACK_OPTIONS"; +const WEBPACK_OPTIONS_FLAG = "WEBPACK_OPTIONS"; module.exports = { NON_COMPILATION_ARGS, GROUPS, - webpackOptionsFlag + WEBPACK_OPTIONS_FLAG }; diff --git a/bin/opencollective.js b/bin/opencollective.js index 16207dc7575..a6266a25b4e 100644 --- a/bin/opencollective.js +++ b/bin/opencollective.js @@ -26,11 +26,7 @@ function printBadge() { print(`Please consider donating to our ${chalk.bold.blue("Open Collective")}`); print("to help us maintain this package."); console.log("\n\n"); - print( - `${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow( - "https://opencollective.com/webpack/donate" - )}` - ); + print(`${emoji("👉")} ${chalk.bold.yellow(" Donate:")} ${chalk.reset.underline.yellow("https://opencollective.com/webpack/donate")}`); console.log("\n"); } diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index d5096042a7f..4746e573509 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const { webpackOptionsFlag } = require("../constants"); +const { WEBPACK_OPTIONS_FLAG } = require("../constants"); exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n"); @@ -12,7 +12,7 @@ exports.cutOffByFlag = (stack, flag) => { return stack.join("\n"); }; -exports.cutOffWebpackOptions = stack => exports.cutOffByFlag(stack, webpackOptionsFlag); +exports.cutOffWebpackOptions = stack => exports.cutOffByFlag(stack, WEBPACK_OPTIONS_FLAG); exports.cutOffMultilineMessage = (stack, message) => { stack = stack.split("\n"); From 927e3f975babee8fba398fdb6dcfd10e6ec96bec Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Fri, 22 Mar 2019 11:02:03 +0530 Subject: [PATCH 6/6] chore(cli): moved constants to utils moved constants to utils directory --- bin/cli.js | 2 +- bin/config/config-yargs.js | 26 +++++++++++++------------- bin/{ => utils}/constants.js | 0 bin/utils/errorHelpers.js | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) rename bin/{ => utils}/constants.js (100%) diff --git a/bin/cli.js b/bin/cli.js index b278d5f673e..aa7df4c2d9c 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -5,7 +5,7 @@ Author Tobias Koppers @sokra */ -const { NON_COMPILATION_ARGS } = require("./constants"); +const { NON_COMPILATION_ARGS } = require("./utils/constants"); (function() { // wrap in IIFE to be able to use return diff --git a/bin/config/config-yargs.js b/bin/config/config-yargs.js index 3db49f43946..105358875a7 100644 --- a/bin/config/config-yargs.js +++ b/bin/config/config-yargs.js @@ -1,5 +1,18 @@ const optionsSchema = require("../config/optionsSchema.json"); +const { GROUPS } = require("../utils/constants"); + +const { + CONFIG_GROUP, + BASIC_GROUP, + MODULE_GROUP, + OUTPUT_GROUP, + ADVANCED_GROUP, + RESOLVE_GROUP, + OPTIMIZE_GROUP, + DISPLAY_GROUP +} = GROUPS; + const nestedProperties = ["anyOf", "oneOf", "allOf"]; const resolveSchema = schema => { @@ -52,19 +65,6 @@ const getSchemaInfo = (path, property, subProperty) => { return findPropertyInSchema(current, property, subProperty); }; -const { GROUPS } = require("../constants"); - -const { - CONFIG_GROUP, - BASIC_GROUP, - MODULE_GROUP, - OUTPUT_GROUP, - ADVANCED_GROUP, - RESOLVE_GROUP, - OPTIMIZE_GROUP, - DISPLAY_GROUP -} = GROUPS; - module.exports = function(yargs) { yargs .help("help") diff --git a/bin/constants.js b/bin/utils/constants.js similarity index 100% rename from bin/constants.js rename to bin/utils/constants.js diff --git a/bin/utils/errorHelpers.js b/bin/utils/errorHelpers.js index 4746e573509..96fe950f34d 100644 --- a/bin/utils/errorHelpers.js +++ b/bin/utils/errorHelpers.js @@ -4,7 +4,7 @@ */ "use strict"; -const { WEBPACK_OPTIONS_FLAG } = require("../constants"); +const { WEBPACK_OPTIONS_FLAG } = require("./constants"); exports.cutOffByFlag = (stack, flag) => { stack = stack.split("\n");