Skip to content

Commit 618ad78

Browse files
fix: code
1 parent d7cb671 commit 618ad78

File tree

6 files changed

+264
-212
lines changed

6 files changed

+264
-212
lines changed

lib/utils/DevServerPlugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class DevServerPlugin {
129129

130130
return encodeURIComponent(
131131
new URL(
132-
`${protocol}//${
133-
username && password ? `${username}:${password}@` : ''
132+
`${protocol}//${username}${password ? `:${password}` : ''}${
133+
username || password ? `@` : ''
134134
}${ipaddr.IPv6.isIPv6(host) ? `[${host}]` : host}${
135135
port ? `:${port}` : ''
136136
}${path || '/'}${

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

Lines changed: 2 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ Options:
7373
--client-web-socket-url-port <value> Tells clients connected to devServer to use the provided port.
7474
--client-web-socket-url-path <value> Tells clients connected to devServer to use the provided path to connect.
7575
--client-web-socket-url-protocol <value> Tells clients connected to devServer to use the provided protocol.
76+
--client-web-socket-url-username <value> Tells clients connected to devServer to use the provided username to authenticate.
77+
--client-web-socket-url-password <value> Tells clients connected to devServer to use the provided password to authenticate.
7678
--web-socket-server <value> Allows to set web socket server and options (by default 'ws'). https://webpack.js.org/configuration/dev-server/#devserverwebsocketserver
7779
--compress Enables gzip compression for everything served. https://webpack.js.org/configuration/dev-server/#devservercompress
7880
--no-compress Disables gzip compression for everything served.
@@ -147,79 +149,6 @@ exports[`CLI historyApiFallback option --no-history-api-fallback 1`] = `
147149
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
148150
`;
149151

150-
exports[`CLI host and port options --host and --port are unspecified: stderr 1`] = `
151-
"<i> [webpack-dev-server] Project is running at:
152-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
153-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
154-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
155-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
156-
`;
157-
158-
exports[`CLI host and port options --host localhost --port 9999: stderr 1`] = `
159-
"<i> [webpack-dev-server] Project is running at:
160-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
161-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
162-
`;
163-
164-
exports[`CLI host option --host :: (IPv6): stderr 1`] = `
165-
"<i> [webpack-dev-server] Project is running at:
166-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
167-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
168-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
169-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
170-
`;
171-
172-
exports[`CLI host option --host ::1 (IPv6): stderr 1`] = `
173-
"<i> [webpack-dev-server] Project is running at:
174-
<i> [webpack-dev-server] Loopback: http://[::1]:<port>/
175-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
176-
`;
177-
178-
exports[`CLI host option --host <IPv4>: stderr 1`] = `
179-
"<i> [webpack-dev-server] Project is running at:
180-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
181-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
182-
`;
183-
184-
exports[`CLI host option --host <local-ip>: stderr 1`] = `
185-
"<i> [webpack-dev-server] Project is running at:
186-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
187-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
188-
`;
189-
190-
exports[`CLI host option --host <local-ipv4>: stderr 1`] = `
191-
"<i> [webpack-dev-server] Project is running at:
192-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
193-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
194-
`;
195-
196-
exports[`CLI host option --host 0.0.0.0 (IPv4): stderr 1`] = `
197-
"<i> [webpack-dev-server] Project is running at:
198-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
199-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
200-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
201-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
202-
`;
203-
204-
exports[`CLI host option --host 0:0:0:0:0:FFFF:7F00:0001 (IPv6): stderr 1`] = `
205-
"<i> [webpack-dev-server] Project is running at:
206-
<i> [webpack-dev-server] On Your Network (IPv4): http://127.0.0.1:<port>/
207-
<i> [webpack-dev-server] On Your Network (IPv6): http://[::ffff:127.0.0.1]:<port>/
208-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
209-
`;
210-
211-
exports[`CLI host option --host 127.0.0.1 (IPv4): stderr 1`] = `
212-
"<i> [webpack-dev-server] Project is running at:
213-
<i> [webpack-dev-server] Loopback: http://127.0.0.1:<port>/
214-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
215-
`;
216-
217-
exports[`CLI host option --host localhost: stderr 1`] = `
218-
"<i> [webpack-dev-server] Project is running at:
219-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/, http://127.0.0.1:<port>/
220-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
221-
`;
222-
223152
exports[`CLI http2 option --http2 1`] = `
224153
"<i> [webpack-dev-server] Project is running at:
225154
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
@@ -283,139 +212,3 @@ exports[`CLI https option https options 1`] = `
283212
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
284213
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
285214
`;
286-
287-
exports[`CLI port option --port is auto: stderr 1`] = `
288-
"<i> [webpack-dev-server] Project is running at:
289-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
290-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
291-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
292-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
293-
`;
294-
295-
exports[`CLI port option --port is string: stderr 1`] = `
296-
"<i> [webpack-dev-server] Project is running at:
297-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
298-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
299-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
300-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
301-
`;
302-
303-
exports[`CLI static option --no-static-serve-index: stderr 1`] = `
304-
"<i> [webpack-dev-server] Project is running at:
305-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
306-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
307-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
308-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
309-
`;
310-
311-
exports[`CLI static option --no-static-watch: stderr 1`] = `
312-
"<i> [webpack-dev-server] Project is running at:
313-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
314-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
315-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
316-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
317-
`;
318-
319-
exports[`CLI static option --static <value> --static <other-value>: stderr 1`] = `
320-
"<i> [webpack-dev-server] Project is running at:
321-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
322-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
323-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
324-
<i> [webpack-dev-server] Content not from webpack is served from 'new-static, other-static' directory"
325-
`;
326-
327-
exports[`CLI static option --static <value>: stderr 1`] = `
328-
"<i> [webpack-dev-server] Project is running at:
329-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
330-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
331-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
332-
<i> [webpack-dev-server] Content not from webpack is served from 'new-static' directory"
333-
`;
334-
335-
exports[`CLI static option --static: stderr 1`] = `
336-
"<i> [webpack-dev-server] Project is running at:
337-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
338-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
339-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
340-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
341-
`;
342-
343-
exports[`CLI static option --static-directory: stderr 1`] = `
344-
"<i> [webpack-dev-server] Project is running at:
345-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
346-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
347-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
348-
<i> [webpack-dev-server] Content not from webpack is served from 'static-dir' directory"
349-
`;
350-
351-
exports[`CLI static option --static-public-path: stderr 1`] = `
352-
"<i> [webpack-dev-server] Project is running at:
353-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
354-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
355-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
356-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
357-
`;
358-
359-
exports[`CLI static option --static-public-path-reset: stderr 1`] = `
360-
"<i> [webpack-dev-server] Project is running at:
361-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
362-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
363-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
364-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
365-
`;
366-
367-
exports[`CLI static option --static-reset --static-directory <value>: stderr 1`] = `
368-
"<i> [webpack-dev-server] Project is running at:
369-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
370-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
371-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
372-
<i> [webpack-dev-server] Content not from webpack is served from 'new-static-directory' directory"
373-
`;
374-
375-
exports[`CLI static option --static-reset: stderr 1`] = `
376-
"<i> [webpack-dev-server] Project is running at:
377-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
378-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
379-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
380-
<i> [webpack-dev-server] Content not from webpack is served from 'new-static-after-reset' directory"
381-
`;
382-
383-
exports[`CLI static option --static-serve-index: stderr 1`] = `
384-
"<i> [webpack-dev-server] Project is running at:
385-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
386-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
387-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
388-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
389-
`;
390-
391-
exports[`CLI static option --static-watch: stderr 1`] = `
392-
"<i> [webpack-dev-server] Project is running at:
393-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
394-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
395-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
396-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
397-
`;
398-
399-
exports[`CLI watchFiles option --watch-files <value> --watch-files <other-value>: stderr 1`] = `
400-
"<i> [webpack-dev-server] Project is running at:
401-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
402-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
403-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
404-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
405-
`;
406-
407-
exports[`CLI watchFiles option --watch-files <value>: stderr 1`] = `
408-
"<i> [webpack-dev-server] Project is running at:
409-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
410-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
411-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
412-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
413-
`;
414-
415-
exports[`CLI watchFiles option --watch-files-reset: stderr 1`] = `
416-
"<i> [webpack-dev-server] Project is running at:
417-
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
418-
<i> [webpack-dev-server] On Your Network (IPv4): http://<network-ip-v4>:<port>/
419-
<i> [webpack-dev-server] On Your Network (IPv6): http://[<network-ip-v6>]:<port>/
420-
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
421-
`;

test/cli/cli.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('CLI', () => {
4040
);
4141
});
4242

43-
describe('help', () => {
43+
describe.only('help', () => {
4444
(isMacOS ? it.skip : it)('should generate correct cli flags', async () => {
4545
const { exitCode, stdout } = await testBin(['--help']);
4646

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ Array [
261261

262262
exports[`web socket server URL should work with the "client.webSocketURL.host" option using "0.0.0.0" value ("ws"): page errors 1`] = `Array []`;
263263

264+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("sockjs"): console messages 1`] = `
265+
Array [
266+
"[HMR] Waiting for update signal from WDS...",
267+
"Hey.",
268+
"[webpack-dev-server] Hot Module Replacement enabled.",
269+
"[webpack-dev-server] Live Reloading enabled.",
270+
]
271+
`;
272+
273+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("sockjs"): page errors 1`] = `Array []`;
274+
275+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): console messages 1`] = `
276+
Array [
277+
"[HMR] Waiting for update signal from WDS...",
278+
"Hey.",
279+
"[webpack-dev-server] Hot Module Replacement enabled.",
280+
"[webpack-dev-server] Live Reloading enabled.",
281+
]
282+
`;
283+
284+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
285+
264286
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): console messages 1`] = `
265287
Array [
266288
"[HMR] Waiting for update signal from WDS...",
@@ -458,3 +480,25 @@ Array [
458480
`;
459481

460482
exports[`web socket server URL should work with the "client.webSocketURL.username" and "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
483+
484+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("sockjs"): console messages 1`] = `
485+
Array [
486+
"[HMR] Waiting for update signal from WDS...",
487+
"Hey.",
488+
"[webpack-dev-server] Hot Module Replacement enabled.",
489+
"[webpack-dev-server] Live Reloading enabled.",
490+
]
491+
`;
492+
493+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("sockjs"): page errors 1`] = `Array []`;
494+
495+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("ws"): console messages 1`] = `
496+
Array [
497+
"[HMR] Waiting for update signal from WDS...",
498+
"Hey.",
499+
"[webpack-dev-server] Hot Module Replacement enabled.",
500+
"[webpack-dev-server] Live Reloading enabled.",
501+
]
502+
`;
503+
504+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("ws"): page errors 1`] = `Array []`;

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,28 @@ Array [
261261

262262
exports[`web socket server URL should work with the "client.webSocketURL.host" option using "0.0.0.0" value ("ws"): page errors 1`] = `Array []`;
263263

264+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("sockjs"): console messages 1`] = `
265+
Array [
266+
"[HMR] Waiting for update signal from WDS...",
267+
"Hey.",
268+
"[webpack-dev-server] Hot Module Replacement enabled.",
269+
"[webpack-dev-server] Live Reloading enabled.",
270+
]
271+
`;
272+
273+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("sockjs"): page errors 1`] = `Array []`;
274+
275+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): console messages 1`] = `
276+
Array [
277+
"[HMR] Waiting for update signal from WDS...",
278+
"Hey.",
279+
"[webpack-dev-server] Hot Module Replacement enabled.",
280+
"[webpack-dev-server] Live Reloading enabled.",
281+
]
282+
`;
283+
284+
exports[`web socket server URL should work with the "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
285+
264286
exports[`web socket server URL should work with the "client.webSocketURL.path" option ("sockjs"): console messages 1`] = `
265287
Array [
266288
"[HMR] Waiting for update signal from WDS...",
@@ -458,3 +480,25 @@ Array [
458480
`;
459481

460482
exports[`web socket server URL should work with the "client.webSocketURL.username" and "client.webSocketURL.password" option ("ws"): page errors 1`] = `Array []`;
483+
484+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("sockjs"): console messages 1`] = `
485+
Array [
486+
"[HMR] Waiting for update signal from WDS...",
487+
"Hey.",
488+
"[webpack-dev-server] Hot Module Replacement enabled.",
489+
"[webpack-dev-server] Live Reloading enabled.",
490+
]
491+
`;
492+
493+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("sockjs"): page errors 1`] = `Array []`;
494+
495+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("ws"): console messages 1`] = `
496+
Array [
497+
"[HMR] Waiting for update signal from WDS...",
498+
"Hey.",
499+
"[webpack-dev-server] Hot Module Replacement enabled.",
500+
"[webpack-dev-server] Live Reloading enabled.",
501+
]
502+
`;
503+
504+
exports[`web socket server URL should work with the "client.webSocketURL.username" option ("ws"): page errors 1`] = `Array []`;

0 commit comments

Comments
 (0)