From c9ccc96f9d5cd9930f69b927b248d52509ec1e55 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 16 Aug 2021 18:38:24 +0530 Subject: [PATCH] fix: respect infastructureLogging.level for client.logging (#3613) --- lib/Server.js | 129 ++++---- test/fixtures/client-config/webpack.config.js | 17 +- .../multi-compiler-config/webpack.config.js | 17 +- test/fixtures/overlay-config/foo.js | 3 - .../fixtures/overlay-config/webpack.config.js | 17 +- .../provide-plugin-custom/webpack.config.js | 17 +- .../provide-plugin-default/webpack.config.js | 17 +- .../webpack.config.js | 17 +- .../webpack.config.js | 17 +- .../reload-config-2/webpack.config.js | 17 +- test/fixtures/reload-config/webpack.config.js | 18 +- test/fixtures/simple-config/webpack.config.js | 17 +- test/server/Server.test.js | 107 +++++++ .../Server.test.js.snap.webpack4 | 303 +++++++++++++++++- .../Server.test.js.snap.webpack5 | 303 +++++++++++++++++- 15 files changed, 913 insertions(+), 103 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 908c8ca7f3..f351263f33 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -126,12 +126,47 @@ class Server { return path.resolve(dir, "node_modules/.cache/webpack-dev-server"); } - getCompilerConfigArray() { - const compilers = this.compiler.compilers - ? this.compiler.compilers - : [this.compiler]; + getCompilerOptions() { + if (typeof this.compiler.compilers !== "undefined") { + if (this.compiler.compilers.length === 1) { + return this.compiler.compilers[0].options; + } + + // Configuration with the `devServer` options + const compilerWithDevServer = this.compiler.compilers.find( + (config) => config.options.devServer + ); + + if (compilerWithDevServer) { + return compilerWithDevServer.options; + } + + // Configuration with `web` preset + const compilerWithWebPreset = this.compiler.compilers.find( + (config) => + (config.options.externalsPresets && + config.options.externalsPresets.web) || + [ + "web", + "webworker", + "electron-preload", + "electron-renderer", + "node-webkit", + // eslint-disable-next-line no-undefined + undefined, + null, + ].includes(config.options.target) + ); + + if (compilerWithWebPreset) { + return compilerWithWebPreset.options; + } + + // Fallback + return this.compiler.compilers[0].options; + } - return compilers.map((compiler) => compiler.options); + return this.compiler.options; } // eslint-disable-next-line class-methods-use-this @@ -142,15 +177,9 @@ class Server { this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); } - // TODO: improve this to not use .find for compiler watchOptions - const configArray = this.getCompilerConfigArray(); - const watchOptionsConfig = configArray.find( - (config) => config.watch !== false && config.watchOptions - ); - const watchOptions = watchOptionsConfig - ? watchOptionsConfig.watchOptions - : {}; - + const compilerOptions = this.getCompilerOptions(); + // TODO remove `{}` after drop webpack v4 support + const watchOptions = compilerOptions.watchOptions || {}; const defaultOptionsForStatic = { directory: path.join(process.cwd(), "public"), staticOptions: {}, @@ -218,6 +247,13 @@ class Server { ...options.client.overlay, }; } + + // Respect infrastructureLogging.level + if (typeof options.client.logging === "undefined") { + options.client.logging = compilerOptions.infrastructureLogging + ? compilerOptions.infrastructureLogging.level + : "info"; + } } if (typeof options.compress === "undefined") { @@ -493,12 +529,11 @@ class Server { return level; }; - const configWithDevServer = - configArray.find((config) => config.devServer) || configArray[0]; - if (typeof proxyOptions.logLevel === "undefined") { proxyOptions.logLevel = getLogLevelForProxy( - configWithDevServer.infrastructureLogging.level + compilerOptions.infrastructureLogging + ? compilerOptions.infrastructureLogging.level + : "info" ); } @@ -707,6 +742,17 @@ class Server { this.app = new express(); } + getStats(statsObj) { + const stats = Server.DEFAULT_STATS; + const compilerOptions = this.getCompilerOptions(); + + if (compilerOptions.stats && compilerOptions.stats.warningsFilter) { + stats.warningsFilter = compilerOptions.stats.warningsFilter; + } + + return statsObj.toJson(stats); + } + setupHooks() { const addHooks = (compiler) => { compiler.hooks.invalid.tap("webpack-dev-server", () => { @@ -1260,13 +1306,16 @@ class Server { logStatus() { const colorette = require("colorette"); - const getColorsOption = (configArray) => { - const statsOption = this.getStatsOption(configArray); + const getColorsOption = (compilerOptions) => { + let colorsEnabled; - let colorsEnabled = false; - - if (typeof statsOption === "object" && statsOption.colors) { - colorsEnabled = statsOption.colors; + if ( + compilerOptions.stats && + typeof compilerOptions.stats.colors !== "undefined" + ) { + colorsEnabled = compilerOptions.stats; + } else { + colorsEnabled = colorette.options.enabled; } return colorsEnabled; @@ -1288,7 +1337,7 @@ class Server { return msg; }, }; - const useColor = getColorsOption(this.getCompilerConfigArray()); + const useColor = getColorsOption(this.getCompilerOptions()); if (this.options.ipc) { this.logger.info(`Project is running at: "${this.server.address()}"`); @@ -1420,36 +1469,6 @@ class Server { } } - // eslint-disable-next-line class-methods-use-this - getStatsOption(configArray) { - const isEmptyObject = (val) => - typeof val === "object" && Object.keys(val).length === 0; - - // in webpack@4 stats will not be defined if not provided, - // but in webpack@5 it will be an empty object - const statsConfig = configArray.find( - (configuration) => - typeof configuration === "object" && - configuration.stats && - !isEmptyObject(configuration.stats) - ); - - return statsConfig ? statsConfig.stats : {}; - } - - getStats(statsObj) { - const stats = Server.DEFAULT_STATS; - - const configArray = this.getCompilerConfigArray(); - const statsOption = this.getStatsOption(configArray); - - if (typeof statsOption === "object" && statsOption.warningsFilter) { - stats.warningsFilter = statsOption.warningsFilter; - } - - return statsObj.toJson(stats); - } - setHeaders(req, res, next) { let { headers } = this.options; diff --git a/test/fixtures/client-config/webpack.config.js b/test/fixtures/client-config/webpack.config.js index 2106890ec5..69fcaa0933 100644 --- a/test/fixtures/client-config/webpack.config.js +++ b/test/fixtures/client-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + const HTMLContent = ` @@ -20,9 +24,16 @@ module.exports = { output: { path: "/", }, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, plugins: [ { apply(compiler) { diff --git a/test/fixtures/multi-compiler-config/webpack.config.js b/test/fixtures/multi-compiler-config/webpack.config.js index 7b8c2320f1..d366a2837d 100644 --- a/test/fixtures/multi-compiler-config/webpack.config.js +++ b/test/fixtures/multi-compiler-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = [ { mode: "development", @@ -10,8 +14,15 @@ module.exports = [ path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }, ]; diff --git a/test/fixtures/overlay-config/foo.js b/test/fixtures/overlay-config/foo.js index 3c915dbcb8..e69de29bb2 100644 --- a/test/fixtures/overlay-config/foo.js +++ b/test/fixtures/overlay-config/foo.js @@ -1,3 +0,0 @@ -"use strict"; - -console.log("Hey."); diff --git a/test/fixtures/overlay-config/webpack.config.js b/test/fixtures/overlay-config/webpack.config.js index f03898aa61..56ac7546bb 100644 --- a/test/fixtures/overlay-config/webpack.config.js +++ b/test/fixtures/overlay-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -8,7 +12,14 @@ module.exports = { output: { path: "/", }, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/provide-plugin-custom/webpack.config.js b/test/fixtures/provide-plugin-custom/webpack.config.js index 624dc8a648..2ba7d2cd74 100644 --- a/test/fixtures/provide-plugin-custom/webpack.config.js +++ b/test/fixtures/provide-plugin-custom/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -9,7 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/provide-plugin-default/webpack.config.js b/test/fixtures/provide-plugin-default/webpack.config.js index 624dc8a648..2ba7d2cd74 100644 --- a/test/fixtures/provide-plugin-default/webpack.config.js +++ b/test/fixtures/provide-plugin-default/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -9,7 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js index 624dc8a648..2ba7d2cd74 100644 --- a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js +++ b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -9,7 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/provide-plugin-ws-config/webpack.config.js b/test/fixtures/provide-plugin-ws-config/webpack.config.js index 624dc8a648..2ba7d2cd74 100644 --- a/test/fixtures/provide-plugin-ws-config/webpack.config.js +++ b/test/fixtures/provide-plugin-ws-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -9,7 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/reload-config-2/webpack.config.js b/test/fixtures/reload-config-2/webpack.config.js index e6b58b3802..02847ac3db 100644 --- a/test/fixtures/reload-config-2/webpack.config.js +++ b/test/fixtures/reload-config-2/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -17,7 +21,14 @@ module.exports = { ], }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/reload-config/webpack.config.js b/test/fixtures/reload-config/webpack.config.js index a4c6cce401..910b38f3da 100644 --- a/test/fixtures/reload-config/webpack.config.js +++ b/test/fixtures/reload-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -16,8 +20,14 @@ module.exports = { }, ], }, - infrastructureLogging: { - level: "warn", - }, - node: false, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index 624dc8a648..2ba7d2cd74 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -1,5 +1,9 @@ "use strict"; +const webpack = require("webpack"); + +const isWebpack5 = webpack.version.startsWith("5"); + module.exports = { mode: "development", context: __dirname, @@ -9,7 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "warn", - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 8c1f19cd38..a6302028e0 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -283,6 +283,113 @@ describe("Server", () => { }, }, }, + { + title: + "single compiler client.logging should default to infrastructureLogging.level", + multiCompiler: false, + options: {}, + webpackConfig: { + infrastructureLogging: isWebpack5 + ? { + level: "verbose", + stream: { + write: () => {}, + }, + } + : { + level: "verbose", + }, + }, + }, + { + title: + "single compiler client.logging should override to infrastructureLogging.level", + multiCompiler: false, + options: { + client: { + logging: "none", + }, + }, + webpackConfig: { + infrastructureLogging: isWebpack5 + ? { + level: "verbose", + stream: { + write: () => {}, + }, + } + : { + level: "verbose", + }, + }, + }, + { + title: + "multi compiler client.logging should respect infrastructureLogging.level", + multiCompiler: true, + options: {}, + webpackConfig: [ + { + target: "node", + }, + // infrastructureLogging is set on the second compiler + { + target: "web", + infrastructureLogging: { + level: "warn", + }, + }, + ], + }, + { + title: + "multi compiler client.logging should respect infrastructureLogging.level", + multiCompiler: true, + options: {}, + webpackConfig: [ + {}, + // infrastructureLogging is set on the second compiler + { + devServer: {}, + infrastructureLogging: { + level: "warn", + }, + }, + ], + }, + { + title: + "multi compiler client.logging should respect infrastructureLogging.level", + multiCompiler: true, + options: {}, + webpackConfig: [ + // Fallback + { + infrastructureLogging: { + level: "warn", + }, + }, + {}, + ], + }, + { + title: + "multi compiler client.logging should override infrastructureLogging.level", + multiCompiler: true, + options: { + client: { + logging: "none", + }, + }, + webpackConfig: [ + { + infrastructureLogging: { + level: "warn", + }, + }, + {}, + ], + }, { title: "liveReload is true", multiCompiler: false, diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index eabda29f6f..f5c0375fe6 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -63,6 +63,7 @@ Object { ], "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -103,6 +104,7 @@ Object { "allowedHosts": "all", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -143,6 +145,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "/path/to/custom/client/", "webSocketURL": Object {}, @@ -184,6 +187,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "hostname": "my.host", @@ -227,6 +231,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "hostname": "my.host", @@ -270,6 +275,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "pathname": "/custom/path/", @@ -312,6 +318,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "pathname": "custom/path", @@ -354,6 +361,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "sockjs", "webSocketURL": Object {}, @@ -395,6 +403,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -436,6 +445,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -480,6 +490,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -524,6 +535,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -565,6 +577,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -607,6 +620,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -647,6 +661,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -687,6 +702,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -727,6 +743,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -767,6 +784,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -802,11 +820,12 @@ Object { } `; -exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +exports[`Server normalizeOptions multi compiler client.logging should override infrastructureLogging.level 1`] = ` Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "none", "overlay": true, "webSocketURL": Object {}, }, @@ -829,9 +848,171 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object { - "aggregateTimeout": 300, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 2`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 3`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, }, + "staticOptions": Object {}, + "watch": Object {}, }, ], "watchFiles": Array [], @@ -849,6 +1030,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -889,6 +1071,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions single compiler client.logging should default to infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "verbose", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions single compiler client.logging should override to infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "none", "overlay": true, "webSocketURL": Object {}, }, @@ -929,6 +1194,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -971,6 +1237,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1013,6 +1280,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1055,6 +1323,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1077,7 +1346,9 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object {}, + "watch": Object { + "aggregateTimeout": 300, + }, }, ], "watchFiles": Array [], @@ -1095,6 +1366,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1146,6 +1418,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1197,6 +1470,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1248,6 +1522,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1288,6 +1563,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1316,6 +1592,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1356,6 +1633,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1396,6 +1674,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1436,6 +1715,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1477,6 +1757,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1517,6 +1798,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1555,6 +1837,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1595,6 +1878,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1637,6 +1921,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1677,6 +1962,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1717,6 +2003,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "password": "chuntaro", @@ -1760,6 +2047,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1800,6 +2088,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index eabda29f6f..f5c0375fe6 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -4,7 +4,7 @@ exports[`Server DevServerPlugin add hot option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -22,7 +22,7 @@ exports[`Server DevServerPlugin add hot-only option 1`] = ` Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -40,7 +40,7 @@ exports[`Server DevServerPlugin should create and run server with old parameters Array [ Array [ "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", ], Array [ "node_modules", @@ -63,6 +63,7 @@ Object { ], "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -103,6 +104,7 @@ Object { "allowedHosts": "all", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -143,6 +145,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "/path/to/custom/client/", "webSocketURL": Object {}, @@ -184,6 +187,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "hostname": "my.host", @@ -227,6 +231,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "hostname": "my.host", @@ -270,6 +275,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "pathname": "/custom/path/", @@ -312,6 +318,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "pathname": "custom/path", @@ -354,6 +361,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "sockjs", "webSocketURL": Object {}, @@ -395,6 +403,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -436,6 +445,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -480,6 +490,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -524,6 +535,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketTransport": "ws", "webSocketURL": Object {}, @@ -565,6 +577,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -607,6 +620,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -647,6 +661,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -687,6 +702,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -727,6 +743,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -767,6 +784,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -802,11 +820,12 @@ Object { } `; -exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +exports[`Server normalizeOptions multi compiler client.logging should override infrastructureLogging.level 1`] = ` Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "none", "overlay": true, "webSocketURL": Object {}, }, @@ -829,9 +848,171 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object { - "aggregateTimeout": 300, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 2`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 3`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, }, + "staticOptions": Object {}, + "watch": Object {}, }, ], "watchFiles": Array [], @@ -849,6 +1030,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -889,6 +1071,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions single compiler client.logging should default to infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "verbose", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": undefined, + "hot": true, + "liveReload": true, + "open": Array [], + "port": "", + "setupExitSignals": true, + "static": Array [ + Object { + "directory": "/public", + "publicPath": Array [ + "/", + ], + "serveIndex": Object { + "icons": true, + }, + "staticOptions": Object {}, + "watch": Object {}, + }, + ], + "watchFiles": Array [], + "webSocketServer": Object { + "options": Object { + "path": "/ws", + }, + "type": "ws", + }, +} +`; + +exports[`Server normalizeOptions single compiler client.logging should override to infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "none", "overlay": true, "webSocketURL": Object {}, }, @@ -929,6 +1194,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -971,6 +1237,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1013,6 +1280,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1055,6 +1323,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1077,7 +1346,9 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object {}, + "watch": Object { + "aggregateTimeout": 300, + }, }, ], "watchFiles": Array [], @@ -1095,6 +1366,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1146,6 +1418,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1197,6 +1470,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1248,6 +1522,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1288,6 +1563,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1316,6 +1592,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1356,6 +1633,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1396,6 +1674,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1436,6 +1715,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1477,6 +1757,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1517,6 +1798,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1555,6 +1837,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1595,6 +1878,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1637,6 +1921,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1677,6 +1962,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1717,6 +2003,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "password": "chuntaro", @@ -1760,6 +2047,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1800,6 +2088,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, },