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

feat(webpack-cli): add --no-stats flag #1654

Merged
merged 4 commits into from
Jun 29, 2020
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
1 change: 1 addition & 0 deletions packages/webpack-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Options
-v, --version Get current version
--node-args string[] NodeJS flags
--stats string It instructs webpack on how to treat the stats
--no-stats Disables stats output
--verbose It tells webpack to output all the information
```

Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/groups/StatsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const logger = require('../utils/logger');
*/
class StatsGroup extends GroupHelper {
static validOptions() {
return ['none', 'errors-only', 'minimal', 'normal', 'detailed', 'verbose', 'errors-warnings', true];
return ['none', 'errors-only', 'minimal', 'normal', 'detailed', 'verbose', 'errors-warnings', true, false];
}

constructor(options) {
Expand Down
8 changes: 8 additions & 0 deletions packages/webpack-cli/lib/utils/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,14 @@ module.exports = {
description: 'It instructs webpack on how to treat the stats e.g. verbose',
link: 'https://webpack.js.org/configuration/stats/#stats',
},
{
name: 'no-stats',
usage: '--no-stats',
type: Boolean,
group: DISPLAY_GROUP,
description: 'Disables stats output',
link: 'https://webpack.js.org/configuration/stats/#stats',
},
{
name: 'verbose',
usage: '--verbose',
Expand Down
4 changes: 4 additions & 0 deletions test/no-stats/with-config/a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('url');
require('path');

console.log('--no-stats with config test');
29 changes: 29 additions & 0 deletions test/no-stats/with-config/no-stats-with-config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
// eslint-disable-next-line node/no-unpublished-require
const { run } = require('../../utils/test-utils');
// eslint-disable-next-line node/no-extraneous-require
const { version } = require('webpack');

describe('stats flag', () => {
it(`should use stats 'detailed' as defined in webpack config`, () => {
const { stderr, stdout } = run(__dirname, []);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'detailed' }`);
} else {
expect(stdout).toContain(`stats: 'detailed'`);
}
});

it(`should use --no-stats and override value in config`, () => {
const { stderr, stdout } = run(__dirname, ['--no-stats']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain(`stats: false`);
}
});
});
9 changes: 9 additions & 0 deletions test/no-stats/with-config/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// eslint-disable-next-line node/no-unpublished-require
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
entry: './main.js',
stats: 'detailed',
plugins: [new WebpackCLITestPlugin()],
};
4 changes: 4 additions & 0 deletions test/no-stats/with-flags/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require('url');
require('path');

console.log('--no-stats test');
51 changes: 51 additions & 0 deletions test/no-stats/with-flags/no-stats.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';
// eslint-disable-next-line node/no-unpublished-require
const { run } = require('../../utils/test-utils');
// eslint-disable-next-line node/no-extraneous-require
const { version } = require('webpack');

describe('stats flag', () => {
it('should accept --no-stats as boolean', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain('stats: false');
}
});

it('should warn and use --no-stats when stats and no-stats both are provided', () => {
const { stderr, stdout } = run(__dirname, ['--stats', 'verbose', '--no-stats']);

expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`);
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'none' }`);
} else {
expect(stdout).toContain('stats: false');
}
});

it('should warn and use --stats when stats and no-stats both are provided', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats', '--stats', 'verbose']);

expect(stderr).toContain(`You provided both --stats and --no-stats. We will use only the last of these flags`);
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'verbose' }`);
} else {
expect(stdout).toContain(`stats: 'verbose'`);
}
});

it('should use --verbose over --no-stats', () => {
const { stderr, stdout } = run(__dirname, ['--no-stats', '--verbose']);

expect(stderr).toBeFalsy();
if (version.startsWith('5')) {
expect(stdout).toContain(`stats: { preset: 'verbose' }`);
} else {
expect(stdout).toContain(`stats: 'verbose'`);
}
});
});
8 changes: 8 additions & 0 deletions test/no-stats/with-flags/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// eslint-disable-next-line node/no-unpublished-require
const WebpackCLITestPlugin = require('../../utils/webpack-cli-test-plugin');

module.exports = {
mode: 'development',
entry: './main.js',
plugins: [new WebpackCLITestPlugin()],
};