Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,37 @@ function normalizeStatsOptions(statsOptions) {
return statsOptions;
}

// Compatibility with rspack
/**
* @returns {boolean} true when color supported, otherwise false
*/
function isColorSupported() {
const {
env = {},
argv = [],
platform = "",
} = typeof process === "undefined" ? {} : process;

const isDisabled = "NO_COLOR" in env || argv.includes("--no-color");
const isForced = "FORCE_COLOR" in env || argv.includes("--color");
const isWindows = platform === "win32";
const isDumbTerminal = env.TERM === "dumb";

const tty = require("node:tty");

const isCompatibleTerminal =
tty && tty.isatty && tty.isatty(1) && env.TERM && !isDumbTerminal;

const isCI =
"CI" in env &&
("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env);

return (
!isDisabled &&
(isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI)
);
}

/**
* @template {IncomingMessage} Request
* @template {ServerResponse} Response
Expand Down Expand Up @@ -287,7 +318,9 @@ function printStats(stats, context) {
(compiler).compilers;

childStatsOptions.colors =
firstCompiler.webpack.cli.isColorSupported();
typeof firstCompiler.webpack.cli.isColorSupported === "function"
? firstCompiler.webpack.cli.isColorSupported()
: isColorSupported();
}

return childStatsOptions;
Expand All @@ -300,7 +333,10 @@ function printStats(stats, context) {

if (typeof statsOptions.colors === "undefined") {
const { compiler } = /** @type {{ compiler: Compiler }} */ (context);
statsOptions.colors = compiler.webpack.cli.isColorSupported();
statsOptions.colors =
typeof compiler.webpack.cli.isColorSupported === "function"
? compiler.webpack.cli.isColorSupported()
: isColorSupported();
}
}

Expand Down
Loading