diff --git a/README.md b/README.md index bac6ca3bc0..649010cc4d 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,9 @@ Options: --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. - --web-socket-server Allows to set web socket server and options (by default 'ws'). + --web-socket-server Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). --no-web-socket-server Negative 'web-socket-server' option. + --web-socket-server-type Allows to set web socket server and options (by default 'ws'). --compress Enables gzip compression for everything served. --no-compress Disables gzip compression for everything served. --history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API. diff --git a/bin/cli-flags.js b/bin/cli-flags.js index da2c2bf227..01a5219d27 100644 --- a/bin/cli-flags.js +++ b/bin/cli-flags.js @@ -321,7 +321,7 @@ module.exports = { configs: [ { description: - "Allows to set web socket server and options (by default 'ws').", + "Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.", multiple: false, path: "webSocketServer", type: "enum", @@ -329,7 +329,7 @@ module.exports = { }, { description: - "Allows to set web socket server and options (by default 'ws').", + "Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.", multiple: false, path: "webSocketServer", type: "enum", @@ -344,6 +344,30 @@ module.exports = { }, ], + description: + "Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws').", + simpleType: "string", + multiple: false, + }, + "web-socket-server-type": { + configs: [ + { + description: + "Allows to set web socket server and options (by default 'ws').", + multiple: false, + path: "webSocketServer.type", + type: "enum", + values: ["sockjs", "ws"], + }, + { + description: + "Allows to set web socket server and options (by default 'ws').", + multiple: false, + path: "webSocketServer.type", + type: "string", + }, + ], + description: "Allows to set web socket server and options (by default 'ws').", simpleType: "string", diff --git a/lib/Server.js b/lib/Server.js index d35e507d75..6a79d51701 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1618,6 +1618,7 @@ class Server { }); } + // TODO: remove `--web-socket-server` in favor of `--web-socket-server-type` createWebSocketServer() { this.webSocketServer = new (this.getServerTransport())(this); this.webSocketServer.implementation.on("connection", (client, request) => { diff --git a/lib/options.json b/lib/options.json index dd6d7f5e8c..6ed93c9078 100644 --- a/lib/options.json +++ b/lib/options.json @@ -1026,16 +1026,14 @@ { "$ref": "#/definitions/WebSocketServerType" } - ] + ], + "description": "Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option." }, "WebSocketServerFunction": { "instanceof": "Function" }, "WebSocketServerObject": { "type": "object", - "cli": { - "exclude": true - }, "properties": { "type": { "anyOf": [ @@ -1052,7 +1050,10 @@ }, "options": { "type": "object", - "additionalProperties": true + "additionalProperties": true, + "cli": { + "exclude": true + } } }, "additionalProperties": false diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack4 b/test/__snapshots__/validate-options.test.js.snap.webpack4 index 646e103f06..5650232a05 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack4 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack4 @@ -864,6 +864,7 @@ exports[`options validate should throw an error on the "webSocketServer" option Details: * options.webSocketServer should be one of these: false | \\"sockjs\\" | \\"ws\\" + -> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Details: * options.webSocketServer should be false. * options.webSocketServer should be one of these: @@ -883,6 +884,7 @@ exports[`options validate should throw an error on the "webSocketServer" option Details: * options.webSocketServer should be one of these: false | \\"sockjs\\" | \\"ws\\" + -> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Details: * options.webSocketServer should be false. * options.webSocketServer should be one of these: diff --git a/test/__snapshots__/validate-options.test.js.snap.webpack5 b/test/__snapshots__/validate-options.test.js.snap.webpack5 index 646e103f06..5650232a05 100644 --- a/test/__snapshots__/validate-options.test.js.snap.webpack5 +++ b/test/__snapshots__/validate-options.test.js.snap.webpack5 @@ -864,6 +864,7 @@ exports[`options validate should throw an error on the "webSocketServer" option Details: * options.webSocketServer should be one of these: false | \\"sockjs\\" | \\"ws\\" + -> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Details: * options.webSocketServer should be false. * options.webSocketServer should be one of these: @@ -883,6 +884,7 @@ exports[`options validate should throw an error on the "webSocketServer" option Details: * options.webSocketServer should be one of these: false | \\"sockjs\\" | \\"ws\\" + -> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Details: * options.webSocketServer should be false. * options.webSocketServer should be one of these: diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack4 b/test/cli/__snapshots__/basic.test.js.snap.webpack4 index 447853a050..89940feb4e 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack4 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack4 @@ -78,8 +78,9 @@ Options: --client-web-socket-url-protocol Tells clients connected to devServer to use the provided protocol. --client-web-socket-url-username Tells clients connected to devServer to use the provided username to authenticate. --client-web-socket-url-password Tells clients connected to devServer to use the provided password to authenticate. - --web-socket-server Allows to set web socket server and options (by default 'ws'). + --web-socket-server Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). --no-web-socket-server Negative 'web-socket-server' option. + --web-socket-server-type Allows to set web socket server and options (by default 'ws'). --compress Enables gzip compression for everything served. --no-compress Disables gzip compression for everything served. --history-api-fallback Allows to proxy requests through a specified index page (by default 'index.html'), useful for Single Page Applications that utilise the HTML5 History API. diff --git a/test/cli/__snapshots__/basic.test.js.snap.webpack5 b/test/cli/__snapshots__/basic.test.js.snap.webpack5 index db8a66fbee..9b339a91a8 100644 --- a/test/cli/__snapshots__/basic.test.js.snap.webpack5 +++ b/test/cli/__snapshots__/basic.test.js.snap.webpack5 @@ -147,8 +147,9 @@ Options: --static-public-path-reset Clear all items provided in 'static.publicPath' configuration. The static files will be available in the browser under this public path. --watch-files Allows to configure list of globs/directories/files to watch for file changes. --watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes. - --web-socket-server Allows to set web socket server and options (by default 'ws'). + --web-socket-server Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws'). --no-web-socket-server Negative 'web-socket-server' option. + --web-socket-server-type Allows to set web socket server and options (by default 'ws'). Global options: --color Enable colors on console. diff --git a/test/cli/webSocketServer-option.test.js b/test/cli/webSocketServer-option.test.js index 51f0f14826..2aba5b98eb 100644 --- a/test/cli/webSocketServer-option.test.js +++ b/test/cli/webSocketServer-option.test.js @@ -25,4 +25,26 @@ describe('"webSocketServer" CLI option', () => { expect(exitCode).toEqual(0); }); + + it('should work using "--web-socket-server-type ws"', async () => { + const { exitCode } = await testBin([ + "--port", + port, + "--web-socket-server-type", + "ws", + ]); + + expect(exitCode).toEqual(0); + }); + + it('should work using "--web-socket-server-type sockjs"', async () => { + const { exitCode } = await testBin([ + "--port", + port, + "--web-socket-server-type", + "sockjs", + ]); + + expect(exitCode).toEqual(0); + }); });