Skip to content

Commit

Permalink
Revert "Revert "Show help on no command" (webpack#276)"
Browse files Browse the repository at this point in the history
This reverts commit 4079570.
  • Loading branch information
dhruvdutt authored Feb 23, 2018
1 parent 4079570 commit f9d6e61
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
22 changes: 18 additions & 4 deletions bin/webpack.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@
"Controls the output of lifecycle messaging e.g. Started watching files..."
}
});

// 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 +464,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 +479,20 @@
const 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) {
const watchOptions =
firstOptions.watchOptions ||
Expand All @@ -496,7 +508,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
16 changes: 16 additions & 0 deletions test/binCases/help/help-output-no-command/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(2);
expect(stdout).toEqual(expect.anything());
expect(stdout).toContain("Config options:");
expect(stdout).toContain("Basic options:");
expect(stdout).toContain("Module options:");
expect(stdout).toContain("Output options:");
expect(stdout).toContain("Advanced options:");
expect(stdout).toContain("Resolving options:");
expect(stdout).toContain("Optimizing options:");
expect(stdout).toContain("Stats options:");
expect(stdout).toContain("Options:");
expect(stderr).toHaveLength(0);
};
Empty file.

0 comments on commit f9d6e61

Please sign in to comment.