Skip to content

Commit 256e535

Browse files
refactor: use built-in colors
1 parent e7150ee commit 256e535

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/utils/setupHooks.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ function setupHooks(context) {
112112
const [firstCompiler] =
113113
/** @type {MultiCompiler} */
114114
(compiler).compilers;
115+
116+
// TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
115117
childStatsOptions.colors =
118+
typeof firstCompiler.webpack !== "undefined" &&
119+
typeof firstCompiler.webpack.cli !== "undefined" &&
116120
typeof firstCompiler.webpack.cli.isColorSupported ===
117-
"function"
121+
"function"
118122
? firstCompiler.webpack.cli.isColorSupported()
119123
: require("colorette").isColorSupported;
120124
}
@@ -128,14 +132,13 @@ function setupHooks(context) {
128132
);
129133

130134
if (typeof statsOptions.colors === "undefined") {
135+
const { compiler } = /** @type {{ compiler: Compiler }} */ (context);
131136
// TODO remove `colorette` and set minimum supported webpack version is `5.101.0`
132137
statsOptions.colors =
133-
typeof (
134-
/** @type {Compiler} */
135-
(context.compiler).webpack.cli.isColorSupported
136-
) === "function"
137-
? /** @type {Compiler} */
138-
(context.compiler).webpack.cli.isColorSupported()
138+
typeof compiler.webpack !== "undefined" &&
139+
typeof compiler.webpack.cli !== "undefined" &&
140+
typeof compiler.webpack.cli.isColorSupported === "function"
141+
? compiler.webpack.cli.isColorSupported()
139142
: require("colorette").isColorSupported;
140143
}
141144
}

0 commit comments

Comments
 (0)