Skip to content

Commit d67f4b7

Browse files
author
kingdaro
committed
fix: change help logic
makes it so help is shown when the webpack build fails and there is no webpack.config.js possibly hide the build failing error as well? also consider showing additional information about the default configuration
1 parent 7be0da7 commit d67f4b7

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

bin/webpack.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,6 @@
196196
"Controls the output of lifecycle messaging e.g. Started watching files... (verbose, info, none)"
197197
}
198198
});
199-
200-
if (yargs.argv._.length === 0) {
201-
yargs.showHelp();
202-
return;
203-
}
204-
205199
// yargs will terminate the process early when the user uses help or version.
206200
// This causes large help outputs to be cut short (https://github.com/nodejs/node/wiki/API-changes-between-v0.10-and-v4#process).
207201
// To prevent this we use the yargs.parse API and exit the process normally
@@ -465,9 +459,12 @@
465459
if (err) {
466460
lastHash = null;
467461
console.error(err.stack || err);
468-
if (err.details) console.error(err.details);
469-
process.exit(1); // eslint-disable-line
462+
if (err.details) {
463+
console.error(err.details);
464+
}
465+
process.exit(1);
470466
}
467+
471468
if (outputOptions.json) {
472469
stdout.write(
473470
JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n"
@@ -477,10 +474,20 @@
477474
var statsString = stats.toString(outputOptions);
478475
if (statsString) stdout.write(statsString + "\n");
479476
}
477+
480478
if (!options.watch && stats.hasErrors()) {
481479
process.exitCode = 2;
480+
481+
const fs = require("fs");
482+
const context = stats.compilation.compiler.context;
483+
const configPath = context + "/webpack.config.js";
484+
const configMissing = !fs.existsSync(configPath);
485+
if (yargs.argv._.length === 0 && configMissing) {
486+
yargs.showHelp("log");
487+
}
482488
}
483489
}
490+
484491
if (firstOptions.watch || options.watch) {
485492
var watchOptions =
486493
firstOptions.watchOptions ||
@@ -496,7 +503,9 @@
496503
compiler.watch(watchOptions, compilerCallback);
497504
if (outputOptions.infoVerbosity !== "none")
498505
console.log("\nWebpack is watching the files…\n");
499-
} else compiler.run(compilerCallback);
506+
} else {
507+
compiler.run(compilerCallback);
508+
}
500509
}
501510

502511
processOptions(options);

0 commit comments

Comments
 (0)