Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] --silent #241

Merged
merged 1 commit into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions bin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
var BASIC_GROUP = "Basic options:";

yargs.options({
silent: {
type: "boolean",
describe: "Prevent output from being displayed in stdout"
},
json: {
type: "boolean",
alias: "j",
Expand Down Expand Up @@ -229,6 +233,14 @@
return;
}

/**
* When --silent flag is present, an object with a no-op write method is
* used in place of process.stout
*/
var stdout = argv.silent ? {
write: () => {}
} : process.stdout;

function ifArg(name, fn, init) {
if (Array.isArray(argv[name])) {
if (init) init();
Expand Down Expand Up @@ -423,13 +435,13 @@
process.exit(1); // eslint-disable-line
}
if (outputOptions.json) {
process.stdout.write(
stdout.write(
JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n"
);
} else if (stats.hash !== lastHash) {
lastHash = stats.hash;
var statsString = stats.toString(outputOptions);
if (statsString) process.stdout.write(statsString + "\n");
if (statsString) stdout.write(statsString + "\n");
}
if (!options.watch && stats.hasErrors()) {
process.exitCode = 2;
Expand Down
1 change: 1 addition & 0 deletions test/binCases/silent/silent-output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "foo";
1 change: 1 addition & 0 deletions test/binCases/silent/silent-output/index2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = "bar";
7 changes: 7 additions & 0 deletions test/binCases/silent/silent-output/stdin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

module.exports = function testAssertions(code, stdout, stderr) {
expect(code).toBe(0);
expect(stdout).toHaveLength(0);
expect(stderr).toHaveLength(0);
};
1 change: 1 addition & 0 deletions test/binCases/silent/silent-output/test.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--silent
17 changes: 17 additions & 0 deletions test/binCases/silent/silent-output/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var path = require("path");

module.exports = [
{
entry: path.resolve(__dirname, "./index"),
stats: "errors-only"
},
{
entry: path.resolve(__dirname, "./index2"),
stats: {
assets: true,
colors: true,
chunks: true,
maxModules: 0
}
}
];