From d67f4b7c87d8aee03782d43ef260351d05c11676 Mon Sep 17 00:00:00 2001 From: kingdaro Date: Fri, 26 Jan 2018 11:18:11 -0500 Subject: [PATCH] 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 --- bin/webpack.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/webpack.js b/bin/webpack.js index 4fc97f889b4..c96ad41ef91 100644 --- a/bin/webpack.js +++ b/bin/webpack.js @@ -196,12 +196,6 @@ "Controls the output of lifecycle messaging e.g. Started watching files... (verbose, info, none)" } }); - - if (yargs.argv._.length === 0) { - yargs.showHelp(); - return; - } - // 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 @@ -465,9 +459,12 @@ if (err) { lastHash = null; console.error(err.stack || err); - if (err.details) console.error(err.details); - process.exit(1); // eslint-disable-line + if (err.details) { + console.error(err.details); + } + process.exit(1); } + if (outputOptions.json) { stdout.write( JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n" @@ -477,10 +474,20 @@ var statsString = stats.toString(outputOptions); if (statsString) stdout.write(statsString + "\n"); } + if (!options.watch && stats.hasErrors()) { process.exitCode = 2; + + const fs = require("fs"); + const context = stats.compilation.compiler.context; + const configPath = context + "/webpack.config.js"; + const configMissing = !fs.existsSync(configPath); + if (yargs.argv._.length === 0 && configMissing) { + yargs.showHelp("log"); + } } } + if (firstOptions.watch || options.watch) { var watchOptions = firstOptions.watchOptions || @@ -496,7 +503,9 @@ compiler.watch(watchOptions, compilerCallback); if (outputOptions.infoVerbosity !== "none") console.log("\nWebpack is watching the files…\n"); - } else compiler.run(compilerCallback); + } else { + compiler.run(compilerCallback); + } } processOptions(options);