Skip to content

Commit 17c390a

Browse files
authored
feat: add --web-socket-server-type option for CLI (#4001)
1 parent 521cf85 commit 17c390a

9 files changed

+65
-10
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,9 @@ Options:
109109
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
110110
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
111111
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
112-
--web-socket-server <value> Allows to set web socket server and options (by default 'ws').
112+
--web-socket-server <value> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws').
113113
--no-web-socket-server Negative 'web-socket-server' option.
114+
--web-socket-server-type <value> Allows to set web socket server and options (by default 'ws').
114115
--compress Enables gzip compression for everything served.
115116
--no-compress Disables gzip compression for everything served.
116117
--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.

bin/cli-flags.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,15 @@ module.exports = {
321321
configs: [
322322
{
323323
description:
324-
"Allows to set web socket server and options (by default 'ws').",
324+
"Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.",
325325
multiple: false,
326326
path: "webSocketServer",
327327
type: "enum",
328328
values: [false],
329329
},
330330
{
331331
description:
332-
"Allows to set web socket server and options (by default 'ws').",
332+
"Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.",
333333
multiple: false,
334334
path: "webSocketServer",
335335
type: "enum",
@@ -344,6 +344,30 @@ module.exports = {
344344
},
345345
],
346346

347+
description:
348+
"Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws').",
349+
simpleType: "string",
350+
multiple: false,
351+
},
352+
"web-socket-server-type": {
353+
configs: [
354+
{
355+
description:
356+
"Allows to set web socket server and options (by default 'ws').",
357+
multiple: false,
358+
path: "webSocketServer.type",
359+
type: "enum",
360+
values: ["sockjs", "ws"],
361+
},
362+
{
363+
description:
364+
"Allows to set web socket server and options (by default 'ws').",
365+
multiple: false,
366+
path: "webSocketServer.type",
367+
type: "string",
368+
},
369+
],
370+
347371
description:
348372
"Allows to set web socket server and options (by default 'ws').",
349373
simpleType: "string",

lib/Server.js

+1
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ class Server {
16181618
});
16191619
}
16201620

1621+
// TODO: remove `--web-socket-server` in favor of `--web-socket-server-type`
16211622
createWebSocketServer() {
16221623
this.webSocketServer = new (this.getServerTransport())(this);
16231624
this.webSocketServer.implementation.on("connection", (client, request) => {

lib/options.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1026,16 +1026,14 @@
10261026
{
10271027
"$ref": "#/definitions/WebSocketServerType"
10281028
}
1029-
]
1029+
],
1030+
"description": "Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option."
10301031
},
10311032
"WebSocketServerFunction": {
10321033
"instanceof": "Function"
10331034
},
10341035
"WebSocketServerObject": {
10351036
"type": "object",
1036-
"cli": {
1037-
"exclude": true
1038-
},
10391037
"properties": {
10401038
"type": {
10411039
"anyOf": [
@@ -1052,7 +1050,10 @@
10521050
},
10531051
"options": {
10541052
"type": "object",
1055-
"additionalProperties": true
1053+
"additionalProperties": true,
1054+
"cli": {
1055+
"exclude": true
1056+
}
10561057
}
10571058
},
10581059
"additionalProperties": false

test/__snapshots__/validate-options.test.js.snap.webpack4

+2
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ exports[`options validate should throw an error on the "webSocketServer" option
864864
Details:
865865
* options.webSocketServer should be one of these:
866866
false | \\"sockjs\\" | \\"ws\\"
867+
-> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.
867868
Details:
868869
* options.webSocketServer should be false.
869870
* options.webSocketServer should be one of these:
@@ -883,6 +884,7 @@ exports[`options validate should throw an error on the "webSocketServer" option
883884
Details:
884885
* options.webSocketServer should be one of these:
885886
false | \\"sockjs\\" | \\"ws\\"
887+
-> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.
886888
Details:
887889
* options.webSocketServer should be false.
888890
* options.webSocketServer should be one of these:

test/__snapshots__/validate-options.test.js.snap.webpack5

+2
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,7 @@ exports[`options validate should throw an error on the "webSocketServer" option
864864
Details:
865865
* options.webSocketServer should be one of these:
866866
false | \\"sockjs\\" | \\"ws\\"
867+
-> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.
867868
Details:
868869
* options.webSocketServer should be false.
869870
* options.webSocketServer should be one of these:
@@ -883,6 +884,7 @@ exports[`options validate should throw an error on the "webSocketServer" option
883884
Details:
884885
* options.webSocketServer should be one of these:
885886
false | \\"sockjs\\" | \\"ws\\"
887+
-> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option.
886888
Details:
887889
* options.webSocketServer should be false.
888890
* options.webSocketServer should be one of these:

test/cli/__snapshots__/basic.test.js.snap.webpack4

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,9 @@ Options:
7878
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
7979
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
8080
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
81-
--web-socket-server <value> Allows to set web socket server and options (by default 'ws').
81+
--web-socket-server <value> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws').
8282
--no-web-socket-server Negative 'web-socket-server' option.
83+
--web-socket-server-type <value> Allows to set web socket server and options (by default 'ws').
8384
--compress Enables gzip compression for everything served.
8485
--no-compress Disables gzip compression for everything served.
8586
--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.

test/cli/__snapshots__/basic.test.js.snap.webpack5

+2-1
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,9 @@ Options:
147147
--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.
148148
--watch-files <value...> Allows to configure list of globs/directories/files to watch for file changes.
149149
--watch-files-reset Clear all items provided in 'watchFiles' configuration. Allows to configure list of globs/directories/files to watch for file changes.
150-
--web-socket-server <value> Allows to set web socket server and options (by default 'ws').
150+
--web-socket-server <value> Deprecated: please use 'webSocketServer.type'/'--web-socket-server-type' option. Allows to set web socket server and options (by default 'ws').
151151
--no-web-socket-server Negative 'web-socket-server' option.
152+
--web-socket-server-type <value> Allows to set web socket server and options (by default 'ws').
152153

153154
Global options:
154155
--color Enable colors on console.

test/cli/webSocketServer-option.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,26 @@ describe('"webSocketServer" CLI option', () => {
2525

2626
expect(exitCode).toEqual(0);
2727
});
28+
29+
it('should work using "--web-socket-server-type ws"', async () => {
30+
const { exitCode } = await testBin([
31+
"--port",
32+
port,
33+
"--web-socket-server-type",
34+
"ws",
35+
]);
36+
37+
expect(exitCode).toEqual(0);
38+
});
39+
40+
it('should work using "--web-socket-server-type sockjs"', async () => {
41+
const { exitCode } = await testBin([
42+
"--port",
43+
port,
44+
"--web-socket-server-type",
45+
"sockjs",
46+
]);
47+
48+
expect(exitCode).toEqual(0);
49+
});
2850
});

0 commit comments

Comments
 (0)