@@ -14,6 +14,25 @@ export default function setupHooks(context) {
14
14
context . stats = undefined ;
15
15
}
16
16
17
+ const statsForWebpack4 = webpack . Stats && webpack . Stats . presetToOptions ;
18
+
19
+ function normalizeStatsOptions ( statsOptions ) {
20
+ if ( statsForWebpack4 ) {
21
+ if ( typeof statsOptions === 'undefined' ) {
22
+ // eslint-disable-next-line no-param-reassign
23
+ statsOptions = { } ;
24
+ } else if (
25
+ typeof statsOptions === 'boolean' ||
26
+ typeof statsOptions === 'string'
27
+ ) {
28
+ // eslint-disable-next-line no-param-reassign
29
+ statsOptions = webpack . Stats . presetToOptions ( statsOptions ) ;
30
+ }
31
+ }
32
+
33
+ return statsOptions ;
34
+ }
35
+
17
36
function done ( stats ) {
18
37
// We are now on valid state
19
38
// eslint-disable-next-line no-param-reassign
@@ -33,28 +52,14 @@ export default function setupHooks(context) {
33
52
logger . log ( 'Compilation finished' ) ;
34
53
35
54
let statsOptions = compiler . compilers
36
- ? {
37
- children : compiler . compilers . map ( ( child ) =>
38
- // eslint-disable-next-line no-undefined
39
- child . options ? child . options . stats : undefined
40
- ) ,
41
- }
42
- : compiler . options
43
- ? compiler . options . stats
44
- : // eslint-disable-next-line no-undefined
45
- undefined ;
46
-
47
- const statsForWebpack4 = webpack . Stats && webpack . Stats . presetToOptions ;
55
+ ? { children : compiler . compilers . map ( ( child ) => child . options . stats ) }
56
+ : compiler . options . stats ;
48
57
49
58
if ( compiler . compilers ) {
50
59
statsOptions . children = statsOptions . children . map (
51
60
( childStatsOptions ) => {
52
- if ( statsForWebpack4 ) {
53
- // eslint-disable-next-line no-param-reassign
54
- childStatsOptions = webpack . Stats . presetToOptions (
55
- childStatsOptions
56
- ) ;
57
- }
61
+ // eslint-disable-next-line no-param-reassign
62
+ childStatsOptions = normalizeStatsOptions ( childStatsOptions ) ;
58
63
59
64
if ( typeof childStatsOptions . colors === 'undefined' ) {
60
65
// eslint-disable-next-line no-param-reassign
@@ -64,15 +69,12 @@ export default function setupHooks(context) {
64
69
return childStatsOptions ;
65
70
}
66
71
) ;
67
- } else if (
68
- typeof statsOptions . colors === 'undefined' ||
69
- typeof statsOptions === 'string'
70
- ) {
71
- if ( statsForWebpack4 ) {
72
- statsOptions = webpack . Stats . presetToOptions ( statsOptions ) ;
73
- }
72
+ } else {
73
+ statsOptions = normalizeStatsOptions ( statsOptions ) ;
74
74
75
- statsOptions . colors = Boolean ( colorette . options . enabled ) ;
75
+ if ( typeof statsOptions . colors === 'undefined' ) {
76
+ statsOptions . colors = Boolean ( colorette . options . enabled ) ;
77
+ }
76
78
}
77
79
78
80
// TODO webpack@4 doesn't support `{ children: [{ colors: true }, { colors: true }] }` for stats
0 commit comments