@@ -109,8 +109,18 @@ function setupHooks(context) {
109
109
childStatsOptions = normalizeStatsOptions ( childStatsOptions ) ;
110
110
111
111
if ( typeof childStatsOptions . colors === "undefined" ) {
112
+ const [ firstCompiler ] =
113
+ /** @type {MultiCompiler } */
114
+ ( compiler ) . compilers ;
115
+
116
+ // TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
112
117
childStatsOptions . colors =
113
- require ( "colorette" ) . isColorSupported ;
118
+ typeof firstCompiler . webpack !== "undefined" &&
119
+ typeof firstCompiler . webpack . cli !== "undefined" &&
120
+ typeof firstCompiler . webpack . cli . isColorSupported ===
121
+ "function"
122
+ ? firstCompiler . webpack . cli . isColorSupported ( )
123
+ : require ( "colorette" ) . isColorSupported ;
114
124
}
115
125
116
126
return childStatsOptions ;
@@ -122,12 +132,20 @@ function setupHooks(context) {
122
132
) ;
123
133
124
134
if ( typeof statsOptions . colors === "undefined" ) {
125
- statsOptions . colors = require ( "colorette" ) . isColorSupported ;
135
+ const { compiler } = /** @type {{ compiler: Compiler } } */ ( context ) ;
136
+ // TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
137
+ statsOptions . colors =
138
+ typeof compiler . webpack !== "undefined" &&
139
+ typeof compiler . webpack . cli !== "undefined" &&
140
+ typeof compiler . webpack . cli . isColorSupported === "function"
141
+ ? compiler . webpack . cli . isColorSupported ( )
142
+ : require ( "colorette" ) . isColorSupported ;
126
143
}
127
144
}
128
145
129
146
const printedStats = stats . toString (
130
- /** @type {StatsObjectOptions } */ ( statsOptions ) ,
147
+ /** @type {StatsObjectOptions } */
148
+ ( statsOptions ) ,
131
149
) ;
132
150
133
151
// Avoid extra empty line when `stats: 'none'`
0 commit comments