@@ -233,6 +233,37 @@ function normalizeStatsOptions(statsOptions) {
233233 return statsOptions ;
234234}
235235
236+ // Compatibility with rspack
237+ /**
238+ * @returns {boolean } true when color supported, otherwise false
239+ */
240+ function isColorSupported ( ) {
241+ const {
242+ env = { } ,
243+ argv = [ ] ,
244+ platform = "" ,
245+ } = typeof process === "undefined" ? { } : process ;
246+
247+ const isDisabled = "NO_COLOR" in env || argv . includes ( "--no-color" ) ;
248+ const isForced = "FORCE_COLOR" in env || argv . includes ( "--color" ) ;
249+ const isWindows = platform === "win32" ;
250+ const isDumbTerminal = env . TERM === "dumb" ;
251+
252+ const tty = require ( "node:tty" ) ;
253+
254+ const isCompatibleTerminal =
255+ tty && tty . isatty && tty . isatty ( 1 ) && env . TERM && ! isDumbTerminal ;
256+
257+ const isCI =
258+ "CI" in env &&
259+ ( "GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env ) ;
260+
261+ return (
262+ ! isDisabled &&
263+ ( isForced || ( isWindows && ! isDumbTerminal ) || isCompatibleTerminal || isCI )
264+ ) ;
265+ }
266+
236267/**
237268 * @template {IncomingMessage} Request
238269 * @template {ServerResponse} Response
@@ -287,7 +318,9 @@ function printStats(stats, context) {
287318 ( compiler ) . compilers ;
288319
289320 childStatsOptions . colors =
290- firstCompiler . webpack . cli . isColorSupported ( ) ;
321+ typeof firstCompiler . webpack . cli . isColorSupported === "function"
322+ ? firstCompiler . webpack . cli . isColorSupported ( )
323+ : isColorSupported ( ) ;
291324 }
292325
293326 return childStatsOptions ;
@@ -300,7 +333,10 @@ function printStats(stats, context) {
300333
301334 if ( typeof statsOptions . colors === "undefined" ) {
302335 const { compiler } = /** @type {{ compiler: Compiler } } */ ( context ) ;
303- statsOptions . colors = compiler . webpack . cli . isColorSupported ( ) ;
336+ statsOptions . colors =
337+ typeof compiler . webpack . cli . isColorSupported === "function"
338+ ? compiler . webpack . cli . isColorSupported ( )
339+ : isColorSupported ( ) ;
304340 }
305341 }
306342
0 commit comments