Skip to content

Commit 105fdf9

Browse files
committed
refactor(stats): moved stats and colors handling to normalize options
1 parent 19f21ba commit 105fdf9

File tree

6 files changed

+343
-34
lines changed

6 files changed

+343
-34
lines changed

lib/utils/createConfig.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ function createConfig(config, argv, { port }) {
7979
options.watchContentBase = true;
8080
}
8181

82-
if (
83-
typeof options.stats === 'object' &&
84-
typeof options.stats.colors === 'undefined' &&
85-
argv.color
86-
) {
87-
options.stats = Object.assign({}, options.stats, { colors: argv.color });
88-
}
89-
9082
if (argv.lazy) {
9183
options.lazy = true;
9284
}

lib/utils/normalizeOptions.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const path = require('path');
88
const isAbsoluteUrl = require('is-absolute-url');
9+
const supportsColor = require('supports-color').stdout;
910
const defaultTo = require('./defaultTo');
1011

1112
function normalizeOptions(compiler, options) {
@@ -91,8 +92,20 @@ function normalizeOptions(compiler, options) {
9192
});
9293
}
9394

94-
// consider retrieving the webpack config's color option, and remove the dev server
95-
// CLI color option entirely.
95+
// the fallback for the color value is whether or not the user's console
96+
// supports color, so usually true (supportsColor is an object but we just want a boolean)
97+
let colors = !!supportsColor;
98+
if (
99+
typeof firstWpOpt.stats === 'object' &&
100+
firstWpOpt.stats.colors !== undefined
101+
) {
102+
// firstWpOpt.stats.colors could be an object but we just want a boolean
103+
colors = !!firstWpOpt.stats.colors;
104+
}
105+
106+
if (typeof options.stats === 'object' && options.stats.colors === undefined) {
107+
options.stats = Object.assign({}, options.stats, { colors });
108+
}
96109

97110
if (options.openPage) {
98111
options.open = true;

test/server/utils/__snapshots__/createConfig.test.js.snap

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -639,18 +639,6 @@ Object {
639639
}
640640
`;
641641

642-
exports[`createConfig stats option (colors) 1`] = `
643-
Object {
644-
"hot": true,
645-
"noInfo": true,
646-
"port": 8080,
647-
"stats": Object {
648-
"colors": true,
649-
"errors": true,
650-
},
651-
}
652-
`;
653-
654642
exports[`createConfig stats option 1`] = `
655643
Object {
656644
"hot": true,

0 commit comments

Comments
 (0)