Skip to content

Commit 91ecbd5

Browse files
refactor: use built-in colors
1 parent dab1b5f commit 91ecbd5

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"strip-ansi": "^6.0.0",
107107
"supertest": "^7.0.0",
108108
"typescript": "^5.3.3",
109-
"webpack": "^5.93.0"
109+
"webpack": "^5.101.0"
110110
},
111111
"peerDependencies": {
112112
"webpack": "^5.0.0"

src/utils/setupHooks.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)