webpack-dev-server 4.7.0 → 4.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli-flags.js +26 -22
- package/client/clients/SockJSClient.js +5 -1
- package/client/index.js +50 -2
- package/client/modules/sockjs-client/index.js +15 -4
- package/client/overlay.js +38 -3
- package/client/socket.js +14 -2
- package/client/utils/createSocketURL.js +71 -4
- package/client/utils/getCurrentScriptSource.js +3 -0
- package/client/utils/parseURL.js +17 -19
- package/client/utils/reloadApp.js +15 -2
- package/client/utils/sendMessage.js +1 -1
- package/lib/Server.js +129 -138
- package/lib/options.json +59 -12
- package/package.json +16 -15
- package/types/bin/cli-flags.d.ts +29 -21
- package/types/lib/Server.d.ts +503 -303
package/bin/cli-flags.js
CHANGED
|
@@ -46,13 +46,13 @@ module.exports = {
|
|
|
46
46
|
multiple: false,
|
|
47
47
|
description:
|
|
48
48
|
"Allows to broadcasts dev server via ZeroConf networking on start.",
|
|
49
|
+
negatedDescription:
|
|
50
|
+
"Disallows to broadcasts dev server via ZeroConf networking on start.",
|
|
49
51
|
path: "bonjour",
|
|
50
52
|
},
|
|
51
53
|
],
|
|
52
54
|
description:
|
|
53
55
|
"Allows to broadcasts dev server via ZeroConf networking on start.",
|
|
54
|
-
negatedDescription:
|
|
55
|
-
"Disallows to broadcasts dev server via ZeroConf networking on start.",
|
|
56
56
|
simpleType: "boolean",
|
|
57
57
|
multiple: false,
|
|
58
58
|
},
|
|
@@ -93,13 +93,13 @@ module.exports = {
|
|
|
93
93
|
multiple: false,
|
|
94
94
|
description:
|
|
95
95
|
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
96
|
+
negatedDescription:
|
|
97
|
+
"Disables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
96
98
|
path: "client.overlay",
|
|
97
99
|
},
|
|
98
100
|
],
|
|
99
101
|
description:
|
|
100
102
|
"Enables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
101
|
-
negatedDescription:
|
|
102
|
-
"Disables a full-screen overlay in the browser when there are compiler errors or warnings.",
|
|
103
103
|
simpleType: "boolean",
|
|
104
104
|
multiple: false,
|
|
105
105
|
},
|
|
@@ -140,12 +140,12 @@ module.exports = {
|
|
|
140
140
|
multiple: false,
|
|
141
141
|
description:
|
|
142
142
|
"Prints compilation progress in percentage in the browser.",
|
|
143
|
+
negatedDescription:
|
|
144
|
+
"Does not print compilation progress in percentage in the browser.",
|
|
143
145
|
path: "client.progress",
|
|
144
146
|
},
|
|
145
147
|
],
|
|
146
148
|
description: "Prints compilation progress in percentage in the browser.",
|
|
147
|
-
negatedDescription:
|
|
148
|
-
"Does not print compilation progress in percentage in the browser.",
|
|
149
149
|
simpleType: "boolean",
|
|
150
150
|
multiple: false,
|
|
151
151
|
},
|
|
@@ -156,6 +156,8 @@ module.exports = {
|
|
|
156
156
|
multiple: false,
|
|
157
157
|
description:
|
|
158
158
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
159
|
+
negatedDescription:
|
|
160
|
+
"Tells dev-server to not to try to connect the client.",
|
|
159
161
|
path: "client.reconnect",
|
|
160
162
|
},
|
|
161
163
|
{
|
|
@@ -163,12 +165,13 @@ module.exports = {
|
|
|
163
165
|
multiple: false,
|
|
164
166
|
description:
|
|
165
167
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
168
|
+
negatedDescription:
|
|
169
|
+
"Tells dev-server to not to try to connect the client.",
|
|
166
170
|
path: "client.reconnect",
|
|
167
171
|
},
|
|
168
172
|
],
|
|
169
173
|
description:
|
|
170
174
|
"Tells dev-server the number of times it should try to reconnect the client.",
|
|
171
|
-
negatedDescription: "Tells dev-server to not to try to connect the client.",
|
|
172
175
|
simpleType: "string",
|
|
173
176
|
multiple: false,
|
|
174
177
|
},
|
|
@@ -321,11 +324,11 @@ module.exports = {
|
|
|
321
324
|
type: "boolean",
|
|
322
325
|
multiple: false,
|
|
323
326
|
description: "Enables gzip compression for everything served.",
|
|
327
|
+
negatedDescription: "Disables gzip compression for everything served.",
|
|
324
328
|
path: "compress",
|
|
325
329
|
},
|
|
326
330
|
],
|
|
327
331
|
description: "Enables gzip compression for everything served.",
|
|
328
|
-
negatedDescription: "Disables gzip compression for everything served.",
|
|
329
332
|
simpleType: "boolean",
|
|
330
333
|
multiple: false,
|
|
331
334
|
},
|
|
@@ -370,6 +373,7 @@ module.exports = {
|
|
|
370
373
|
type: "boolean",
|
|
371
374
|
multiple: false,
|
|
372
375
|
description: "Enables Hot Module Replacement.",
|
|
376
|
+
negatedDescription: "Disables Hot Module Replacement.",
|
|
373
377
|
path: "hot",
|
|
374
378
|
},
|
|
375
379
|
{
|
|
@@ -377,11 +381,11 @@ module.exports = {
|
|
|
377
381
|
values: ["only"],
|
|
378
382
|
multiple: false,
|
|
379
383
|
description: "Enables Hot Module Replacement.",
|
|
384
|
+
negatedDescription: "Disables Hot Module Replacement.",
|
|
380
385
|
path: "hot",
|
|
381
386
|
},
|
|
382
387
|
],
|
|
383
388
|
description: "Enables Hot Module Replacement.",
|
|
384
|
-
negatedDescription: "Disables Hot Module Replacement.",
|
|
385
389
|
simpleType: "string",
|
|
386
390
|
multiple: false,
|
|
387
391
|
},
|
|
@@ -392,12 +396,12 @@ module.exports = {
|
|
|
392
396
|
multiple: false,
|
|
393
397
|
description:
|
|
394
398
|
"Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option.",
|
|
399
|
+
negatedDescription: "Does not serve over HTTP/2 using SPDY.",
|
|
395
400
|
path: "http2",
|
|
396
401
|
},
|
|
397
402
|
],
|
|
398
403
|
description:
|
|
399
404
|
"Allows to serve over HTTP/2 using SPDY. Deprecated, use the `server` option.",
|
|
400
|
-
negatedDescription: "Does not serve over HTTP/2 using SPDY.",
|
|
401
405
|
simpleType: "boolean",
|
|
402
406
|
multiple: false,
|
|
403
407
|
},
|
|
@@ -408,13 +412,13 @@ module.exports = {
|
|
|
408
412
|
multiple: false,
|
|
409
413
|
description:
|
|
410
414
|
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option.",
|
|
415
|
+
negatedDescription:
|
|
416
|
+
"Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
411
417
|
path: "https",
|
|
412
418
|
},
|
|
413
419
|
],
|
|
414
420
|
description:
|
|
415
421
|
"Allows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP). Deprecated, use the `server` option.",
|
|
416
|
-
negatedDescription:
|
|
417
|
-
"Disallows to configure the server's listening socket for TLS (by default, dev server will be served over HTTP).",
|
|
418
422
|
simpleType: "boolean",
|
|
419
423
|
multiple: false,
|
|
420
424
|
},
|
|
@@ -620,12 +624,12 @@ module.exports = {
|
|
|
620
624
|
multiple: false,
|
|
621
625
|
description:
|
|
622
626
|
"Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option.",
|
|
627
|
+
negatedDescription: "Does not request for an SSL certificate.",
|
|
623
628
|
path: "https.requestCert",
|
|
624
629
|
},
|
|
625
630
|
],
|
|
626
631
|
description:
|
|
627
632
|
"Request for an SSL certificate. Deprecated, use the `server.options.requestCert` option.",
|
|
628
|
-
negatedDescription: "Does not request for an SSL certificate.",
|
|
629
633
|
simpleType: "boolean",
|
|
630
634
|
multiple: false,
|
|
631
635
|
},
|
|
@@ -656,13 +660,13 @@ module.exports = {
|
|
|
656
660
|
multiple: false,
|
|
657
661
|
description:
|
|
658
662
|
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
663
|
+
negatedDescription:
|
|
664
|
+
"Disables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
659
665
|
path: "liveReload",
|
|
660
666
|
},
|
|
661
667
|
],
|
|
662
668
|
description:
|
|
663
669
|
"Enables reload/refresh the page(s) when file changes are detected (enabled by default).",
|
|
664
|
-
negatedDescription:
|
|
665
|
-
"Disables reload/refresh the page(s) when file changes are detected (enabled by default)",
|
|
666
670
|
simpleType: "boolean",
|
|
667
671
|
multiple: false,
|
|
668
672
|
},
|
|
@@ -673,13 +677,13 @@ module.exports = {
|
|
|
673
677
|
multiple: false,
|
|
674
678
|
description:
|
|
675
679
|
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
680
|
+
negatedDescription:
|
|
681
|
+
"Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
676
682
|
path: "magicHtml",
|
|
677
683
|
},
|
|
678
684
|
],
|
|
679
685
|
description:
|
|
680
686
|
"Tells dev-server whether to enable magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
681
|
-
negatedDescription:
|
|
682
|
-
"Disables magic HTML routes (routes corresponding to your webpack output, for example '/main' for 'main.js').",
|
|
683
687
|
simpleType: "boolean",
|
|
684
688
|
multiple: false,
|
|
685
689
|
},
|
|
@@ -697,12 +701,12 @@ module.exports = {
|
|
|
697
701
|
multiple: false,
|
|
698
702
|
description:
|
|
699
703
|
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
|
|
704
|
+
negatedDescription: "Does not open the default browser.",
|
|
700
705
|
path: "open",
|
|
701
706
|
},
|
|
702
707
|
],
|
|
703
708
|
description:
|
|
704
709
|
"Allows to configure dev server to open the browser(s) and page(s) after server had been started (set it to true to open your default browser).",
|
|
705
|
-
negatedDescription: "Does not open the default browser.",
|
|
706
710
|
simpleType: "string",
|
|
707
711
|
multiple: true,
|
|
708
712
|
},
|
|
@@ -786,7 +790,6 @@ module.exports = {
|
|
|
786
790
|
},
|
|
787
791
|
],
|
|
788
792
|
description: "Opens specified page in browser.",
|
|
789
|
-
negatedDescription: "Does not open specified page in browser.",
|
|
790
793
|
simpleType: "string",
|
|
791
794
|
multiple: true,
|
|
792
795
|
},
|
|
@@ -1140,12 +1143,12 @@ module.exports = {
|
|
|
1140
1143
|
multiple: true,
|
|
1141
1144
|
description:
|
|
1142
1145
|
"Tells dev server to use serveIndex middleware when enabled.",
|
|
1146
|
+
negatedDescription:
|
|
1147
|
+
"Does not tell dev server to use serveIndex middleware.",
|
|
1143
1148
|
path: "static[].serveIndex",
|
|
1144
1149
|
},
|
|
1145
1150
|
],
|
|
1146
1151
|
description: "Tells dev server to use serveIndex middleware when enabled.",
|
|
1147
|
-
negatedDescription:
|
|
1148
|
-
"Does not tell dev server to use serveIndex middleware.",
|
|
1149
1152
|
simpleType: "boolean",
|
|
1150
1153
|
multiple: true,
|
|
1151
1154
|
},
|
|
@@ -1155,11 +1158,12 @@ module.exports = {
|
|
|
1155
1158
|
type: "boolean",
|
|
1156
1159
|
multiple: true,
|
|
1157
1160
|
description: "Watches for files in static content directory.",
|
|
1161
|
+
negatedDescription:
|
|
1162
|
+
"Does not watch for files in static content directory.",
|
|
1158
1163
|
path: "static[].watch",
|
|
1159
1164
|
},
|
|
1160
1165
|
],
|
|
1161
1166
|
description: "Watches for files in static content directory.",
|
|
1162
|
-
negatedDescription: "Does not watch for files in static content directory.",
|
|
1163
1167
|
simpleType: "boolean",
|
|
1164
1168
|
multiple: true,
|
|
1165
1169
|
},
|
|
@@ -52,7 +52,11 @@ var SockJSClient = /*#__PURE__*/function () {
|
|
|
52
52
|
}, {
|
|
53
53
|
key: "onMessage",
|
|
54
54
|
value: function onMessage(f) {
|
|
55
|
-
this.sock.onmessage =
|
|
55
|
+
this.sock.onmessage =
|
|
56
|
+
/**
|
|
57
|
+
* @param {Error & { data: string }} e
|
|
58
|
+
*/
|
|
59
|
+
function (e) {
|
|
56
60
|
f(e.data);
|
|
57
61
|
};
|
|
58
62
|
}
|
package/client/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/* global __resourceQuery, __webpack_hash__ */
|
|
2
|
+
/// <reference types="webpack/module" />
|
|
2
3
|
import webpackHotLog from "webpack/hot/log.js";
|
|
3
4
|
import stripAnsi from "./modules/strip-ansi/index.js";
|
|
4
5
|
import parseURL from "./utils/parseURL.js";
|
|
@@ -8,12 +9,35 @@ import { log, setLogLevel } from "./utils/log.js";
|
|
|
8
9
|
import sendMessage from "./utils/sendMessage.js";
|
|
9
10
|
import reloadApp from "./utils/reloadApp.js";
|
|
10
11
|
import createSocketURL from "./utils/createSocketURL.js";
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {Object} Options
|
|
14
|
+
* @property {boolean} hot
|
|
15
|
+
* @property {boolean} liveReload
|
|
16
|
+
* @property {boolean} progress
|
|
17
|
+
* @property {boolean | { warnings?: boolean, errors?: boolean }} overlay
|
|
18
|
+
* @property {string} [logging]
|
|
19
|
+
* @property {number} [reconnect]
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @typedef {Object} Status
|
|
24
|
+
* @property {boolean} isUnloading
|
|
25
|
+
* @property {string} currentHash
|
|
26
|
+
* @property {string} [previousHash]
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @type {Status}
|
|
31
|
+
*/
|
|
32
|
+
|
|
11
33
|
var status = {
|
|
12
34
|
isUnloading: false,
|
|
13
35
|
// TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
|
|
14
36
|
// eslint-disable-next-line camelcase
|
|
15
37
|
currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
|
|
16
38
|
};
|
|
39
|
+
/** @type {Options} */
|
|
40
|
+
|
|
17
41
|
var options = {
|
|
18
42
|
hot: false,
|
|
19
43
|
liveReload: false,
|
|
@@ -92,6 +116,10 @@ var onSocketMessage = {
|
|
|
92
116
|
status.currentHash = _hash;
|
|
93
117
|
},
|
|
94
118
|
logging: setAllLogLevel,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @param {boolean} value
|
|
122
|
+
*/
|
|
95
123
|
overlay: function overlay(value) {
|
|
96
124
|
if (typeof document === "undefined") {
|
|
97
125
|
return;
|
|
@@ -99,6 +127,10 @@ var onSocketMessage = {
|
|
|
99
127
|
|
|
100
128
|
options.overlay = value;
|
|
101
129
|
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {number} value
|
|
133
|
+
*/
|
|
102
134
|
reconnect: function reconnect(value) {
|
|
103
135
|
if (parsedResourceQuery.reconnect === "false") {
|
|
104
136
|
return;
|
|
@@ -106,9 +138,17 @@ var onSocketMessage = {
|
|
|
106
138
|
|
|
107
139
|
options.reconnect = value;
|
|
108
140
|
},
|
|
109
|
-
|
|
110
|
-
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @param {boolean} value
|
|
144
|
+
*/
|
|
145
|
+
progress: function progress(value) {
|
|
146
|
+
options.progress = value;
|
|
111
147
|
},
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {{ pluginName?: string, percent: number, msg: string }} data
|
|
151
|
+
*/
|
|
112
152
|
"progress-update": function progressUpdate(data) {
|
|
113
153
|
if (options.progress) {
|
|
114
154
|
log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "").concat(data.percent, "% - ").concat(data.msg, "."));
|
|
@@ -135,10 +175,18 @@ var onSocketMessage = {
|
|
|
135
175
|
reloadApp(options, status);
|
|
136
176
|
},
|
|
137
177
|
// TODO: remove in v5 in favor of 'static-changed'
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {string} file
|
|
181
|
+
*/
|
|
138
182
|
"content-changed": function contentChanged(file) {
|
|
139
183
|
log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
|
|
140
184
|
self.location.reload();
|
|
141
185
|
},
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {string} file
|
|
189
|
+
*/
|
|
142
190
|
"static-changed": function staticChanged(file) {
|
|
143
191
|
log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
|
|
144
192
|
self.location.reload();
|
|
@@ -6459,7 +6459,7 @@ function Url(address, location, parser) {
|
|
|
6459
6459
|
|
|
6460
6460
|
if (url.auth) {
|
|
6461
6461
|
instruction = url.auth.split(':');
|
|
6462
|
-
url.username = instruction[0]
|
|
6462
|
+
url.username = instruction[0];
|
|
6463
6463
|
url.password = instruction[1] || '';
|
|
6464
6464
|
}
|
|
6465
6465
|
|
|
@@ -6544,8 +6544,15 @@ function set(part, value, fn) {
|
|
|
6544
6544
|
|
|
6545
6545
|
break;
|
|
6546
6546
|
|
|
6547
|
-
|
|
6548
|
-
|
|
6547
|
+
case 'username':
|
|
6548
|
+
case 'password':
|
|
6549
|
+
url[part] = encodeURIComponent(value);
|
|
6550
|
+
break;
|
|
6551
|
+
|
|
6552
|
+
case 'auth':
|
|
6553
|
+
var splits = value.split(':');
|
|
6554
|
+
url.username = splits[0];
|
|
6555
|
+
url.password = splits.length === 2 ? splits[1] : '';
|
|
6549
6556
|
}
|
|
6550
6557
|
|
|
6551
6558
|
for (var i = 0; i < rules.length; i++) {
|
|
@@ -6553,6 +6560,7 @@ function set(part, value, fn) {
|
|
|
6553
6560
|
if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
|
|
6554
6561
|
}
|
|
6555
6562
|
|
|
6563
|
+
url.auth = url.password ? url.username + ':' + url.password : url.username;
|
|
6556
6564
|
url.origin = url.protocol !== 'file:' && isSpecial(url.protocol) && url.host ? url.protocol + '//' + url.host : 'null';
|
|
6557
6565
|
url.href = url.toString();
|
|
6558
6566
|
return url;
|
|
@@ -6572,12 +6580,15 @@ function toString(stringify) {
|
|
|
6572
6580
|
url = this,
|
|
6573
6581
|
protocol = url.protocol;
|
|
6574
6582
|
if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
|
|
6575
|
-
var result = protocol + (url.slashes || isSpecial(url.protocol) ? '//' : '');
|
|
6583
|
+
var result = protocol + (url.protocol && url.slashes || isSpecial(url.protocol) ? '//' : '');
|
|
6576
6584
|
|
|
6577
6585
|
if (url.username) {
|
|
6578
6586
|
result += url.username;
|
|
6579
6587
|
if (url.password) result += ':' + url.password;
|
|
6580
6588
|
result += '@';
|
|
6589
|
+
} else if (url.password) {
|
|
6590
|
+
result += ':' + url.password;
|
|
6591
|
+
result += '@';
|
|
6581
6592
|
}
|
|
6582
6593
|
|
|
6583
6594
|
result += url.host + url.pathname;
|
package/client/overlay.js
CHANGED
|
@@ -14,8 +14,14 @@ var colors = {
|
|
|
14
14
|
lightgrey: "EBE7E3",
|
|
15
15
|
darkgrey: "6D7891"
|
|
16
16
|
};
|
|
17
|
+
/** @type {HTMLIFrameElement | null | undefined} */
|
|
18
|
+
|
|
17
19
|
var iframeContainerElement;
|
|
20
|
+
/** @type {HTMLDivElement | null | undefined} */
|
|
21
|
+
|
|
18
22
|
var containerElement;
|
|
23
|
+
/** @type {Array<(element: HTMLDivElement) => void>} */
|
|
24
|
+
|
|
19
25
|
var onLoadQueue = [];
|
|
20
26
|
ansiHTML.setColors(colors);
|
|
21
27
|
|
|
@@ -34,7 +40,11 @@ function createContainer() {
|
|
|
34
40
|
iframeContainerElement.style.zIndex = 9999999999;
|
|
35
41
|
|
|
36
42
|
iframeContainerElement.onload = function () {
|
|
37
|
-
containerElement =
|
|
43
|
+
containerElement =
|
|
44
|
+
/** @type {Document} */
|
|
45
|
+
|
|
46
|
+
/** @type {HTMLIFrameElement} */
|
|
47
|
+
iframeContainerElement.contentDocument.createElement("div");
|
|
38
48
|
containerElement.id = "webpack-dev-server-client-overlay-div";
|
|
39
49
|
containerElement.style.position = "fixed";
|
|
40
50
|
containerElement.style.boxSizing = "border-box";
|
|
@@ -62,7 +72,8 @@ function createContainer() {
|
|
|
62
72
|
closeButtonElement.style.fontWeight = "bold";
|
|
63
73
|
closeButtonElement.style.color = "white";
|
|
64
74
|
closeButtonElement.style.cursor = "pointer";
|
|
65
|
-
closeButtonElement.style.cssFloat = "right";
|
|
75
|
+
closeButtonElement.style.cssFloat = "right"; // @ts-ignore
|
|
76
|
+
|
|
66
77
|
closeButtonElement.style.styleFloat = "right";
|
|
67
78
|
closeButtonElement.addEventListener("click", function () {
|
|
68
79
|
hide();
|
|
@@ -71,16 +82,27 @@ function createContainer() {
|
|
|
71
82
|
containerElement.appendChild(closeButtonElement);
|
|
72
83
|
containerElement.appendChild(document.createElement("br"));
|
|
73
84
|
containerElement.appendChild(document.createElement("br"));
|
|
85
|
+
/** @type {Document} */
|
|
86
|
+
|
|
87
|
+
/** @type {HTMLIFrameElement} */
|
|
74
88
|
iframeContainerElement.contentDocument.body.appendChild(containerElement);
|
|
75
89
|
onLoadQueue.forEach(function (onLoad) {
|
|
76
|
-
onLoad(
|
|
90
|
+
onLoad(
|
|
91
|
+
/** @type {HTMLDivElement} */
|
|
92
|
+
containerElement);
|
|
77
93
|
});
|
|
78
94
|
onLoadQueue = [];
|
|
95
|
+
/** @type {HTMLIFrameElement} */
|
|
96
|
+
|
|
79
97
|
iframeContainerElement.onload = null;
|
|
80
98
|
};
|
|
81
99
|
|
|
82
100
|
document.body.appendChild(iframeContainerElement);
|
|
83
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* @param {(element: HTMLDivElement) => void} callback
|
|
104
|
+
*/
|
|
105
|
+
|
|
84
106
|
|
|
85
107
|
function ensureOverlayExists(callback) {
|
|
86
108
|
if (containerElement) {
|
|
@@ -109,6 +131,12 @@ function hide() {
|
|
|
109
131
|
iframeContainerElement = null;
|
|
110
132
|
containerElement = null;
|
|
111
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* @param {string} type
|
|
136
|
+
* @param {string | { file?: string, moduleName?: string, loc?: string, message?: string }} item
|
|
137
|
+
* @returns {{ header: string, body: string }}
|
|
138
|
+
*/
|
|
139
|
+
|
|
112
140
|
|
|
113
141
|
function formatProblem(type, item) {
|
|
114
142
|
var header = type === "warning" ? "WARNING" : "ERROR";
|
|
@@ -131,6 +159,11 @@ function formatProblem(type, item) {
|
|
|
131
159
|
};
|
|
132
160
|
} // Compilation with errors (e.g. syntax error or missing modules).
|
|
133
161
|
|
|
162
|
+
/**
|
|
163
|
+
* @param {string} type
|
|
164
|
+
* @param {Array<string | { file?: string, moduleName?: string, loc?: string, message?: string }>} messages
|
|
165
|
+
*/
|
|
166
|
+
|
|
134
167
|
|
|
135
168
|
function show(type, messages) {
|
|
136
169
|
ensureOverlayExists(function () {
|
|
@@ -154,6 +187,8 @@ function show(type, messages) {
|
|
|
154
187
|
entryElement.appendChild(messageTextNode);
|
|
155
188
|
entryElement.appendChild(document.createElement("br"));
|
|
156
189
|
entryElement.appendChild(document.createElement("br"));
|
|
190
|
+
/** @type {HTMLDivElement} */
|
|
191
|
+
|
|
157
192
|
containerElement.appendChild(entryElement);
|
|
158
193
|
});
|
|
159
194
|
});
|
package/client/socket.js
CHANGED
|
@@ -11,12 +11,20 @@ typeof __webpack_dev_server_client__ !== "undefined" ? typeof __webpack_dev_serv
|
|
|
11
11
|
var retries = 0;
|
|
12
12
|
var maxRetries = 10;
|
|
13
13
|
var client = null;
|
|
14
|
+
/**
|
|
15
|
+
* @param {string} url
|
|
16
|
+
* @param {{ [handler: string]: (data?: any, params?: any) => any }} handlers
|
|
17
|
+
* @param {number} [reconnect]
|
|
18
|
+
*/
|
|
14
19
|
|
|
15
20
|
var socket = function initSocket(url, handlers, reconnect) {
|
|
16
21
|
client = new Client(url);
|
|
17
22
|
client.onOpen(function () {
|
|
18
23
|
retries = 0;
|
|
19
|
-
|
|
24
|
+
|
|
25
|
+
if (typeof reconnect !== "undefined") {
|
|
26
|
+
maxRetries = reconnect;
|
|
27
|
+
}
|
|
20
28
|
});
|
|
21
29
|
client.onClose(function () {
|
|
22
30
|
if (retries === 0) {
|
|
@@ -38,7 +46,11 @@ var socket = function initSocket(url, handlers, reconnect) {
|
|
|
38
46
|
}, retryInMs);
|
|
39
47
|
}
|
|
40
48
|
});
|
|
41
|
-
client.onMessage(
|
|
49
|
+
client.onMessage(
|
|
50
|
+
/**
|
|
51
|
+
* @param {any} data
|
|
52
|
+
*/
|
|
53
|
+
function (data) {
|
|
42
54
|
var message = JSON.parse(data);
|
|
43
55
|
|
|
44
56
|
if (handlers[message.type]) {
|
|
@@ -1,9 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL
|
|
3
|
+
* @returns {string}
|
|
4
|
+
*/
|
|
5
|
+
function format(objURL) {
|
|
6
|
+
var protocol = objURL.protocol || "";
|
|
7
|
+
|
|
8
|
+
if (protocol && protocol.substr(-1) !== ":") {
|
|
9
|
+
protocol += ":";
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
var auth = objURL.auth || "";
|
|
13
|
+
|
|
14
|
+
if (auth) {
|
|
15
|
+
auth = encodeURIComponent(auth);
|
|
16
|
+
auth = auth.replace(/%3A/i, ":");
|
|
17
|
+
auth += "@";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var host = "";
|
|
21
|
+
|
|
22
|
+
if (objURL.hostname) {
|
|
23
|
+
host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
|
|
24
|
+
|
|
25
|
+
if (objURL.port) {
|
|
26
|
+
host += ":".concat(objURL.port);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var pathname = objURL.pathname || "";
|
|
31
|
+
|
|
32
|
+
if (objURL.slashes) {
|
|
33
|
+
host = "//".concat(host || "");
|
|
34
|
+
|
|
35
|
+
if (pathname && pathname.charAt(0) !== "/") {
|
|
36
|
+
pathname = "/".concat(pathname);
|
|
37
|
+
}
|
|
38
|
+
} else if (!host) {
|
|
39
|
+
host = "";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var search = objURL.search || "";
|
|
43
|
+
|
|
44
|
+
if (search && search.charAt(0) !== "?") {
|
|
45
|
+
search = "?".concat(search);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
var hash = objURL.hash || "";
|
|
49
|
+
|
|
50
|
+
if (hash && hash.charAt(0) !== "#") {
|
|
51
|
+
hash = "#".concat(hash);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
pathname = pathname.replace(/[?#]/g,
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} match
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
59
|
+
function (match) {
|
|
60
|
+
return encodeURIComponent(match);
|
|
61
|
+
});
|
|
62
|
+
search = search.replace("#", "%23");
|
|
63
|
+
return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @param {URL & { fromCurrentScript?: boolean }} parsedURL
|
|
67
|
+
* @returns {string}
|
|
68
|
+
*/
|
|
69
|
+
|
|
3
70
|
|
|
4
71
|
function createSocketURL(parsedURL) {
|
|
5
72
|
var hostname = parsedURL.hostname; // Node.js module parses it as `::`
|
|
6
|
-
// `new URL(urlString, [
|
|
73
|
+
// `new URL(urlString, [baseURLString])` parses it as '[::]'
|
|
7
74
|
|
|
8
75
|
var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]"; // why do we need this check?
|
|
9
76
|
// hostname n/a for file protocol (example, when using electron, ionic)
|
|
@@ -57,7 +124,7 @@ function createSocketURL(parsedURL) {
|
|
|
57
124
|
socketURLPathname = parsedURL.pathname;
|
|
58
125
|
}
|
|
59
126
|
|
|
60
|
-
return
|
|
127
|
+
return format({
|
|
61
128
|
protocol: socketURLProtocol,
|
|
62
129
|
auth: socketURLAuth,
|
|
63
130
|
hostname: socketURLHostname,
|
package/client/utils/parseURL.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import url from "url";
|
|
2
1
|
import getCurrentScriptSource from "./getCurrentScriptSource.js";
|
|
2
|
+
/**
|
|
3
|
+
* @param {string} resourceQuery
|
|
4
|
+
* @returns {{ [key: string]: string | boolean }}
|
|
5
|
+
*/
|
|
3
6
|
|
|
4
7
|
function parseURL(resourceQuery) {
|
|
8
|
+
/** @type {{ [key: string]: string }} */
|
|
5
9
|
var options = {};
|
|
6
10
|
|
|
7
11
|
if (typeof resourceQuery === "string" && resourceQuery !== "") {
|
|
@@ -14,25 +18,19 @@ function parseURL(resourceQuery) {
|
|
|
14
18
|
} else {
|
|
15
19
|
// Else, get the url from the <script> this file was called with.
|
|
16
20
|
var scriptSource = getCurrentScriptSource();
|
|
21
|
+
var scriptSourceURL;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
// The placeholder `baseURL` with `window.location.href`,
|
|
25
|
+
// is to allow parsing of path-relative or protocol-relative URLs,
|
|
26
|
+
// and will have no effect if `scriptSource` is a fully valid URL.
|
|
27
|
+
scriptSourceURL = new URL(scriptSource, self.location.href);
|
|
28
|
+
} catch (error) {// URL parsing failed, do nothing.
|
|
29
|
+
// We will still proceed to see if we can recover using `resourceQuery`
|
|
30
|
+
}
|
|
17
31
|
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
// The placeholder `baseURL` with `window.location.href`,
|
|
23
|
-
// is to allow parsing of path-relative or protocol-relative URLs,
|
|
24
|
-
// and will have no effect if `scriptSource` is a fully valid URL.
|
|
25
|
-
scriptSourceURL = new URL(scriptSource, self.location.href);
|
|
26
|
-
} catch (error) {// URL parsing failed, do nothing.
|
|
27
|
-
// We will still proceed to see if we can recover using `resourceQuery`
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (scriptSourceURL) {
|
|
31
|
-
options = scriptSourceURL;
|
|
32
|
-
options.fromCurrentScript = true;
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
options = url.parse(self.location.href, true, true);
|
|
32
|
+
if (scriptSourceURL) {
|
|
33
|
+
options = scriptSourceURL;
|
|
36
34
|
options.fromCurrentScript = true;
|
|
37
35
|
}
|
|
38
36
|
}
|