From 4f05601dc2efcb0ffbd8cd6aab9e03c15f57a3d6 Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 11 Aug 2021 09:18:51 +0530 Subject: [PATCH 1/7] fix: respect `infastructureLogging.level` for `client.logging` --- lib/Server.js | 12 + test/fixtures/simple-config/webpack.config.js | 2 +- test/server/Server.test.js | 60 +++++ .../Server.test.js.snap.webpack4 | 213 +++++++++++++++++- .../Server.test.js.snap.webpack5 | 213 +++++++++++++++++- 5 files changed, 493 insertions(+), 7 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 908c8ca7f3..6e507b692b 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -218,6 +218,18 @@ class Server { ...options.client.overlay, }; } + + // Respect infrastructureLogging.level + if (typeof options.client.logging === "undefined") { + const configWithInfrastructureLogging = + configArray.find( + (config) => + config.infrastructureLogging && config.infrastructureLogging.level + ) || configArray[0]; + + options.client.logging = + configWithInfrastructureLogging.infrastructureLogging.level; + } } if (typeof options.compress === "undefined") { diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index 624dc8a648..338e8946cb 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -10,6 +10,6 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", }, }; diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 8c1f19cd38..17ee65eed3 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -283,6 +283,66 @@ describe("Server", () => { }, }, }, + { + title: + "single compiler client.logging should default to infrastructureLogging.level", + multiCompiler: false, + options: {}, + webpackConfig: { + infrastructureLogging: { + level: "verbose", + }, + }, + }, + { + title: + "single compiler client.logging should override to infrastructureLogging.level", + multiCompiler: false, + options: { + client: { + logging: "none", + }, + }, + webpackConfig: { + infrastructureLogging: { + level: "verbose", + }, + }, + }, + { + title: + "multi compiler client.logging should respect infrastructureLogging.level", + multiCompiler: true, + options: {}, + webpackConfig: [ + {}, + // infrastructureLogging is set on the second compiler + { + infrastructureLogging: { + level: "warn", + }, + }, + ], + }, + { + title: + "multi compiler client.logging should override infrastructureLogging.level", + multiCompiler: true, + options: { + client: { + logging: "none", + }, + }, + webpackConfig: [ + {}, + // infrastructureLogging is set on the second compiler + { + 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..500c088acf 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,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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 override infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "none", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", "overlay": true, "webSocketURL": Object {}, }, @@ -807,6 +907,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "warn", "overlay": true, "webSocketURL": Object {}, }, @@ -849,6 +950,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -889,6 +991,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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": "127.0.0.1", + "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 +1114,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -971,6 +1157,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1013,6 +1200,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1055,6 +1243,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1095,6 +1284,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1146,6 +1336,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1197,6 +1388,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1248,6 +1440,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1288,6 +1481,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1316,6 +1510,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1356,6 +1551,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1396,6 +1592,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1436,6 +1633,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1477,6 +1675,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1517,6 +1716,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1555,6 +1755,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1595,6 +1796,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1637,6 +1839,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1677,6 +1880,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1717,6 +1921,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "password": "chuntaro", @@ -1760,6 +1965,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1800,6 +2006,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..500c088acf 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,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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 override infrastructureLogging.level 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "none", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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 1`] = ` +Object { + "allowedHosts": "auto", + "bonjour": false, + "client": Object { + "logging": "warn", "overlay": true, "webSocketURL": Object {}, }, @@ -807,6 +907,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "warn", "overlay": true, "webSocketURL": Object {}, }, @@ -849,6 +950,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -889,6 +991,89 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", + "overlay": true, + "webSocketURL": Object {}, + }, + "compress": true, + "devMiddleware": Object {}, + "historyApiFallback": false, + "host": "127.0.0.1", + "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": "127.0.0.1", + "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 +1114,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -971,6 +1157,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1013,6 +1200,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1055,6 +1243,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1095,6 +1284,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1146,6 +1336,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1197,6 +1388,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1248,6 +1440,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1288,6 +1481,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1316,6 +1510,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1356,6 +1551,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1396,6 +1592,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1436,6 +1633,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1477,6 +1675,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1517,6 +1716,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1555,6 +1755,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1595,6 +1796,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1637,6 +1839,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1677,6 +1880,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1717,6 +1921,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object { "password": "chuntaro", @@ -1760,6 +1965,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, @@ -1800,6 +2006,7 @@ Object { "allowedHosts": "auto", "bonjour": false, "client": Object { + "logging": "info", "overlay": true, "webSocketURL": Object {}, }, From 885291679aff6840e0b508bcef0ef8c780d6ece8 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Sun, 15 Aug 2021 22:06:25 +0300 Subject: [PATCH 2/7] refactor: code --- lib/Server.js | 260 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 206 insertions(+), 54 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 6e507b692b..6c265154a9 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -126,31 +126,60 @@ 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) + ); - return compilers.map((compiler) => compiler.options); + if (compilerWithWebPreset) { + return compilerWithWebPreset.options; + } + + // Fallback + return this.compiler.compilers[0].options; + } + + return this.compiler.options; } // eslint-disable-next-line class-methods-use-this - async normalizeOptions() { + normalizeOptions() { const { options } = this; if (!this.logger) { 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: {}, @@ -221,14 +250,9 @@ class Server { // Respect infrastructureLogging.level if (typeof options.client.logging === "undefined") { - const configWithInfrastructureLogging = - configArray.find( - (config) => - config.infrastructureLogging && config.infrastructureLogging.level - ) || configArray[0]; - - options.client.logging = - configWithInfrastructureLogging.infrastructureLogging.level; + options.client.logging = compilerOptions.infrastructureLogging + ? compilerOptions.infrastructureLogging.level + : "info"; } } @@ -504,13 +528,12 @@ 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" ); } @@ -1272,13 +1295,13 @@ 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 (typeof compilerOptions.stats.colors !== "undefined") { + colorsEnabled = compilerOptions.stats; + } else { + colorsEnabled = colorette.options.enabled; } return colorsEnabled; @@ -1300,7 +1323,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()}"`); @@ -1432,31 +1455,160 @@ 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) + listen(port, hostname, fn) { + this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); + this.normalizeOptions(this.options); + + if (typeof port === "function") { + fn = port; + } + + if ( + typeof port !== "undefined" && + typeof this.options.port !== "undefined" && + port !== this.options.port + ) { + this.options.port = port; + + this.logger.warn( + 'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.' + ); + } + + if (!this.options.port) { + this.options.port = port; + } + + if ( + typeof hostname !== "undefined" && + typeof this.options.host !== "undefined" && + hostname !== this.options.host + ) { + this.options.host = hostname; + + this.logger.warn( + 'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.' + ); + } + + if (!this.options.host) { + this.options.host = hostname; + } + + this.options.host = Server.getHostname(this.options.host); + + const resolveFreePortOrIPC = () => { + if (this.options.ipc) { + return new Promise((resolve, reject) => { + const net = require("net"); + const socket = new net.Socket(); + + socket.on("error", (error) => { + if (error.code === "ECONNREFUSED") { + fs.unlinkSync(this.options.ipc); + + resolve(this.options.ipc); + + return; + } else if (error.code === "ENOENT") { + resolve(this.options.ipc); + + return; + } + + reject(error); + }); + + socket.connect({ path: this.options.ipc }, () => { + throw new Error(`IPC "${this.options.ipc}" is already used`); + }); + }); + } + + return Server.getFreePort(this.options.port).then((foundPort) => { + this.options.port = foundPort; + }); + }; + + return resolveFreePortOrIPC() + .then(() => { + this.initialize(); + + const listenOptions = this.options.ipc + ? { path: this.options.ipc } + : { + host: this.options.host, + port: this.options.port, + }; + + return this.server.listen(listenOptions, (error) => { + if (this.options.ipc) { + // chmod 666 (rw rw rw) + const READ_WRITE = 438; + + fs.chmodSync(this.options.ipc, READ_WRITE); + } + + if (this.options.webSocketServer) { + try { + this.createWebSocketServer(); + } catch (webSocketServerError) { + fn.call(this.server, webSocketServerError); + + return; + } + } + + if (this.options.bonjour) { + this.runBonjour(); + } + + this.logStatus(); + + if (fn) { + fn.call(this.server, error); + } + + if (typeof this.options.onListening === "function") { + this.options.onListening(this); + } + }); + }) + .catch((error) => { + if (fn) { + fn.call(this.server, error); + } + }); + } + + close(callback) { + if (this.webSocketServer) { + this.webSocketServer.implementation.close(); + } + + const prom = Promise.all( + this.staticWatchers.map((watcher) => watcher.close()) ); + this.staticWatchers = []; - return statsConfig ? statsConfig.stats : {}; + if (this.server) { + this.server.kill(() => { + // watchers must be closed before closing middleware + prom.then(() => { + this.middleware.close(callback); + }); + }); + } else if (callback) { + callback(); + } } getStats(statsObj) { const stats = Server.DEFAULT_STATS; + const compilerOptions = this.getCompilerOptions(); - const configArray = this.getCompilerConfigArray(); - const statsOption = this.getStatsOption(configArray); - - if (typeof statsOption === "object" && statsOption.warningsFilter) { - stats.warningsFilter = statsOption.warningsFilter; + if (compilerOptions.stats && compilerOptions.stats.warningsFilter) { + stats.warningsFilter = compilerOptions.stats.warningsFilter; } return statsObj.toJson(stats); From dced9208ca09fa9e7cf97202f3aafcb34b411994 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Sun, 15 Aug 2021 22:13:23 +0300 Subject: [PATCH 3/7] fix: rebase --- lib/Server.js | 88 ++------------------------------------------------- 1 file changed, 3 insertions(+), 85 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 6c265154a9..6fb8f87396 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -170,13 +170,13 @@ class Server { } // eslint-disable-next-line class-methods-use-this - normalizeOptions() { + async normalizeOptions() { const { options } = this; if (!this.logger) { this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); } - + const compilerOptions = this.getCompilerOptions(); // TODO remove `{}` after drop webpack v4 support const watchOptions = compilerOptions.watchOptions || {}; @@ -528,7 +528,7 @@ class Server { return level; }; - + if (typeof proxyOptions.logLevel === "undefined") { proxyOptions.logLevel = getLogLevelForProxy( compilerOptions.infrastructureLogging @@ -1581,28 +1581,6 @@ class Server { }); } - close(callback) { - if (this.webSocketServer) { - this.webSocketServer.implementation.close(); - } - - const prom = Promise.all( - this.staticWatchers.map((watcher) => watcher.close()) - ); - this.staticWatchers = []; - - if (this.server) { - this.server.kill(() => { - // watchers must be closed before closing middleware - prom.then(() => { - this.middleware.close(callback); - }); - }); - } else if (callback) { - callback(); - } - } - getStats(statsObj) { const stats = Server.DEFAULT_STATS; const compilerOptions = this.getCompilerOptions(); @@ -1942,66 +1920,6 @@ class Server { this.stop().then(() => callback(null), callback); } - // TODO remove in the next major release - listen(port, hostname, fn) { - util.deprecate( - () => {}, - "'listen' is deprecated. Please use async 'start' or 'startCallback' methods.", - "DEP_WEBPACK_DEV_SERVER_LISTEN" - )(); - - this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); - - if (typeof port === "function") { - fn = port; - } - - if ( - typeof port !== "undefined" && - typeof this.options.port !== "undefined" && - port !== this.options.port - ) { - this.options.port = port; - - this.logger.warn( - 'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.' - ); - } - - if (!this.options.port) { - this.options.port = port; - } - - if ( - typeof hostname !== "undefined" && - typeof this.options.host !== "undefined" && - hostname !== this.options.host - ) { - this.options.host = hostname; - - this.logger.warn( - 'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.' - ); - } - - if (!this.options.host) { - this.options.host = hostname; - } - - return this.start() - .then(() => { - if (fn) { - fn.call(this.server); - } - }) - .catch((error) => { - // Nothing - if (fn) { - fn.call(this.server, error); - } - }); - } - // TODO remove in the next major release close(callback) { util.deprecate( From b7aaf64e71ec159a670b4a39d989114d86611b18 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Sun, 15 Aug 2021 22:14:38 +0300 Subject: [PATCH 4/7] fix: rebase --- lib/Server.js | 208 +++++++++++++++++--------------------------------- 1 file changed, 71 insertions(+), 137 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index 6fb8f87396..f55762c0ed 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -742,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", () => { @@ -1455,143 +1466,6 @@ class Server { } } - listen(port, hostname, fn) { - this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); - this.normalizeOptions(this.options); - - if (typeof port === "function") { - fn = port; - } - - if ( - typeof port !== "undefined" && - typeof this.options.port !== "undefined" && - port !== this.options.port - ) { - this.options.port = port; - - this.logger.warn( - 'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.' - ); - } - - if (!this.options.port) { - this.options.port = port; - } - - if ( - typeof hostname !== "undefined" && - typeof this.options.host !== "undefined" && - hostname !== this.options.host - ) { - this.options.host = hostname; - - this.logger.warn( - 'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.' - ); - } - - if (!this.options.host) { - this.options.host = hostname; - } - - this.options.host = Server.getHostname(this.options.host); - - const resolveFreePortOrIPC = () => { - if (this.options.ipc) { - return new Promise((resolve, reject) => { - const net = require("net"); - const socket = new net.Socket(); - - socket.on("error", (error) => { - if (error.code === "ECONNREFUSED") { - fs.unlinkSync(this.options.ipc); - - resolve(this.options.ipc); - - return; - } else if (error.code === "ENOENT") { - resolve(this.options.ipc); - - return; - } - - reject(error); - }); - - socket.connect({ path: this.options.ipc }, () => { - throw new Error(`IPC "${this.options.ipc}" is already used`); - }); - }); - } - - return Server.getFreePort(this.options.port).then((foundPort) => { - this.options.port = foundPort; - }); - }; - - return resolveFreePortOrIPC() - .then(() => { - this.initialize(); - - const listenOptions = this.options.ipc - ? { path: this.options.ipc } - : { - host: this.options.host, - port: this.options.port, - }; - - return this.server.listen(listenOptions, (error) => { - if (this.options.ipc) { - // chmod 666 (rw rw rw) - const READ_WRITE = 438; - - fs.chmodSync(this.options.ipc, READ_WRITE); - } - - if (this.options.webSocketServer) { - try { - this.createWebSocketServer(); - } catch (webSocketServerError) { - fn.call(this.server, webSocketServerError); - - return; - } - } - - if (this.options.bonjour) { - this.runBonjour(); - } - - this.logStatus(); - - if (fn) { - fn.call(this.server, error); - } - - if (typeof this.options.onListening === "function") { - this.options.onListening(this); - } - }); - }) - .catch((error) => { - if (fn) { - fn.call(this.server, error); - } - }); - } - - 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); - } - setHeaders(req, res, next) { let { headers } = this.options; @@ -1920,6 +1794,66 @@ class Server { this.stop().then(() => callback(null), callback); } + // TODO remove in the next major release + listen(port, hostname, fn) { + util.deprecate( + () => {}, + "'listen' is deprecated. Please use async 'start' or 'startCallback' methods.", + "DEP_WEBPACK_DEV_SERVER_LISTEN" + )(); + + this.logger = this.compiler.getInfrastructureLogger("webpack-dev-server"); + + if (typeof port === "function") { + fn = port; + } + + if ( + typeof port !== "undefined" && + typeof this.options.port !== "undefined" && + port !== this.options.port + ) { + this.options.port = port; + + this.logger.warn( + 'The "port" specified in options is different from the port passed as an argument. Will be used from arguments.' + ); + } + + if (!this.options.port) { + this.options.port = port; + } + + if ( + typeof hostname !== "undefined" && + typeof this.options.host !== "undefined" && + hostname !== this.options.host + ) { + this.options.host = hostname; + + this.logger.warn( + 'The "host" specified in options is different from the host passed as an argument. Will be used from arguments.' + ); + } + + if (!this.options.host) { + this.options.host = hostname; + } + + return this.start() + .then(() => { + if (fn) { + fn.call(this.server); + } + }) + .catch((error) => { + // Nothing + if (fn) { + fn.call(this.server, error); + } + }); + } + // TODO remove in the next major release close(callback) { util.deprecate( From cda3ec16f90f3d4f59cc259cf74b9c082bbe7de3 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Sun, 15 Aug 2021 23:03:47 +0300 Subject: [PATCH 5/7] test: fix --- test/fixtures/client-config/webpack.config.js | 5 +- .../multi-compiler-config/webpack.config.js | 5 +- test/fixtures/overlay-config/foo.js | 3 - .../fixtures/overlay-config/webpack.config.js | 5 +- .../provide-plugin-custom/webpack.config.js | 5 +- .../provide-plugin-default/webpack.config.js | 5 +- .../webpack.config.js | 5 +- .../webpack.config.js | 5 +- .../reload-config-2/webpack.config.js | 5 +- test/fixtures/simple-config/webpack.config.js | 3 + test/server/Server.test.js | 45 ++++++- .../Server.test.js.snap.webpack4 | 116 ++++++++++++++---- .../Server.test.js.snap.webpack5 | 116 ++++++++++++++---- 13 files changed, 257 insertions(+), 66 deletions(-) diff --git a/test/fixtures/client-config/webpack.config.js b/test/fixtures/client-config/webpack.config.js index 2106890ec5..14aa069ddd 100644 --- a/test/fixtures/client-config/webpack.config.js +++ b/test/fixtures/client-config/webpack.config.js @@ -21,7 +21,10 @@ module.exports = { path: "/", }, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, plugins: [ { diff --git a/test/fixtures/multi-compiler-config/webpack.config.js b/test/fixtures/multi-compiler-config/webpack.config.js index 7b8c2320f1..28bcf73362 100644 --- a/test/fixtures/multi-compiler-config/webpack.config.js +++ b/test/fixtures/multi-compiler-config/webpack.config.js @@ -11,7 +11,10 @@ module.exports = [ }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }, ]; 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..cd7b610d84 100644 --- a/test/fixtures/overlay-config/webpack.config.js +++ b/test/fixtures/overlay-config/webpack.config.js @@ -9,6 +9,9 @@ module.exports = { path: "/", }, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/provide-plugin-custom/webpack.config.js b/test/fixtures/provide-plugin-custom/webpack.config.js index 624dc8a648..f8bc3a9399 100644 --- a/test/fixtures/provide-plugin-custom/webpack.config.js +++ b/test/fixtures/provide-plugin-custom/webpack.config.js @@ -10,6 +10,9 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/provide-plugin-default/webpack.config.js b/test/fixtures/provide-plugin-default/webpack.config.js index 624dc8a648..f8bc3a9399 100644 --- a/test/fixtures/provide-plugin-default/webpack.config.js +++ b/test/fixtures/provide-plugin-default/webpack.config.js @@ -10,6 +10,9 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js index 624dc8a648..f8bc3a9399 100644 --- a/test/fixtures/provide-plugin-sockjs-config/webpack.config.js +++ b/test/fixtures/provide-plugin-sockjs-config/webpack.config.js @@ -10,6 +10,9 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/provide-plugin-ws-config/webpack.config.js b/test/fixtures/provide-plugin-ws-config/webpack.config.js index 624dc8a648..f8bc3a9399 100644 --- a/test/fixtures/provide-plugin-ws-config/webpack.config.js +++ b/test/fixtures/provide-plugin-ws-config/webpack.config.js @@ -10,6 +10,9 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/reload-config-2/webpack.config.js b/test/fixtures/reload-config-2/webpack.config.js index e6b58b3802..e18fed2ab2 100644 --- a/test/fixtures/reload-config-2/webpack.config.js +++ b/test/fixtures/reload-config-2/webpack.config.js @@ -18,6 +18,9 @@ module.exports = { }, node: false, infrastructureLogging: { - level: "warn", + level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/fixtures/simple-config/webpack.config.js b/test/fixtures/simple-config/webpack.config.js index 338e8946cb..f8bc3a9399 100644 --- a/test/fixtures/simple-config/webpack.config.js +++ b/test/fixtures/simple-config/webpack.config.js @@ -11,5 +11,8 @@ module.exports = { node: false, infrastructureLogging: { level: "info", + stream: { + write: () => {}, + }, }, }; diff --git a/test/server/Server.test.js b/test/server/Server.test.js index 17ee65eed3..ddc07cf2b2 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -120,7 +120,7 @@ describe("Server", () => { }); }); - describe("normalizeOptions", () => { + describe.only("normalizeOptions", () => { const cases = [ { title: "no options", @@ -291,6 +291,9 @@ describe("Server", () => { webpackConfig: { infrastructureLogging: { level: "verbose", + stream: { + write: () => {}, + }, }, }, }, @@ -306,9 +309,30 @@ describe("Server", () => { webpackConfig: { infrastructureLogging: { level: "verbose", + stream: { + write: () => {}, + }, }, }, }, + { + 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", @@ -318,12 +342,28 @@ describe("Server", () => { {}, // 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", @@ -334,13 +374,12 @@ describe("Server", () => { }, }, webpackConfig: [ - {}, - // infrastructureLogging is set on the second compiler { infrastructureLogging: { level: "warn", }, }, + {}, ], }, { diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index 500c088acf..0e65a8e566 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -36,24 +36,6 @@ Array [ ] `; -exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` -Array [ - Array [ - "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", - ], - Array [ - "node_modules", - "webpack", - "hot", - "dev-server.js", - ], - Array [ - "foo.js", - ], -] -`; - exports[`Server Server.getFreePort should throws the error when the port isn't found 1`] = `"busy"`; exports[`Server normalizeOptions allowedHosts is array 1`] = ` @@ -791,7 +773,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -832,7 +814,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -902,7 +884,7 @@ Object { } `; -exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 2`] = ` Object { "allowedHosts": "auto", "bonjour": false, @@ -930,9 +912,89 @@ 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 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 [], @@ -998,7 +1060,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -1039,7 +1101,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -1266,7 +1328,9 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object {}, + "watch": Object { + "aggregateTimeout": 300, + }, }, ], "watchFiles": Array [], diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index 500c088acf..0e65a8e566 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -36,24 +36,6 @@ Array [ ] `; -exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` -Array [ - Array [ - "client", - "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", - ], - Array [ - "node_modules", - "webpack", - "hot", - "dev-server.js", - ], - Array [ - "foo.js", - ], -] -`; - exports[`Server Server.getFreePort should throws the error when the port isn't found 1`] = `"busy"`; exports[`Server normalizeOptions allowedHosts is array 1`] = ` @@ -791,7 +773,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -832,7 +814,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -902,7 +884,7 @@ Object { } `; -exports[`Server normalizeOptions multi compiler watchOptions is set 1`] = ` +exports[`Server normalizeOptions multi compiler client.logging should respect infrastructureLogging.level 2`] = ` Object { "allowedHosts": "auto", "bonjour": false, @@ -930,9 +912,89 @@ 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 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 [], @@ -998,7 +1060,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -1039,7 +1101,7 @@ Object { "compress": true, "devMiddleware": Object {}, "historyApiFallback": false, - "host": "127.0.0.1", + "host": undefined, "hot": true, "liveReload": true, "open": Array [], @@ -1266,7 +1328,9 @@ Object { "icons": true, }, "staticOptions": Object {}, - "watch": Object {}, + "watch": Object { + "aggregateTimeout": 300, + }, }, ], "watchFiles": Array [], From 5e6253d298832a7d1128a0e82e29fc56e5615067 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 16 Aug 2021 15:11:55 +0300 Subject: [PATCH 6/7] fix: code --- lib/Server.js | 5 ++- test/fixtures/client-config/webpack.config.js | 20 +++++++---- .../multi-compiler-config/webpack.config.js | 20 +++++++---- .../fixtures/overlay-config/webpack.config.js | 20 +++++++---- .../provide-plugin-custom/webpack.config.js | 20 +++++++---- .../provide-plugin-default/webpack.config.js | 20 +++++++---- .../webpack.config.js | 20 +++++++---- .../webpack.config.js | 20 +++++++---- .../reload-config-2/webpack.config.js | 20 +++++++---- test/fixtures/simple-config/webpack.config.js | 20 +++++++---- test/server/Server.test.js | 34 ++++++++++++------- .../Server.test.js.snap.webpack4 | 18 ++++++++++ .../Server.test.js.snap.webpack5 | 18 ++++++++++ 13 files changed, 187 insertions(+), 68 deletions(-) diff --git a/lib/Server.js b/lib/Server.js index f55762c0ed..f351263f33 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1309,7 +1309,10 @@ class Server { const getColorsOption = (compilerOptions) => { let colorsEnabled; - if (typeof compilerOptions.stats.colors !== "undefined") { + if ( + compilerOptions.stats && + typeof compilerOptions.stats.colors !== "undefined" + ) { colorsEnabled = compilerOptions.stats; } else { colorsEnabled = colorette.options.enabled; diff --git a/test/fixtures/client-config/webpack.config.js b/test/fixtures/client-config/webpack.config.js index 14aa069ddd..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,12 +24,16 @@ module.exports = { output: { path: "/", }, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 28bcf73362..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,11 +14,15 @@ module.exports = [ path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }, ]; diff --git a/test/fixtures/overlay-config/webpack.config.js b/test/fixtures/overlay-config/webpack.config.js index cd7b610d84..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,10 +12,14 @@ module.exports = { output: { path: "/", }, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 f8bc3a9399..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,10 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 f8bc3a9399..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,10 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 f8bc3a9399..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,10 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 f8bc3a9399..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,10 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 e18fed2ab2..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,10 +21,14 @@ module.exports = { ], }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + 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 f8bc3a9399..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,10 +13,14 @@ module.exports = { path: "/", }, node: false, - infrastructureLogging: { - level: "info", - stream: { - write: () => {}, - }, - }, + infrastructureLogging: isWebpack5 + ? { + level: "info", + stream: { + write: () => {}, + }, + } + : { + level: "info", + }, }; diff --git a/test/server/Server.test.js b/test/server/Server.test.js index ddc07cf2b2..a6302028e0 100644 --- a/test/server/Server.test.js +++ b/test/server/Server.test.js @@ -120,7 +120,7 @@ describe("Server", () => { }); }); - describe.only("normalizeOptions", () => { + describe("normalizeOptions", () => { const cases = [ { title: "no options", @@ -289,12 +289,16 @@ describe("Server", () => { multiCompiler: false, options: {}, webpackConfig: { - infrastructureLogging: { - level: "verbose", - stream: { - write: () => {}, - }, - }, + infrastructureLogging: isWebpack5 + ? { + level: "verbose", + stream: { + write: () => {}, + }, + } + : { + level: "verbose", + }, }, }, { @@ -307,12 +311,16 @@ describe("Server", () => { }, }, webpackConfig: { - infrastructureLogging: { - level: "verbose", - stream: { - write: () => {}, - }, - }, + infrastructureLogging: isWebpack5 + ? { + level: "verbose", + stream: { + write: () => {}, + }, + } + : { + level: "verbose", + }, }, }, { diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack4 b/test/server/__snapshots__/Server.test.js.snap.webpack4 index 0e65a8e566..f5c0375fe6 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack4 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack4 @@ -36,6 +36,24 @@ Array [ ] `; +exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` +Array [ + Array [ + "client", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + ], + Array [ + "node_modules", + "webpack", + "hot", + "dev-server.js", + ], + Array [ + "foo.js", + ], +] +`; + exports[`Server Server.getFreePort should throws the error when the port isn't found 1`] = `"busy"`; exports[`Server normalizeOptions allowedHosts is array 1`] = ` diff --git a/test/server/__snapshots__/Server.test.js.snap.webpack5 b/test/server/__snapshots__/Server.test.js.snap.webpack5 index 0e65a8e566..f5c0375fe6 100644 --- a/test/server/__snapshots__/Server.test.js.snap.webpack5 +++ b/test/server/__snapshots__/Server.test.js.snap.webpack5 @@ -36,6 +36,24 @@ Array [ ] `; +exports[`Server DevServerPlugin should create and run server with old parameters order and log deprecation warning: oldparam 1`] = ` +Array [ + Array [ + "client", + "index.js?protocol=ws%3A&hostname=localhost&port=8124&pathname=%2Fws&logging=info", + ], + Array [ + "node_modules", + "webpack", + "hot", + "dev-server.js", + ], + Array [ + "foo.js", + ], +] +`; + exports[`Server Server.getFreePort should throws the error when the port isn't found 1`] = `"busy"`; exports[`Server normalizeOptions allowedHosts is array 1`] = ` From 6094d7a90f850111cac0f036a92ac5451ab88fff Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Mon, 16 Aug 2021 15:23:41 +0300 Subject: [PATCH 7/7] test: fix --- test/fixtures/reload-config/webpack.config.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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", + }, };