webpack-dev-server 4.3.1 → 4.4.0

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.
@@ -91,33 +91,61 @@ function _createClass(Constructor, protoProps, staticProps) {
91
91
  }
92
92
 
93
93
  var LogType = Object.freeze({
94
- error: "error",
94
+ error:
95
+ /** @type {"error"} */
96
+ "error",
95
97
  // message, c style arguments
96
- warn: "warn",
98
+ warn:
99
+ /** @type {"warn"} */
100
+ "warn",
97
101
  // message, c style arguments
98
- info: "info",
102
+ info:
103
+ /** @type {"info"} */
104
+ "info",
99
105
  // message, c style arguments
100
- log: "log",
106
+ log:
107
+ /** @type {"log"} */
108
+ "log",
101
109
  // message, c style arguments
102
- debug: "debug",
110
+ debug:
111
+ /** @type {"debug"} */
112
+ "debug",
103
113
  // message, c style arguments
104
- trace: "trace",
114
+ trace:
115
+ /** @type {"trace"} */
116
+ "trace",
105
117
  // no arguments
106
- group: "group",
118
+ group:
119
+ /** @type {"group"} */
120
+ "group",
107
121
  // [label]
108
- groupCollapsed: "groupCollapsed",
122
+ groupCollapsed:
123
+ /** @type {"groupCollapsed"} */
124
+ "groupCollapsed",
109
125
  // [label]
110
- groupEnd: "groupEnd",
126
+ groupEnd:
127
+ /** @type {"groupEnd"} */
128
+ "groupEnd",
111
129
  // [label]
112
- profile: "profile",
130
+ profile:
131
+ /** @type {"profile"} */
132
+ "profile",
113
133
  // [profileName]
114
- profileEnd: "profileEnd",
134
+ profileEnd:
135
+ /** @type {"profileEnd"} */
136
+ "profileEnd",
115
137
  // [profileName]
116
- time: "time",
138
+ time:
139
+ /** @type {"time"} */
140
+ "time",
117
141
  // name, time as [seconds, nanoseconds]
118
- clear: "clear",
142
+ clear:
143
+ /** @type {"clear"} */
144
+ "clear",
119
145
  // no arguments
120
- status: "status" // message, arguments
146
+ status:
147
+ /** @type {"status"} */
148
+ "status" // message, arguments
121
149
 
122
150
  });
123
151
  exports.LogType = LogType;
@@ -314,6 +342,7 @@ var WebpackLogger = /*#__PURE__*/function () {
314
342
  if (this[TIMERS_AGGREGATES_SYMBOL] === undefined) return;
315
343
  var time = this[TIMERS_AGGREGATES_SYMBOL].get(label);
316
344
  if (time === undefined) return;
345
+ this[TIMERS_AGGREGATES_SYMBOL].delete(label);
317
346
  this[LOG_SYMBOL](LogType.time, [label].concat(_toConsumableArray(time)));
318
347
  }
319
348
  }]);
@@ -2958,7 +2958,8 @@ if ('ab'.split(/(?:ab)*/).length !== 2 || '.'.split(/(.?)(.?)/).length !== 4 ||
2958
2958
  }
2959
2959
 
2960
2960
  var output = [],
2961
- flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.extended ? 'x' : '') + (separator.sticky ? 'y' : ''),
2961
+ flags = (separator.ignoreCase ? 'i' : '') + (separator.multiline ? 'm' : '') + (separator.extended ? 'x' : '') + ( // Proposed for ES6
2962
+ separator.sticky ? 'y' : ''),
2962
2963
  // Firefox 3+
2963
2964
  lastLastIndex = 0,
2964
2965
  // Make `global` and avoid `lastIndex` issues by working with a copy
package/client/socket.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* global __webpack_dev_server_client__ */
2
- import WebSocketClient from "./clients/WebSocketClient.js"; // this WebsocketClient is here as a default fallback, in case the client is not injected
2
+ import WebSocketClient from "./clients/WebSocketClient.js";
3
+ import { log } from "./utils/log.js"; // this WebsocketClient is here as a default fallback, in case the client is not injected
3
4
 
4
5
  /* eslint-disable camelcase */
5
6
 
@@ -9,12 +10,14 @@ typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_ser
9
10
  /* eslint-enable camelcase */
10
11
 
11
12
  var retries = 0;
13
+ var maxRetries = 10;
12
14
  var client = null;
13
15
 
14
- var socket = function initSocket(url, handlers) {
16
+ var socket = function initSocket(url, handlers, reconnect) {
15
17
  client = new Client(url);
16
18
  client.onOpen(function () {
17
19
  retries = 0;
20
+ maxRetries = reconnect;
18
21
  });
19
22
  client.onClose(function () {
20
23
  if (retries === 0) {
@@ -24,12 +27,13 @@ var socket = function initSocket(url, handlers) {
24
27
 
25
28
  client = null; // After 10 retries stop trying, to prevent logspam.
26
29
 
27
- if (retries <= 10) {
30
+ if (retries < maxRetries) {
28
31
  // Exponentially increase timeout to reconnect.
29
32
  // Respectfully copied from the package `got`.
30
33
  // eslint-disable-next-line no-mixed-operators, no-restricted-properties
31
34
  var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
32
35
  retries += 1;
36
+ log.info("Trying to reconnect...");
33
37
  setTimeout(function () {
34
38
  socket(url, handlers);
35
39
  }, retryInMs);
package/lib/Server.js CHANGED
@@ -155,7 +155,7 @@ class Server {
155
155
  if (typeof this.options.client.webSocketURL.protocol !== "undefined") {
156
156
  protocol = this.options.client.webSocketURL.protocol;
157
157
  } else {
158
- protocol = this.options.https ? "wss:" : "ws:";
158
+ protocol = this.options.server.type === "http" ? "ws:" : "wss:";
159
159
  }
160
160
 
161
161
  searchParams.set("protocol", protocol);
@@ -258,6 +258,10 @@ class Server {
258
258
  searchParams.set("logging", this.options.client.logging);
259
259
  }
260
260
 
261
+ if (typeof this.options.client.reconnect !== "undefined") {
262
+ searchParams.set("reconnect", this.options.client.reconnect);
263
+ }
264
+
261
265
  webSocketURL = searchParams.toString();
262
266
  }
263
267
 
@@ -474,6 +478,14 @@ class Server {
474
478
  };
475
479
  }
476
480
 
481
+ if (typeof options.client.reconnect === "undefined") {
482
+ options.client.reconnect = 10;
483
+ } else if (options.client.reconnect === true) {
484
+ options.client.reconnect = Infinity;
485
+ } else if (options.client.reconnect === false) {
486
+ options.client.reconnect = 0;
487
+ }
488
+
477
489
  // Respect infrastructureLogging.level
478
490
  if (typeof options.client.logging === "undefined") {
479
491
  options.client.logging = compilerOptions.infrastructureLogging
@@ -508,23 +520,51 @@ class Server {
508
520
  ? options.hot
509
521
  : true;
510
522
 
511
- // if the user enables http2, we can safely enable https
512
- if ((options.http2 && !options.https) || options.https === true) {
513
- options.https = {
514
- requestCert: false,
523
+ const isHTTPs = Boolean(options.https);
524
+ const isSPDY = Boolean(options.http2);
525
+
526
+ options.server = {
527
+ type:
528
+ // eslint-disable-next-line no-nested-ternary
529
+ typeof options.server === "string"
530
+ ? options.server
531
+ : // eslint-disable-next-line no-nested-ternary
532
+ typeof (options.server || {}).type === "string"
533
+ ? options.server.type
534
+ : // eslint-disable-next-line no-nested-ternary
535
+ isSPDY
536
+ ? "spdy"
537
+ : isHTTPs
538
+ ? "https"
539
+ : "http",
540
+ options: {
541
+ ...options.https,
542
+ ...(options.server || {}).options,
543
+ },
544
+ };
545
+
546
+ if (
547
+ options.server.type === "spdy" &&
548
+ typeof options.server.options.spdy === "undefined"
549
+ ) {
550
+ options.server.options.spdy = {
551
+ protocols: ["h2", "http/1.1"],
515
552
  };
516
553
  }
517
554
 
518
- // https option
519
- if (options.https) {
555
+ if (options.server.type === "https" || options.server.type === "spdy") {
556
+ if (typeof options.server.options.requestCert === "undefined") {
557
+ options.server.options.requestCert = false;
558
+ }
559
+
520
560
  // TODO remove the `cacert` option in favor `ca` in the next major release
521
561
  for (const property of ["cacert", "ca", "cert", "crl", "key", "pfx"]) {
522
- if (typeof options.https[property] === "undefined") {
562
+ if (typeof options.server.options[property] === "undefined") {
523
563
  // eslint-disable-next-line no-continue
524
564
  continue;
525
565
  }
526
566
 
527
- const value = options.https[property];
567
+ const value = options.server.options[property];
528
568
  const readFile = (item) => {
529
569
  if (
530
570
  Buffer.isBuffer(item) ||
@@ -547,14 +587,14 @@ class Server {
547
587
  }
548
588
  };
549
589
 
550
- options.https[property] = Array.isArray(value)
590
+ options.server.options[property] = Array.isArray(value)
551
591
  ? value.map((item) => readFile(item))
552
592
  : readFile(value);
553
593
  }
554
594
 
555
595
  let fakeCert;
556
596
 
557
- if (!options.https.key || !options.https.cert) {
597
+ if (!options.server.options.key || !options.server.options.cert) {
558
598
  const certificateDir = Server.findCacheDir();
559
599
  const certificatePath = path.join(certificateDir, "server.pem");
560
600
  let certificateExists;
@@ -577,7 +617,7 @@ class Server {
577
617
  const del = require("del");
578
618
 
579
619
  this.logger.info(
580
- "SSL Certificate is more than 30 days old. Removing..."
620
+ "SSL certificate is more than 30 days old. Removing..."
581
621
  );
582
622
 
583
623
  await del([certificatePath], { force: true });
@@ -587,7 +627,7 @@ class Server {
587
627
  }
588
628
 
589
629
  if (!certificateExists) {
590
- this.logger.info("Generating SSL Certificate...");
630
+ this.logger.info("Generating SSL certificate...");
591
631
 
592
632
  const selfsigned = require("selfsigned");
593
633
  const attributes = [{ name: "commonName", value: "localhost" }];
@@ -669,20 +709,20 @@ class Server {
669
709
  this.logger.info(`SSL certificate: ${certificatePath}`);
670
710
  }
671
711
 
672
- if (options.https.cacert) {
673
- if (options.https.ca) {
712
+ if (options.server.options.cacert) {
713
+ if (options.server.options.ca) {
674
714
  this.logger.warn(
675
- "Do not specify 'https.ca' and 'https.cacert' options together, the 'https.ca' option will be used."
715
+ "Do not specify 'ca' and 'cacert' options together, the 'ca' option will be used."
676
716
  );
677
717
  } else {
678
- options.https.ca = options.https.cacert;
718
+ options.server.options.ca = options.server.options.cacert;
679
719
  }
680
720
 
681
- delete options.https.cacert;
721
+ delete options.server.options.cacert;
682
722
  }
683
723
 
684
- options.https.key = options.https.key || fakeCert;
685
- options.https.cert = options.https.cert || fakeCert;
724
+ options.server.options.key = options.server.options.key || fakeCert;
725
+ options.server.options.cert = options.server.options.cert || fakeCert;
686
726
  }
687
727
 
688
728
  if (typeof options.ipc === "boolean") {
@@ -1547,28 +1587,11 @@ class Server {
1547
1587
  }
1548
1588
 
1549
1589
  createServer() {
1550
- if (this.options.https) {
1551
- if (this.options.http2) {
1552
- // TODO: we need to replace spdy with http2 which is an internal module
1553
- this.server = require("spdy").createServer(
1554
- {
1555
- ...this.options.https,
1556
- spdy: {
1557
- protocols: ["h2", "http/1.1"],
1558
- },
1559
- },
1560
- this.app
1561
- );
1562
- } else {
1563
- const https = require("https");
1564
-
1565
- this.server = https.createServer(this.options.https, this.app);
1566
- }
1567
- } else {
1568
- const http = require("http");
1569
-
1570
- this.server = http.createServer(this.app);
1571
- }
1590
+ // eslint-disable-next-line import/no-dynamic-require
1591
+ this.server = require(this.options.server.type).createServer(
1592
+ this.options.server.options,
1593
+ this.app
1594
+ );
1572
1595
 
1573
1596
  this.server.on("connection", (socket) => {
1574
1597
  // Add socket to list
@@ -1627,6 +1650,10 @@ class Server {
1627
1650
  this.sendMessage([client], "progress", this.options.client.progress);
1628
1651
  }
1629
1652
 
1653
+ if (this.options.client && this.options.client.reconnect) {
1654
+ this.sendMessage([client], "reconnect", this.options.client.reconnect);
1655
+ }
1656
+
1630
1657
  if (this.options.client && this.options.client.overlay) {
1631
1658
  this.sendMessage([client], "overlay", this.options.client.overlay);
1632
1659
  }
@@ -1680,7 +1707,7 @@ class Server {
1680
1707
  bonjour.publish({
1681
1708
  name: `Webpack Dev Server ${os.hostname()}:${this.options.port}`,
1682
1709
  port: this.options.port,
1683
- type: this.options.https ? "https" : "http",
1710
+ type: this.options.server.type === "http" ? "http" : "https",
1684
1711
  subtypes: ["webpack"],
1685
1712
  ...this.options.bonjour,
1686
1713
  });
@@ -1731,7 +1758,7 @@ class Server {
1731
1758
  if (this.options.ipc) {
1732
1759
  this.logger.info(`Project is running at: "${this.server.address()}"`);
1733
1760
  } else {
1734
- const protocol = this.options.https ? "https" : "http";
1761
+ const protocol = this.options.server.type === "http" ? "http" : "https";
1735
1762
  const { address, port } = this.server.address();
1736
1763
  const prettyPrintURL = (newHostname) =>
1737
1764
  url.format({ protocol, hostname: newHostname, port, pathname: "/" });
@@ -1850,7 +1877,9 @@ class Server {
1850
1877
 
1851
1878
  if (this.options.bonjour) {
1852
1879
  const bonjourProtocol =
1853
- this.options.bonjour.type || this.options.https ? "https" : "http";
1880
+ this.options.bonjour.type || this.options.server.type === "http"
1881
+ ? "http"
1882
+ : "https";
1854
1883
 
1855
1884
  this.logger.info(
1856
1885
  `Broadcasting "${bonjourProtocol}" with subtype of "webpack" via ZeroConf DNS (Bonjour)`
@@ -2159,7 +2188,9 @@ class Server {
2159
2188
  }
2160
2189
 
2161
2190
  startCallback(callback) {
2162
- this.start().then(() => callback(null), callback);
2191
+ this.start()
2192
+ .then(() => callback(null), callback)
2193
+ .catch(callback);
2163
2194
  }
2164
2195
 
2165
2196
  async stop() {
@@ -2219,7 +2250,9 @@ class Server {
2219
2250
  }
2220
2251
 
2221
2252
  stopCallback(callback) {
2222
- this.stop().then(() => callback(null), callback);
2253
+ this.stop()
2254
+ .then(() => callback(null), callback)
2255
+ .catch(callback);
2223
2256
  }
2224
2257
 
2225
2258
  // TODO remove in the next major release