@@ -109,8 +109,18 @@ function setupHooks(context) {
109109 childStatsOptions = normalizeStatsOptions ( childStatsOptions ) ;
110110
111111 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`
112117 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 ;
114124 }
115125
116126 return childStatsOptions ;
@@ -122,12 +132,20 @@ function setupHooks(context) {
122132 ) ;
123133
124134 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 ;
126143 }
127144 }
128145
129146 const printedStats = stats . toString (
130- /** @type {StatsObjectOptions } */ ( statsOptions ) ,
147+ /** @type {StatsObjectOptions } */
148+ ( statsOptions ) ,
131149 ) ;
132150
133151 // Avoid extra empty line when `stats: 'none'`
0 commit comments