Skip to content

Commit 5bae797

Browse files
refactor: migrate stats group (#1831)
* refactor: migrate stats group * refactor: migrate stats group Co-authored-by: Rishabh Chawla <rishabh31121999@gmail.com>
1 parent b363e44 commit 5bae797

6 files changed

Lines changed: 43 additions & 52 deletions

File tree

packages/webpack-cli/__tests__/StatsGroup.test.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const resolveStats = require('../lib/groups/resolveStats');
2+
3+
describe('StatsGroup', function () {
4+
it('should assign json correctly', () => {
5+
const result = resolveStats({
6+
json: true,
7+
});
8+
expect(result.options.stats).toBeFalsy();
9+
expect(result.outputOptions.json).toBeTruthy();
10+
});
11+
12+
it('should assign stats correctly', () => {
13+
const result = resolveStats({
14+
stats: 'warning',
15+
});
16+
expect(result.options.stats).toEqual('warning');
17+
expect(result.outputOptions.json).toBeFalsy();
18+
});
19+
});

packages/webpack-cli/lib/groups/StatsGroup.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Resolve flags which deal with compilation stats
3+
* @param {args} args - Parsed args passed to CLI
4+
*/
5+
const resolveStats = (args) => {
6+
const { stats, json } = args;
7+
8+
const finalOptions = {
9+
options: {},
10+
outputOptions: {},
11+
};
12+
13+
if (stats !== undefined) {
14+
finalOptions.options.stats = stats;
15+
}
16+
if (json) {
17+
finalOptions.outputOptions.json = true;
18+
}
19+
return finalOptions;
20+
};
21+
22+
module.exports = resolveStats;

packages/webpack-cli/lib/utils/cli-flags.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const CONFIG_GROUP = 'config';
55
const BASIC_GROUP = 'basic';
66
const OUTPUT_GROUP = 'output';
77
const ADVANCED_GROUP = 'advanced';
8-
const DISPLAY_GROUP = 'stats';
98
const ZERO_CONFIG_GROUP = 'zero-config';
109

1110
const groups = {
@@ -14,7 +13,6 @@ const groups = {
1413
BASIC_GROUP,
1514
OUTPUT_GROUP,
1615
ADVANCED_GROUP,
17-
DISPLAY_GROUP,
1816
ZERO_CONFIG_GROUP,
1917
};
2018

@@ -99,7 +97,6 @@ const core = [
9997
name: 'color',
10098
usage: '--color',
10199
type: Boolean,
102-
group: DISPLAY_GROUP,
103100
negative: true,
104101
defaultValue: true,
105102
description: 'Enable/Disable colors on console',
@@ -189,7 +186,6 @@ const core = [
189186
type: Boolean,
190187
alias: 'j',
191188
description: 'Prints result as JSON',
192-
group: DISPLAY_GROUP,
193189
},
194190
{
195191
name: 'mode',
@@ -210,7 +206,6 @@ const core = [
210206
name: 'stats',
211207
usage: '--stats <value>',
212208
type: [String, Boolean],
213-
group: DISPLAY_GROUP,
214209
negative: true,
215210
description: 'It instructs webpack on how to treat the stats e.g. verbose',
216211
link: 'https://webpack.js.org/configuration/stats/#stats',

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { options } = require('colorette');
22
const GroupHelper = require('./utils/GroupHelper');
33
const handleConfigResolution = require('./groups/ConfigGroup');
44
const resolveMode = require('./groups/resolveMode');
5+
const resolveStats = require('./groups/resolveStats');
56
const { Compiler } = require('./utils/Compiler');
67
const { groups, core } = require('./utils/cli-flags');
78
const webpackMerge = require('webpack-merge');
@@ -114,11 +115,6 @@ class WebpackCLI extends GroupHelper {
114115
this.advancedGroup = new AdvancedGroup(value);
115116
break;
116117
}
117-
case groups.DISPLAY_GROUP: {
118-
const StatsGroup = require('./groups/StatsGroup');
119-
this.statsGroup = new StatsGroup(value);
120-
break;
121-
}
122118
case groups.HELP_GROUP: {
123119
const HelpGroup = require('./groups/HelpGroup');
124120
this.helpGroup = new HelpGroup();
@@ -251,7 +247,7 @@ class WebpackCLI extends GroupHelper {
251247
.then(() => this._handleCoreFlags())
252248
.then(() => this._handleGroupHelper(this.basicGroup))
253249
.then(() => this._handleGroupHelper(this.advancedGroup))
254-
.then(() => this._handleGroupHelper(this.statsGroup))
250+
.then(() => this._baseResolver(resolveStats, parsedArgs))
255251
.then(() => this._handleGroupHelper(this.helpGroup));
256252
}
257253

0 commit comments

Comments
 (0)