Skip to content

Commit

Permalink
fix: change help logic
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kingdaro committed Jan 26, 2018
1 parent 7be0da7 commit d67f4b7
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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 ||
Expand All @@ -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);
Expand Down

0 comments on commit d67f4b7

Please sign in to comment.