Skip to content

Commit

Permalink
feat: add --web-socket-server-type option for CLI (#4001)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Nov 5, 2021
1 parent 521cf85 commit 17c390a
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ Options:
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
--web-socket-server <value> Allows to set web socket server and options (by default 'ws').
--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').
--no-web-socket-server Negative 'web-socket-server' option.
--web-socket-server-type <value> 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.
Expand Down
28 changes: 26 additions & 2 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,15 @@ 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",
values: [false],
},
{
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",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
11 changes: 6 additions & 5 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -1052,7 +1050,10 @@
},
"options": {
"type": "object",
"additionalProperties": true
"additionalProperties": true,
"cli": {
"exclude": true
}
}
},
"additionalProperties": false
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion test/cli/__snapshots__/basic.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ Options:
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
--web-socket-server <value> Allows to set web socket server and options (by default 'ws').
--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').
--no-web-socket-server Negative 'web-socket-server' option.
--web-socket-server-type <value> 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.
Expand Down
3 changes: 2 additions & 1 deletion test/cli/__snapshots__/basic.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -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 <value...> 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 <value> Allows to set web socket server and options (by default 'ws').
--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').
--no-web-socket-server Negative 'web-socket-server' option.
--web-socket-server-type <value> Allows to set web socket server and options (by default 'ws').

Global options:
--color Enable colors on console.
Expand Down
22 changes: 22 additions & 0 deletions test/cli/webSocketServer-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 17c390a

Please sign in to comment.