Skip to content

Commit fd63e02

Browse files
authored
fix: rename path to pathname for client.webSocketURL (#3466)
1 parent 0020f3e commit fd63e02

17 files changed

+67
-58
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Options:
109109
--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
110110
always know where to connect to).
111111
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided host.
112-
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
112+
--client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
113113
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
114114
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
115115
--compress Enables gzip compression for everything served. https://webpack.js.org/configuration/dev-server/#devservercompress

bin/cli-flags.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ module.exports = {
237237
simpleType: 'string',
238238
multiple: false,
239239
},
240-
'client-web-socket-url-path': {
240+
'client-web-socket-url-pathname': {
241241
configs: [
242242
{
243243
type: 'string',
244244
multiple: false,
245245
description:
246246
'Tells clients connected to devServer to use the provided path to connect.',
247-
path: 'client.webSocketURL.path',
247+
path: 'client.webSocketURL.pathname',
248248
},
249249
],
250250
description:

lib/options.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"type": "string",
151151
"minLength": 1
152152
},
153-
"path": {
153+
"pathname": {
154154
"description": "Tells clients connected to devServer to use the provided path to connect.",
155155
"type": "string"
156156
},

lib/utils/DevServerPlugin.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,19 @@ class DevServerPlugin {
8787
}
8888

8989
/** @type {string} */
90-
let path = '';
90+
let pathname = '';
9191

92-
// We are proxying dev server and need to specify custom `path`
93-
if (typeof options.client.webSocketURL.path !== 'undefined') {
94-
path = options.client.webSocketURL.path;
92+
// We are proxying dev server and need to specify custom `pathname`
93+
if (typeof options.client.webSocketURL.pathname !== 'undefined') {
94+
pathname = options.client.webSocketURL.pathname;
9595
}
9696

9797
// Web socket server works on custom `path`
9898
else if (
9999
typeof options.webSocketServer.options.prefix !== 'undefined' ||
100100
typeof options.webSocketServer.options.path !== 'undefined'
101101
) {
102-
path =
102+
pathname =
103103
options.webSocketServer.options.prefix ||
104104
options.webSocketServer.options.path;
105105
}
@@ -132,7 +132,9 @@ class DevServerPlugin {
132132
username || password ? `@` : ''
133133
}${ipaddr.IPv6.isIPv6(hostname) ? `[${hostname}]` : hostname}${
134134
port ? `:${port}` : ''
135-
}${path || '/'}${searchParamsString ? `?${searchParamsString}` : ''}`
135+
}${pathname || '/'}${
136+
searchParamsString ? `?${searchParamsString}` : ''
137+
}`
136138
).toString()
137139
).replace(
138140
/[!'()*]/g,

lib/utils/normalizeOptions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function normalizeOptions(compiler, options, logger, cacheDir) {
126126
protocol: parsedURL.protocol,
127127
hostname: parsedURL.hostname,
128128
port: parsedURL.port.length > 0 ? Number(parsedURL.port) : '',
129-
path: parsedURL.pathname,
129+
pathname: parsedURL.pathname,
130130
username: parsedURL.username,
131131
password: parsedURL.password,
132132
};

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ exports[`options validate should throw an error on the "client" option with '{"w
152152
-> Tells clients connected to devServer to use the provided hostname."
153153
`;
154154

155-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"path":"","port":8080}}' value 1`] = `
155+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"pathname":"","port":8080}}' value 1`] = `
156156
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
157157
- options.client.webSocketURL.hostname should be a non-empty string.
158158
-> Tells clients connected to devServer to use the provided hostname."
159159
`;
160160

161-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"path":true}}' value 1`] = `
161+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"pathname":true}}' value 1`] = `
162162
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
163-
- options.client.webSocketURL.path should be a string.
163+
- options.client.webSocketURL.pathname should be a string.
164164
-> Tells clients connected to devServer to use the provided path to connect."
165165
`;
166166

@@ -172,7 +172,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
172172
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
173173
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
174174
- options.client.webSocketURL should be one of these:
175-
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
175+
non-empty string | object { hostname?, pathname?, password?, port?, protocol?, username? }
176176
-> 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).
177177
Details:
178178
* options.client.webSocketURL.port should be one of these:
@@ -186,7 +186,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
186186
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
187187
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
188188
- options.client.webSocketURL should be one of these:
189-
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
189+
non-empty string | object { hostname?, pathname?, password?, port?, protocol?, username? }
190190
-> 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).
191191
Details:
192192
* options.client.webSocketURL.password should be a string.

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,15 @@ exports[`options validate should throw an error on the "client" option with '{"w
152152
-> Tells clients connected to devServer to use the provided hostname."
153153
`;
154154

155-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"path":"","port":8080}}' value 1`] = `
155+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"hostname":true,"pathname":"","port":8080}}' value 1`] = `
156156
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
157157
- options.client.webSocketURL.hostname should be a non-empty string.
158158
-> Tells clients connected to devServer to use the provided hostname."
159159
`;
160160

161-
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"path":true}}' value 1`] = `
161+
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"pathname":true}}' value 1`] = `
162162
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
163-
- options.client.webSocketURL.path should be a string.
163+
- options.client.webSocketURL.pathname should be a string.
164164
-> Tells clients connected to devServer to use the provided path to connect."
165165
`;
166166

@@ -172,7 +172,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
172172
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"port":true}}' value 1`] = `
173173
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
174174
- options.client.webSocketURL should be one of these:
175-
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
175+
non-empty string | object { hostname?, pathname?, password?, port?, protocol?, username? }
176176
-> 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).
177177
Details:
178178
* options.client.webSocketURL.port should be one of these:
@@ -186,7 +186,7 @@ exports[`options validate should throw an error on the "client" option with '{"w
186186
exports[`options validate should throw an error on the "client" option with '{"webSocketURL":{"username":123,"password":976}}' value 1`] = `
187187
"ValidationError: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
188188
- options.client.webSocketURL should be one of these:
189-
non-empty string | object { hostname?, path?, password?, port?, protocol?, username? }
189+
non-empty string | object { hostname?, pathname?, password?, port?, protocol?, username? }
190190
-> 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).
191191
Details:
192192
* options.client.webSocketURL.password should be a string.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Options:
5959
--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).
6060
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
6161
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
62-
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
62+
--client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
6363
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
6464
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
6565
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Options:
5959
--client-transport <value> Allows to set custom transport to communicate with dev server.
6060
--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).
6161
--client-web-socket-url-hostname <value> Tells clients connected to devServer to use the provided hostname.
62-
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
62+
--client-web-socket-url-pathname <value> Tells clients connected to devServer to use the provided path to connect.
6363
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
6464
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
6565
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.

test/cli/client-option.test.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,11 @@ describe('"client" CLI option', () => {
158158
expect(exitCode).toEqual(0);
159159
});
160160

161-
it('should work using "--client-web-socket-url-path"', async () => {
162-
const { exitCode } = await testBin(['--client-web-socket-url-path', '/ws']);
161+
it('should work using "--client-web-socket-url-pathname"', async () => {
162+
const { exitCode } = await testBin([
163+
'--client-web-socket-url-pathname',
164+
'/ws',
165+
]);
163166

164167
expect(exitCode).toEqual(0);
165168
});
@@ -180,7 +183,7 @@ describe('"client" CLI option', () => {
180183
expect(stdout).toContain('ws%3A%2F%2F0.0.0.0%2Fws');
181184
});
182185

183-
it('should use "client.webSocketURL.path" from configuration', async () => {
186+
it('should use "client.webSocketURL.pathname" from configuration', async () => {
184187
const { exitCode, stdout } = await testBin(
185188
null,
186189
'./test/fixtures/dev-server/client-custom-path-config.js'

test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack4

+8-8
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Array [
283283

284284
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
285285

286-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): console messages 1`] = `
286+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("sockjs"): console messages 1`] = `
287287
Array [
288288
"[HMR] Waiting for update signal from WDS...",
289289
"Hey.",
@@ -292,9 +292,9 @@ Array [
292292
]
293293
`;
294294

295-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): page errors 1`] = `Array []`;
295+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("sockjs"): page errors 1`] = `Array []`;
296296

297-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("ws"): console messages 1`] = `
297+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("ws"): console messages 1`] = `
298298
Array [
299299
"[HMR] Waiting for update signal from WDS...",
300300
"Hey.",
@@ -303,9 +303,9 @@ Array [
303303
]
304304
`;
305305

306-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("ws"): page errors 1`] = `Array []`;
306+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("ws"): page errors 1`] = `Array []`;
307307

308-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("sockjs"): console messages 1`] = `
308+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("sockjs"): console messages 1`] = `
309309
Array [
310310
"[HMR] Waiting for update signal from WDS...",
311311
"Hey.",
@@ -314,9 +314,9 @@ Array [
314314
]
315315
`;
316316

317-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("sockjs"): page errors 1`] = `Array []`;
317+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("sockjs"): page errors 1`] = `Array []`;
318318

319-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("ws"): console messages 1`] = `
319+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("ws"): console messages 1`] = `
320320
Array [
321321
"[HMR] Waiting for update signal from WDS...",
322322
"Hey.",
@@ -325,7 +325,7 @@ Array [
325325
]
326326
`;
327327

328-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("ws"): page errors 1`] = `Array []`;
328+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("ws"): page errors 1`] = `Array []`;
329329

330330
exports[`web socket server URL should work with the "client.webSocketURL.port" option ("sockjs"): console messages 1`] = `
331331
Array [

test/e2e/__snapshots__/web-socket-server-url.test.js.snap.webpack5

+8-8
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Array [
283283

284284
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
285285

286-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): console messages 1`] = `
286+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("sockjs"): console messages 1`] = `
287287
Array [
288288
"[HMR] Waiting for update signal from WDS...",
289289
"Hey.",
@@ -292,9 +292,9 @@ Array [
292292
]
293293
`;
294294

295-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): page errors 1`] = `Array []`;
295+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("sockjs"): page errors 1`] = `Array []`;
296296

297-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("ws"): console messages 1`] = `
297+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("ws"): console messages 1`] = `
298298
Array [
299299
"[HMR] Waiting for update signal from WDS...",
300300
"Hey.",
@@ -303,9 +303,9 @@ Array [
303303
]
304304
`;
305305

306-
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("ws"): page errors 1`] = `Array []`;
306+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option ("ws"): page errors 1`] = `Array []`;
307307

308-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("sockjs"): console messages 1`] = `
308+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("sockjs"): console messages 1`] = `
309309
Array [
310310
"[HMR] Waiting for update signal from WDS...",
311311
"Hey.",
@@ -314,9 +314,9 @@ Array [
314314
]
315315
`;
316316

317-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("sockjs"): page errors 1`] = `Array []`;
317+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("sockjs"): page errors 1`] = `Array []`;
318318

319-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("ws"): console messages 1`] = `
319+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("ws"): console messages 1`] = `
320320
Array [
321321
"[HMR] Waiting for update signal from WDS...",
322322
"Hey.",
@@ -325,7 +325,7 @@ Array [
325325
]
326326
`;
327327

328-
exports[`web socket server URL should work with the "client.webSocketURL.path" option and custom web socket server "path" ("ws"): page errors 1`] = `Array []`;
328+
exports[`web socket server URL should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("ws"): page errors 1`] = `Array []`;
329329

330330
exports[`web socket server URL should work with the "client.webSocketURL.port" option ("sockjs"): console messages 1`] = `
331331
Array [

test/e2e/web-socket-server-url.test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1103,12 +1103,12 @@ describe('web socket server URL', () => {
11031103
});
11041104
});
11051105

1106-
it(`should work with the "client.webSocketURL.path" option ("${webSocketServer}")`, async () => {
1106+
it(`should work with the "client.webSocketURL.pathname" option ("${webSocketServer}")`, async () => {
11071107
const compiler = webpack(config);
11081108
const devServerOptions = {
11091109
client: {
11101110
webSocketURL: {
1111-
path: '/ws',
1111+
pathname: '/ws',
11121112
},
11131113
},
11141114
webSocketServer,
@@ -1443,12 +1443,12 @@ describe('web socket server URL', () => {
14431443
});
14441444
});
14451445

1446-
it(`should work with the "client.webSocketURL.path" option and custom web socket server "path" ("${webSocketServer}")`, async () => {
1446+
it(`should work with the "client.webSocketURL.pathname" option and custom web socket server "path" ("${webSocketServer}")`, async () => {
14471447
const compiler = webpack(config);
14481448
const devServerOptions = {
14491449
client: {
14501450
webSocketURL: {
1451-
path: '/custom-ws',
1451+
pathname: '/custom-ws',
14521452
},
14531453
},
14541454
webSocketServer: {
@@ -1696,7 +1696,7 @@ describe('web socket server URL', () => {
16961696
protocol: 'ws:',
16971697
hostname: '127.0.0.1',
16981698
port: port1,
1699-
path: '/ws',
1699+
pathname: '/ws',
17001700
},
17011701
},
17021702
webSocketServer,

test/server/utils/__snapshots__/normalizeOptions.test.js.snap.webpack4

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ Object {
154154
"hotEntry": true,
155155
"overlay": true,
156156
"webSocketURL": Object {
157-
"path": "/custom/path/",
157+
"pathname": "/custom/path/",
158158
},
159159
},
160160
"compress": true,
@@ -191,7 +191,7 @@ Object {
191191
"hotEntry": true,
192192
"overlay": true,
193193
"webSocketURL": Object {
194-
"path": "custom/path",
194+
"pathname": "custom/path",
195195
},
196196
},
197197
"compress": true,

0 commit comments

Comments
 (0)