Skip to content

Commit c674e87

Browse files
committed
refactor(stats): moved stats and colors handling to normalize options
1 parent e7ab9f1 commit c674e87

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
@@ -74,14 +74,6 @@ function createConfig(config, argv, { port }) {
7474
options.watchContentBase = true;
7575
}
7676

77-
if (
78-
typeof options.stats === 'object' &&
79-
typeof options.stats.colors === 'undefined' &&
80-
argv.color
81-
) {
82-
options.stats = Object.assign({}, options.stats, { colors: argv.color });
83-
}
84-
8577
if (argv.lazy) {
8678
options.lazy = true;
8779
}

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)