Skip to content

Commit

Permalink
feat(webpack-cli): add mode argument validation
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Mar 4, 2020
1 parent a069d73 commit 430c6ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { logger } = require('@webpack-cli/logger');
const HELP_GROUP = 'help';
const CONFIG_GROUP = 'config';
const BASIC_GROUP = 'basic';
Expand Down Expand Up @@ -286,11 +287,17 @@ module.exports = {
{
name: 'mode',
usage: '--mode <development | production>',
type: String,
type: (value) => {
if (value === 'development' || value === 'production' || value === 'none') {
return value ;
} else {
logger.warn('You provided an invalid value for "mode" option.');
return 'production' ;
}
},
group: ZERO_CONFIG_GROUP,
description: 'Defines the mode to pass to webpack',
link: 'https://webpack.js.org/concepts/#mode',
acceptedValues: ["development", "production"]
link: 'https://webpack.js.org/concepts/#mode'
},
{
name: 'no-mode',
Expand Down
2 changes: 1 addition & 1 deletion test/help/__snapshots__/help-single-arg.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Options
--standard Prints standard output
-d, --dev Run development build
-p, --prod Run production build
--mode string Defines the mode to pass to webpack
--mode type Defines the mode to pass to webpack
--no-mode Sets mode="none" which disables any default behavior
--version Get current version
--node-args string[] NodeJS flags
Expand Down

0 comments on commit 430c6ff

Please sign in to comment.