From dfd48262387e3647795336a77f58387860c4fd23 Mon Sep 17 00:00:00 2001 From: Yoann Moinet Date: Thu, 14 Feb 2019 14:40:11 +0100 Subject: [PATCH] fix(Server): cascade stats options --- lib/Server.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index aed9eab65e..86f3b68215 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -72,15 +72,6 @@ if (semver.satisfies(process.version, '8.6.0 - 9')) { tls.DEFAULT_ECDH_CURVE = 'auto'; } -const STATS = { - all: false, - hash: true, - assets: true, - warnings: true, - errors: true, - errorDetails: false, -}; - class Server { constructor(compiler, options = {}, _log) { this.log = _log || createLogger(options); @@ -91,6 +82,15 @@ class Server { throw new Error("'filename' option must be set in lazy mode."); } + this.stats = options.stats; + this.DEFAULT_STATS = { + all: false, + hash: true, + assets: true, + warnings: true, + errors: true, + errorDetails: false, + }; this.hot = options.hot || options.hotOnly; this.headers = options.headers; this.progress = options.progress; @@ -144,7 +144,7 @@ class Server { compile.tap('webpack-dev-server', invalidPlugin); invalid.tap('webpack-dev-server', invalidPlugin); done.tap('webpack-dev-server', (stats) => { - this._sendStats(this.sockets, stats.toJson(STATS)); + this._sendStats(this.sockets, this.getStats(stats)); this._stats = stats; }); }; @@ -650,6 +650,13 @@ class Server { }, this); } + getStats(statsObj) { + return Object.assign( + statsObj.toJson(this.DEFAULT_STATS), + statsObj.toJson(this.stats) + ); + } + use() { // eslint-disable-next-line this.app.use.apply(this.app, arguments); @@ -817,7 +824,7 @@ class Server { return; } - this._sendStats([connection], this._stats.toJson(STATS), true); + this._sendStats([connection], this.getStats(this._stats), true); }); socket.installHandlers(this.listeningApp, {