Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add --web-socket-server-type option for CLI #4001

Merged
merged 7 commits into from Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
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
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
Expand Up @@ -1607,6 +1607,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
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
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
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
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').
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snitin315 Can we mark --web-socket-server <value> is deprecated and add TODO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will update.

--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
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
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);
});
});