Skip to content

refactor: remove client.transport in favor of client.webSocketTransport #3525

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

Merged
merged 5 commits into from
Jul 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Options:
--no-client-overlay-warnings Negative 'client-overlay-warnings' option.
--client-progress Prints compilation progress in percentage in the browser.
--no-client-progress Negative 'client-progress' option.
--client-transport <value> Allows to set custom transport to communicate with dev server.
--client-web-socket-transport <value> Allows to set custom web socket transport to communicate with dev server.
--client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
--client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
Expand Down
12 changes: 6 additions & 6 deletions bin/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,26 @@ module.exports = {
simpleType: 'boolean',
multiple: false,
},
'client-transport': {
'client-web-socket-transport': {
configs: [
{
type: 'enum',
values: ['sockjs', 'ws'],
multiple: false,
description:
'Allows to set custom transport to communicate with dev server.',
path: 'client.transport',
'Allows to set custom web socket transport to communicate with dev server.',
path: 'client.webSocketTransport',
},
{
type: 'string',
multiple: false,
description:
'Allows to set custom transport to communicate with dev server.',
path: 'client.transport',
'Allows to set custom web socket transport to communicate with dev server.',
path: 'client.webSocketTransport',
},
],
description:
'Allows to set custom transport to communicate with dev server.',
'Allows to set custom web socket transport to communicate with dev server.',
simpleType: 'string',
multiple: false,
},
Expand Down
16 changes: 8 additions & 8 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"progress": {
"$ref": "#/definitions/ClientProgress"
},
"transport": {
"$ref": "#/definitions/ClientTransport"
"webSocketTransport": {
"$ref": "#/definitions/ClientWebSocketTransport"
},
"webSocketURL": {
"$ref": "#/definitions/ClientWebSocketURL"
Expand Down Expand Up @@ -95,21 +95,21 @@
"description": "Prints compilation progress in percentage in the browser.",
"type": "boolean"
},
"ClientTransport": {
"ClientWebSocketTransport": {
"anyOf": [
{
"$ref": "#/definitions/ClientTransportEnum"
"$ref": "#/definitions/ClientWebSocketTransportEnum"
},
{
"$ref": "#/definitions/ClientTransportString"
"$ref": "#/definitions/ClientWebSocketTransportString"
}
],
"description": "Allows to set custom transport to communicate with dev server."
"description": "Allows to set custom web socket transport to communicate with dev server."
},
"ClientTransportEnum": {
"ClientWebSocketTransportEnum": {
"enum": ["sockjs", "ws"]
},
"ClientTransportString": {
"ClientWebSocketTransportString": {
"type": "string",
"minLength": 1
},
Expand Down
8 changes: 4 additions & 4 deletions lib/utils/DevServerPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class DevServerPlugin {
let clientTransport;

if (this.options.client) {
if (typeof this.options.client.transport !== 'undefined') {
clientTransport = this.options.client.transport;
if (typeof this.options.client.webSocketTransport !== 'undefined') {
clientTransport = this.options.client.webSocketTransport;
} else if (isKnownWebSocketServerImplementation) {
clientTransport = this.options.webSocketServer.type;
}
Expand Down Expand Up @@ -62,9 +62,9 @@ class DevServerPlugin {
throw new Error(
`${
!isKnownWebSocketServerImplementation
? 'When you use custom web socket implementation you must explicitly specify client.transport. '
? 'When you use custom web socket implementation you must explicitly specify client.webSocketTransport. '
: ''
}client.transport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `
}client.webSocketTransport must be a string denoting a default implementation (e.g. 'sockjs', 'ws') or a full path to a JS file via require.resolve(...) which exports a class `
);
}

Expand Down
34 changes: 17 additions & 17 deletions test/__snapshots__/validate-options.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports[`options validate should throw an error on the "client" option with '{"l
exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.overlay should be one of these:
Expand Down Expand Up @@ -112,25 +112,25 @@ exports[`options validate should throw an error on the "client" option with '{"p
-> Prints compilation progress in percentage in the browser."
`;

exports[`options validate should throw an error on the "client" option with '{"transport":true}' value 1`] = `
exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client has an unknown property 'unknownOption'. These properties are valid:
object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }"
`;

exports[`options validate should throw an error on the "client" option with '{"webSocketTransport":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.transport should be one of these:
* options.client.webSocketTransport should be one of these:
\\"sockjs\\" | \\"ws\\" | non-empty string
-> Allows to set custom transport to communicate with dev server.
-> Allows to set custom web socket transport to communicate with dev server.
Details:
* options.client.transport should be one of these:
* options.client.webSocketTransport should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.client.transport should be a non-empty string."
`;

exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client has an unknown property 'unknownOption'. These properties are valid:
object { logging?, overlay?, progress?, transport?, webSocketURL? }"
* options.client.webSocketTransport should be a non-empty string."
`;

exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":""}}' value 1`] = `
Expand Down Expand Up @@ -159,7 +159,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.webSocketURL.port should be one of these:
Expand All @@ -173,7 +173,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.webSocketURL.password should be a string.
Expand All @@ -185,12 +185,12 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client should be false.
* options.client should be an object:
object { logging?, overlay?, progress?, transport?, webSocketURL? }"
object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }"
`;

exports[`options validate should throw an error on the "compress" option with '' value 1`] = `
Expand Down
34 changes: 17 additions & 17 deletions test/__snapshots__/validate-options.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports[`options validate should throw an error on the "client" option with '{"l
exports[`options validate should throw an error on the "client" option with '{"overlay":""}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.overlay should be one of these:
Expand Down Expand Up @@ -112,25 +112,25 @@ exports[`options validate should throw an error on the "client" option with '{"p
-> Prints compilation progress in percentage in the browser."
`;

exports[`options validate should throw an error on the "client" option with '{"transport":true}' value 1`] = `
exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client has an unknown property 'unknownOption'. These properties are valid:
object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }"
`;

exports[`options validate should throw an error on the "client" option with '{"webSocketTransport":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.transport should be one of these:
* options.client.webSocketTransport should be one of these:
\\"sockjs\\" | \\"ws\\" | non-empty string
-> Allows to set custom transport to communicate with dev server.
-> Allows to set custom web socket transport to communicate with dev server.
Details:
* options.client.transport should be one of these:
* options.client.webSocketTransport should be one of these:
\\"sockjs\\" | \\"ws\\"
* options.client.transport should be a non-empty string."
`;

exports[`options validate should throw an error on the "client" option with '{"unknownOption":true}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client has an unknown property 'unknownOption'. These properties are valid:
object { logging?, overlay?, progress?, transport?, webSocketURL? }"
* options.client.webSocketTransport should be a non-empty string."
`;

exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":""}}' value 1`] = `
Expand Down Expand Up @@ -159,7 +159,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.webSocketURL.port should be one of these:
Expand All @@ -173,7 +173,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client.webSocketURL.password should be a string.
Expand All @@ -185,12 +185,12 @@ exports[`options validate should throw an error on the "client" option with '{"w
exports[`options validate should throw an error on the "client" option with 'whoops!' value 1`] = `
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
- options.client should be one of these:
false | object { logging?, overlay?, progress?, transport?, webSocketURL? }
false | object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }
-> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
Details:
* options.client should be false.
* options.client should be an object:
object { logging?, overlay?, progress?, transport?, webSocketURL? }"
object { logging?, overlay?, progress?, webSocketTransport?, webSocketURL? }"
`;

exports[`options validate should throw an error on the "compress" option with '' value 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion test/cli/__snapshots__/basic.test.js.snap.webpack4
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Options:
--allowed-hosts-reset Clear all items provided in 'allowedHosts' configuration. Allows to enumerate the hosts from which access to the dev server are allowed (useful when you are proxying dev server, by default is 'auto'). https://webpack.js.org/configuration/dev-server/#devserverallowedhosts
--bonjour Allows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
--no-bonjour Disallows to broadcasts dev server via ZeroConf networking on start. https://webpack.js.org/configuration/dev-server/#devserverbonjour
--client-transport <value> Allows to set custom transport to communicate with dev server.
--client-web-socket-transport <value> Allows to set custom web socket transport to communicate with dev server.
--no-client Negative 'client' option.
--client-logging <value> Allows to specify options for client script in the browser or disable client script. https://webpack.js.org/configuration/dev-server/#devserverclient
--client-progress Prints compilation progress in percentage in the browser.
Expand Down
2 changes: 1 addition & 1 deletion test/cli/__snapshots__/basic.test.js.snap.webpack5
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Options:
--no-client-overlay-warnings Negative 'client-overlay-warnings' option.
--client-progress Prints compilation progress in percentage in the browser.
--no-client-progress Negative 'client-progress' option.
--client-transport <value> Allows to set custom transport to communicate with dev server.
--client-web-socket-transport <value> Allows to set custom web socket transport to communicate with dev server.
--client-web-socket-url <value> Allows to specify URL to web socket server (useful when you're proxying dev server and client script does not always know where to connect to).
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
--client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
Expand Down
8 changes: 4 additions & 4 deletions test/cli/client-option.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ const { testBin } = require('../helpers/test-bin');
const port = require('../ports-map')['cli-client'];

describe('"client" CLI option', () => {
it('should work using "--client-transport sockjs"', async () => {
it('should work using "--client-web-socket-transport sockjs"', async () => {
const { exitCode } = await testBin([
'--port',
port,
'--client-transport',
'--client-web-socket-transport',
'sockjs',
]);

expect(exitCode).toEqual(0);
});

it('should work using "--client-transport ws"', async () => {
it('should work using "--client-web-socket-transport ws"', async () => {
const { exitCode } = await testBin([
'--port',
port,
'--client-transport',
'--client-web-socket-transport',
'ws',
]);

Expand Down
Loading