Skip to content

Commit

Permalink
refactor(stats): moved stats and colors handling to normalize options
Browse files Browse the repository at this point in the history
  • Loading branch information
knagaitsev committed Sep 11, 2019
1 parent e7ab9f1 commit c674e87
Show file tree
Hide file tree
Showing 6 changed files with 343 additions and 34 deletions.
8 changes: 0 additions & 8 deletions lib/utils/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ function createConfig(config, argv, { port }) {
options.watchContentBase = true;
}

if (
typeof options.stats === 'object' &&
typeof options.stats.colors === 'undefined' &&
argv.color
) {
options.stats = Object.assign({}, options.stats, { colors: argv.color });
}

if (argv.lazy) {
options.lazy = true;
}
Expand Down
17 changes: 15 additions & 2 deletions lib/utils/normalizeOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

const path = require('path');
const isAbsoluteUrl = require('is-absolute-url');
const supportsColor = require('supports-color').stdout;
const defaultTo = require('./defaultTo');

function normalizeOptions(compiler, options) {
Expand Down Expand Up @@ -91,8 +92,20 @@ function normalizeOptions(compiler, options) {
});
}

// consider retrieving the webpack config's color option, and remove the dev server
// CLI color option entirely.
// the fallback for the color value is whether or not the user's console
// supports color, so usually true (supportsColor is an object but we just want a boolean)
let colors = !!supportsColor;
if (
typeof firstWpOpt.stats === 'object' &&
firstWpOpt.stats.colors !== undefined
) {
// firstWpOpt.stats.colors could be an object but we just want a boolean
colors = !!firstWpOpt.stats.colors;
}

if (typeof options.stats === 'object' && options.stats.colors === undefined) {
options.stats = Object.assign({}, options.stats, { colors });
}

if (options.openPage) {
options.open = true;
Expand Down
12 changes: 0 additions & 12 deletions test/server/utils/__snapshots__/createConfig.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -639,18 +639,6 @@ Object {
}
`;

exports[`createConfig stats option (colors) 1`] = `
Object {
"hot": true,
"noInfo": true,
"port": 8080,
"stats": Object {
"colors": true,
"errors": true,
},
}
`;

exports[`createConfig stats option 1`] = `
Object {
"hot": true,
Expand Down
Loading

0 comments on commit c674e87

Please sign in to comment.