From a52c1dcc618502792118506709136a65d47ca0d5 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 25 Mar 2021 17:48:18 +0530 Subject: [PATCH 1/5] fix: generation of `negative` flags --- packages/webpack-cli/lib/webpack-cli.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index dcf8e8cff22..c89ce0c70e4 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -122,6 +122,7 @@ class WebpackCLI { if (option.configs) { let needNegativeOption = false; let mainOptionType = new Set(); + const isBuiltInFlag = this.builtInFlags.map(({ name }) => name).includes(option.name); option.configs.forEach((config) => { // Possible value: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset" @@ -130,8 +131,14 @@ class WebpackCLI { mainOptionType.add(Boolean); break; case 'boolean': - if (!needNegativeOption) { - needNegativeOption = true; + if (isBuiltInFlag) { + if (option.negative) { + needNegativeOption = true; + } + } else { + if (!needNegativeOption) { + needNegativeOption = true; + } } mainOptionType.add(Boolean); @@ -598,7 +605,7 @@ class WebpackCLI { }); this.builtInOptionsCache = options; - + this.builtInFlags = builtInFlags; return options; } From e5e378550bb37a3c99c234ddc9cbe508e9c2b707 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 25 Mar 2021 17:59:27 +0530 Subject: [PATCH 2/5] test: update --- packages/webpack-cli/lib/webpack-cli.js | 6 ++++- .../__snapshots__/help.test.js.snap.webpack5 | 24 ------------------- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index c89ce0c70e4..0d34ee7a495 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -122,7 +122,11 @@ class WebpackCLI { if (option.configs) { let needNegativeOption = false; let mainOptionType = new Set(); - const isBuiltInFlag = this.builtInFlags.map(({ name }) => name).includes(option.name); + let isBuiltInFlag = false; + + if (this.builtInFlags) { + isBuiltInFlag = this.builtInFlags.map(({ name }) => name).includes(option.name); + } option.configs.forEach((config) => { // Possible value: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset" diff --git a/test/help/__snapshots__/help.test.js.snap.webpack5 b/test/help/__snapshots__/help.test.js.snap.webpack5 index fea93d618b3..61e8d1048bc 100644 --- a/test/help/__snapshots__/help.test.js.snap.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.webpack5 @@ -69,13 +69,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. ./src/main.js. @@ -127,13 +124,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. ./src/main.js. @@ -185,13 +179,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. ./src/main.js. @@ -244,14 +235,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. @@ -421,14 +409,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. @@ -508,14 +493,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. @@ -558,13 +540,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. ./src/main.js. @@ -616,13 +595,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. -d, --devtool Determine source maps to use. --no-devtool Do not generate source maps. --entry The entry point(s) of your application e.g. ./src/main.js. From 1b27d2fc0c96698ef0e90ba3c2314f2e972c935b Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 25 Mar 2021 18:01:18 +0530 Subject: [PATCH 3/5] test: webpack-4 --- .../__snapshots__/help.test.js.snap.webpack4 | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/test/help/__snapshots__/help.test.js.snap.webpack4 b/test/help/__snapshots__/help.test.js.snap.webpack4 index 852d9ff1ff5..f53799dc9c0 100644 --- a/test/help/__snapshots__/help.test.js.snap.webpack4 +++ b/test/help/__snapshots__/help.test.js.snap.webpack4 @@ -69,13 +69,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. @@ -125,13 +122,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. @@ -181,13 +175,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. @@ -238,14 +229,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack @@ -413,14 +401,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack @@ -498,14 +483,11 @@ Options: --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack @@ -546,13 +528,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. @@ -602,13 +581,10 @@ Options: -c, --config Provide path to a webpack configuration file e.g. ./webpack.config.js. --config-name Name of the configuration to use. -m, --merge Merge two or more configurations using 'webpack-merge'. - --no-merge Negative 'merge' option. --env Environment passed to the configuration when it is a function. --node-env Sets process.env.NODE_ENV to the specified value. --progress [value] Print compilation progress during build. - --no-progress Negative 'progress' option. -j, --json [value] Prints result as JSON or store it in a file. - --no-json Negative 'json' option. --entry The entry point(s) of your application e.g. ./src/main.js. -o, --output-path Output location of the file generated by webpack e.g. ./dist/. -t, --target Sets the build target e.g. node. From 52cfbcb6913865f0737fb0c7384c6ac159f3f586 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 25 Mar 2021 17:43:53 +0300 Subject: [PATCH 4/5] refactor: code --- OPTIONS.md | 2 +- packages/webpack-cli/lib/webpack-cli.js | 29 ++++++++++--------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/OPTIONS.md b/OPTIONS.md index d0ddda43f04..f50337bd4d5 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -858,7 +858,7 @@ Commands: configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. - init|c [generation-path] [options] Initialize a new webpack project. + init|c [generation-path] [options] Initialize a new webpack configuration. loader|l [output-path] Scaffold a loader. migrate|m [new-config-path] Migrate a configuration to a new version. plugin|p [output-path] Scaffold a plugin. diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index 0d34ee7a495..29cf8751857 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -122,11 +122,6 @@ class WebpackCLI { if (option.configs) { let needNegativeOption = false; let mainOptionType = new Set(); - let isBuiltInFlag = false; - - if (this.builtInFlags) { - isBuiltInFlag = this.builtInFlags.map(({ name }) => name).includes(option.name); - } option.configs.forEach((config) => { // Possible value: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset" @@ -135,14 +130,8 @@ class WebpackCLI { mainOptionType.add(Boolean); break; case 'boolean': - if (isBuiltInFlag) { - if (option.negative) { - needNegativeOption = true; - } - } else { - if (!needNegativeOption) { - needNegativeOption = true; - } + if (!needNegativeOption) { + needNegativeOption = true; } mainOptionType.add(Boolean); @@ -374,7 +363,8 @@ class WebpackCLI { alias: 'm', configs: [ { - type: 'boolean', + type: 'enum', + values: [true], }, ], description: "Merge two or more configurations using 'webpack-merge'.", @@ -441,7 +431,8 @@ class WebpackCLI { name: 'analyze', configs: [ { - type: 'boolean', + type: 'enum', + values: [true], }, ], multiple: false, @@ -454,7 +445,8 @@ class WebpackCLI { type: 'string', }, { - type: 'boolean', + type: 'enum', + values: [true], }, ], description: 'Print compilation progress during build.', @@ -477,7 +469,8 @@ class WebpackCLI { type: 'string', }, { - type: 'boolean', + type: 'enum', + values: [true], }, ], alias: 'j', @@ -609,7 +602,7 @@ class WebpackCLI { }); this.builtInOptionsCache = options; - this.builtInFlags = builtInFlags; + return options; } From 21cf48af22cd4314b159368ab09ffe2913545f51 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Thu, 25 Mar 2021 18:11:19 +0300 Subject: [PATCH 5/5] refactor: update --- OPTIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OPTIONS.md b/OPTIONS.md index f50337bd4d5..d0ddda43f04 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -858,7 +858,7 @@ Commands: configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. - init|c [generation-path] [options] Initialize a new webpack configuration. + init|c [generation-path] [options] Initialize a new webpack project. loader|l [output-path] Scaffold a loader. migrate|m [new-config-path] Migrate a configuration to a new version. plugin|p [output-path] Scaffold a plugin.