Skip to content

Commit 1daa844

Browse files
committed
add check for validation errors top stop normal cli flow
see webpack#5345
1 parent 0c57254 commit 1daa844

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

‎bin/convert-argv.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ var interpret = require("interpret");
55
var prepareOptions = require("../lib/prepareOptions");
66

77
module.exports = function(yargs, argv, convertOptions) {
8-
if (argv["help"] === true || argv["version"] === true) {
9-
return {exitByHelpOrVersion: true};
8+
if(argv["help"] === true || argv["version"] === true) {
9+
return { exitByHelpOrVersion: true };
1010
}
1111

1212
var options = [];

‎bin/webpack.js‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,24 @@ yargs.options({
146146
}
147147
});
148148

149-
var argv = yargs.argv;
149+
var validationErrorOcurred = false;
150+
var options = {};
151+
try {
152+
var argv = yargs.argv;
150153

151-
if(argv.verbose) {
152-
argv["display"] = "verbose";
153-
}
154+
if(argv.verbose) {
155+
argv["display"] = "verbose";
156+
}
154157

155-
var options = require("./convert-argv")(yargs, argv);
158+
options = require("./convert-argv")(yargs, argv);
159+
} catch(e) {
160+
var YError = require("yargs/lib/yerror");
161+
if(e instanceof YError) {
162+
validationErrorOcurred = true;
163+
} else {
164+
throw e;
165+
}
166+
}
156167

157168
function ifArg(name, fn, init) {
158169
if(Array.isArray(argv[name])) {
@@ -375,7 +386,7 @@ function processOptions(options) {
375386
// To prevent this we configure yargs with .exitProcess(false).
376387
// However, we need to prevent processOptions and convert-argv from causing errorneous results,
377388
// so we only parse inputs if help or version was not called.
378-
if (!options.exitByHelpOrVersion) {
389+
if(!options.exitByHelpOrVersion && !validationErrorOcurred) {
379390
processOptions(options);
380391
}
381392

0 commit comments

Comments
 (0)