webpack-dev-server 4.13.1 → 4.13.3

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/lib/Server.js CHANGED
@@ -6,8 +6,6 @@ const url = require("url");
6
6
  const util = require("util");
7
7
  const fs = require("graceful-fs");
8
8
  const ipaddr = require("ipaddr.js");
9
- const defaultGateway = require("default-gateway");
10
- const express = require("express");
11
9
  const { validate } = require("schema-utils");
12
10
  const schema = require("./options.json");
13
11
 
@@ -186,7 +184,6 @@ const schema = require("./options.json");
186
184
  * @property {boolean} [magicHtml]
187
185
  * @property {"auto" | "all" | string | string[]} [allowedHosts]
188
186
  * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback]
189
- * @property {boolean} [setupExitSignals]
190
187
  * @property {boolean | Record<string, never> | BonjourOptions} [bonjour]
191
188
  * @property {string | string[] | WatchFiles | Array<string | WatchFiles>} [watchFiles]
192
189
  * @property {boolean | string | Static | Array<string | Static>} [static]
@@ -211,6 +208,34 @@ if (!process.env.WEBPACK_SERVE) {
211
208
  process.env.WEBPACK_SERVE = true;
212
209
  }
213
210
 
211
+ /**
212
+ * @template T
213
+ * @param fn {(function(): any) | undefined}
214
+ * @returns {function(): T}
215
+ */
216
+ const memoize = (fn) => {
217
+ let cache = false;
218
+ /** @type {T} */
219
+ let result;
220
+
221
+ return () => {
222
+ if (cache) {
223
+ return result;
224
+ }
225
+
226
+ result = /** @type {function(): any} */ (fn)();
227
+ cache = true;
228
+ // Allow to clean up memory for fn
229
+ // and all dependent resources
230
+ // eslint-disable-next-line no-undefined
231
+ fn = undefined;
232
+
233
+ return result;
234
+ };
235
+ };
236
+
237
+ const getExpress = memoize(() => require("express"));
238
+
214
239
  class Server {
215
240
  /**
216
241
  * @param {Configuration | Compiler | MultiCompiler} options
@@ -343,7 +368,7 @@ class Server {
343
368
  */
344
369
  static async internalIP(family) {
345
370
  try {
346
- const { gateway } = await defaultGateway[family]();
371
+ const { gateway } = await require("default-gateway")[family]();
347
372
  return Server.findIp(gateway);
348
373
  } catch {
349
374
  // ignore
@@ -356,7 +381,7 @@ class Server {
356
381
  */
357
382
  static internalIPSync(family) {
358
383
  try {
359
- const { gateway } = defaultGateway[family].sync();
384
+ const { gateway } = require("default-gateway")[family].sync();
360
385
  return Server.findIp(gateway);
361
386
  } catch {
362
387
  // ignore
@@ -1145,7 +1170,7 @@ class Server {
1145
1170
  // Ignore error
1146
1171
  }
1147
1172
 
1148
- // It is file
1173
+ // It is a file
1149
1174
  return stats ? fs.readFileSync(item) : item;
1150
1175
  }
1151
1176
  };
@@ -1899,8 +1924,7 @@ class Server {
1899
1924
  */
1900
1925
  setupApp() {
1901
1926
  /** @type {import("express").Application | undefined}*/
1902
- // eslint-disable-next-line new-cap
1903
- this.app = new /** @type {any} */ (express)();
1927
+ this.app = new /** @type {any} */ (getExpress())();
1904
1928
  }
1905
1929
 
1906
1930
  /**
@@ -2319,7 +2343,7 @@ class Server {
2319
2343
  middlewares.push({
2320
2344
  name: "express-static",
2321
2345
  path: publicPath,
2322
- middleware: express.static(
2346
+ middleware: getExpress().static(
2323
2347
  staticOption.directory,
2324
2348
  staticOption.staticOptions
2325
2349
  ),
@@ -2374,7 +2398,7 @@ class Server {
2374
2398
  middlewares.push({
2375
2399
  name: "express-static",
2376
2400
  path: publicPath,
2377
- middleware: express.static(
2401
+ middleware: getExpress().static(
2378
2402
  staticOption.directory,
2379
2403
  staticOption.staticOptions
2380
2404
  ),
@@ -2893,7 +2917,11 @@ class Server {
2893
2917
  }
2894
2918
 
2895
2919
  if (/** @type {NormalizedOpen[]} */ (this.options.open).length > 0) {
2896
- const openTarget = prettyPrintURL(this.options.host || "localhost");
2920
+ const openTarget = prettyPrintURL(
2921
+ !this.options.host || this.options.host === "0.0.0.0"
2922
+ ? "localhost"
2923
+ : this.options.host
2924
+ );
2897
2925
 
2898
2926
  this.openBrowser(openTarget);
2899
2927
  }
@@ -3254,7 +3282,7 @@ class Server {
3254
3282
  */
3255
3283
  (error) => {
3256
3284
  if (error.code === "ECONNREFUSED") {
3257
- // No other server listening on this socket so it can be safely removed
3285
+ // No other server listening on this socket, so it can be safely removed
3258
3286
  fs.unlinkSync(/** @type {string} */ (this.options.ipc));
3259
3287
 
3260
3288
  resolve();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "4.13.1",
3
+ "version": "4.13.3",
4
4
  "description": "Serves a webpack app. Updates the browser on changes.",
5
5
  "bin": "bin/webpack-dev-server.js",
6
6
  "main": "lib/Server.js",