webpack-dev-server 4.11.1 → 4.13.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.
package/bin/cli-flags.js CHANGED
@@ -153,6 +153,23 @@ module.exports = {
153
153
  simpleType: "boolean",
154
154
  multiple: false,
155
155
  },
156
+ "client-overlay-runtime-errors": {
157
+ configs: [
158
+ {
159
+ type: "boolean",
160
+ multiple: false,
161
+ description:
162
+ "Enables a full-screen overlay in the browser when there are uncaught runtime errors.",
163
+ negatedDescription:
164
+ "Disables the full-screen overlay in the browser when there are uncaught runtime errors.",
165
+ path: "client.overlay.runtimeErrors",
166
+ },
167
+ ],
168
+ description:
169
+ "Enables a full-screen overlay in the browser when there are uncaught runtime errors.",
170
+ simpleType: "boolean",
171
+ multiple: false,
172
+ },
156
173
  "client-progress": {
157
174
  configs: [
158
175
  {
@@ -58,6 +58,18 @@ const isInstalled = (packageName) => {
58
58
  // eslint-disable-next-line no-cond-assign
59
59
  } while (dir !== (dir = path.dirname(dir)));
60
60
 
61
+ // https://github.com/nodejs/node/blob/v18.9.1/lib/internal/modules/cjs/loader.js#L1274
62
+ // @ts-ignore
63
+ for (const internalPath of require("module").globalPaths) {
64
+ try {
65
+ if (fs.statSync(path.join(internalPath, packageName)).isDirectory()) {
66
+ return true;
67
+ }
68
+ } catch (_error) {
69
+ // Nothing
70
+ }
71
+ }
72
+
61
73
  return false;
62
74
  };
63
75
 
@@ -1,22 +1,18 @@
1
1
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
-
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4
-
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
3
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
-
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
6
  import SockJS from "../modules/sockjs-client/index.js";
8
7
  import { log } from "../utils/log.js";
9
-
10
8
  var SockJSClient = /*#__PURE__*/function () {
11
9
  /**
12
10
  * @param {string} url
13
11
  */
14
12
  function SockJSClient(url) {
15
13
  _classCallCheck(this, SockJSClient);
16
-
17
14
  // SockJS requires `http` and `https` protocols
18
15
  this.sock = new SockJS(url.replace(/^ws:/i, "http:").replace(/^wss:/i, "https:"));
19
-
20
16
  this.sock.onerror =
21
17
  /**
22
18
  * @param {Error} error
@@ -25,30 +21,29 @@ var SockJSClient = /*#__PURE__*/function () {
25
21
  log.error(error);
26
22
  };
27
23
  }
24
+
28
25
  /**
29
26
  * @param {(...args: any[]) => void} f
30
27
  */
31
-
32
-
33
28
  _createClass(SockJSClient, [{
34
29
  key: "onOpen",
35
30
  value: function onOpen(f) {
36
31
  this.sock.onopen = f;
37
32
  }
33
+
38
34
  /**
39
35
  * @param {(...args: any[]) => void} f
40
36
  */
41
-
42
37
  }, {
43
38
  key: "onClose",
44
39
  value: function onClose(f) {
45
40
  this.sock.onclose = f;
46
- } // call f with the message string as the first argument
41
+ }
47
42
 
43
+ // call f with the message string as the first argument
48
44
  /**
49
45
  * @param {(...args: any[]) => void} f
50
46
  */
51
-
52
47
  }, {
53
48
  key: "onMessage",
54
49
  value: function onMessage(f) {
@@ -61,8 +56,6 @@ var SockJSClient = /*#__PURE__*/function () {
61
56
  };
62
57
  }
63
58
  }]);
64
-
65
59
  return SockJSClient;
66
60
  }();
67
-
68
61
  export { SockJSClient as default };
@@ -1,48 +1,43 @@
1
1
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
2
-
3
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
4
-
2
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
3
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
-
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
6
  import { log } from "../utils/log.js";
8
-
9
7
  var WebSocketClient = /*#__PURE__*/function () {
10
8
  /**
11
9
  * @param {string} url
12
10
  */
13
11
  function WebSocketClient(url) {
14
12
  _classCallCheck(this, WebSocketClient);
15
-
16
13
  this.client = new WebSocket(url);
17
-
18
14
  this.client.onerror = function (error) {
19
15
  log.error(error);
20
16
  };
21
17
  }
18
+
22
19
  /**
23
20
  * @param {(...args: any[]) => void} f
24
21
  */
25
-
26
-
27
22
  _createClass(WebSocketClient, [{
28
23
  key: "onOpen",
29
24
  value: function onOpen(f) {
30
25
  this.client.onopen = f;
31
26
  }
27
+
32
28
  /**
33
29
  * @param {(...args: any[]) => void} f
34
30
  */
35
-
36
31
  }, {
37
32
  key: "onClose",
38
33
  value: function onClose(f) {
39
34
  this.client.onclose = f;
40
- } // call f with the message string as the first argument
35
+ }
41
36
 
37
+ // call f with the message string as the first argument
42
38
  /**
43
39
  * @param {(...args: any[]) => void} f
44
40
  */
45
-
46
41
  }, {
47
42
  key: "onMessage",
48
43
  value: function onMessage(f) {
@@ -51,8 +46,6 @@ var WebSocketClient = /*#__PURE__*/function () {
51
46
  };
52
47
  }
53
48
  }]);
54
-
55
49
  return WebSocketClient;
56
50
  }();
57
-
58
51
  export { WebSocketClient as default };
package/client/index.js CHANGED
@@ -1,26 +1,26 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
6
  /* global __resourceQuery, __webpack_hash__ */
8
7
  /// <reference types="webpack/module" />
9
8
  import webpackHotLog from "webpack/hot/log.js";
10
9
  import stripAnsi from "./utils/stripAnsi.js";
11
10
  import parseURL from "./utils/parseURL.js";
12
11
  import socket from "./socket.js";
13
- import { formatProblem, show, hide } from "./overlay.js";
12
+ import { formatProblem, createOverlay } from "./overlay.js";
14
13
  import { log, logEnabledFeatures, setLogLevel } from "./utils/log.js";
15
14
  import sendMessage from "./utils/sendMessage.js";
16
15
  import reloadApp from "./utils/reloadApp.js";
17
16
  import createSocketURL from "./utils/createSocketURL.js";
17
+
18
18
  /**
19
19
  * @typedef {Object} Options
20
20
  * @property {boolean} hot
21
21
  * @property {boolean} liveReload
22
22
  * @property {boolean} progress
23
- * @property {boolean | { warnings?: boolean, errors?: boolean, trustedTypesPolicyName?: string }} overlay
23
+ * @property {boolean | { warnings?: boolean, errors?: boolean, runtimeErrors?: boolean, trustedTypesPolicyName?: string }} overlay
24
24
  * @property {string} [logging]
25
25
  * @property {number} [reconnect]
26
26
  */
@@ -35,15 +35,14 @@ import createSocketURL from "./utils/createSocketURL.js";
35
35
  /**
36
36
  * @type {Status}
37
37
  */
38
-
39
38
  var status = {
40
39
  isUnloading: false,
41
40
  // TODO Workaround for webpack v4, `__webpack_hash__` is not replaced without HotModuleReplacement
42
41
  // eslint-disable-next-line camelcase
43
42
  currentHash: typeof __webpack_hash__ !== "undefined" ? __webpack_hash__ : ""
44
43
  };
45
- /** @type {Options} */
46
44
 
45
+ /** @type {Options} */
47
46
  var options = {
48
47
  hot: false,
49
48
  liveReload: false,
@@ -57,91 +56,90 @@ var enabledFeatures = {
57
56
  Progress: false,
58
57
  Overlay: false
59
58
  };
60
-
61
59
  if (parsedResourceQuery.hot === "true") {
62
60
  options.hot = true;
63
61
  enabledFeatures["Hot Module Replacement"] = true;
64
62
  }
65
-
66
63
  if (parsedResourceQuery["live-reload"] === "true") {
67
64
  options.liveReload = true;
68
65
  enabledFeatures["Live Reloading"] = true;
69
66
  }
70
-
71
67
  if (parsedResourceQuery.progress === "true") {
72
68
  options.progress = true;
73
69
  enabledFeatures.Progress = true;
74
70
  }
75
-
76
71
  if (parsedResourceQuery.overlay) {
77
72
  try {
78
73
  options.overlay = JSON.parse(parsedResourceQuery.overlay);
79
74
  } catch (e) {
80
75
  log.error("Error parsing overlay options from resource query:", e);
81
- } // Fill in default "true" params for partially-specified objects.
82
-
76
+ }
83
77
 
78
+ // Fill in default "true" params for partially-specified objects.
84
79
  if (typeof options.overlay === "object") {
85
80
  options.overlay = _objectSpread({
86
81
  errors: true,
87
- warnings: true
82
+ warnings: true,
83
+ runtimeErrors: true
88
84
  }, options.overlay);
89
85
  }
90
-
91
86
  enabledFeatures.Overlay = true;
92
87
  }
93
-
94
88
  if (parsedResourceQuery.logging) {
95
89
  options.logging = parsedResourceQuery.logging;
96
90
  }
97
-
98
91
  if (typeof parsedResourceQuery.reconnect !== "undefined") {
99
92
  options.reconnect = Number(parsedResourceQuery.reconnect);
100
93
  }
94
+
101
95
  /**
102
96
  * @param {string} level
103
97
  */
104
-
105
-
106
98
  function setAllLogLevel(level) {
107
99
  // This is needed because the HMR logger operate separately from dev server logger
108
100
  webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
109
101
  setLogLevel(level);
110
102
  }
111
-
112
103
  if (options.logging) {
113
104
  setAllLogLevel(options.logging);
114
105
  }
115
-
116
106
  logEnabledFeatures(enabledFeatures);
117
107
  self.addEventListener("beforeunload", function () {
118
108
  status.isUnloading = true;
119
109
  });
110
+ var overlay = typeof window !== "undefined" ? createOverlay(typeof options.overlay === "object" ? {
111
+ trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
112
+ catchRuntimeError: options.overlay.runtimeErrors
113
+ } : {
114
+ trustedTypesPolicyName: false,
115
+ catchRuntimeError: options.overlay
116
+ }) : {
117
+ send: function send() {}
118
+ };
120
119
  var onSocketMessage = {
121
120
  hot: function hot() {
122
121
  if (parsedResourceQuery.hot === "false") {
123
122
  return;
124
123
  }
125
-
126
124
  options.hot = true;
127
125
  },
128
126
  liveReload: function liveReload() {
129
127
  if (parsedResourceQuery["live-reload"] === "false") {
130
128
  return;
131
129
  }
132
-
133
130
  options.liveReload = true;
134
131
  },
135
132
  invalid: function invalid() {
136
- log.info("App updated. Recompiling..."); // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
133
+ log.info("App updated. Recompiling...");
137
134
 
135
+ // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
138
136
  if (options.overlay) {
139
- hide();
137
+ overlay.send({
138
+ type: "DISMISS"
139
+ });
140
140
  }
141
-
142
141
  sendMessage("Invalid");
143
142
  },
144
-
145
143
  /**
146
144
  * @param {string} hash
147
145
  */
@@ -150,7 +148,6 @@ var onSocketMessage = {
150
148
  status.currentHash = _hash;
151
149
  },
152
150
  logging: setAllLogLevel,
153
-
154
151
  /**
155
152
  * @param {boolean} value
156
153
  */
@@ -158,10 +155,8 @@ var onSocketMessage = {
158
155
  if (typeof document === "undefined") {
159
156
  return;
160
157
  }
161
-
162
158
  options.overlay = value;
163
159
  },
164
-
165
160
  /**
166
161
  * @param {number} value
167
162
  */
@@ -169,17 +164,14 @@ var onSocketMessage = {
169
164
  if (parsedResourceQuery.reconnect === "false") {
170
165
  return;
171
166
  }
172
-
173
167
  options.reconnect = value;
174
168
  },
175
-
176
169
  /**
177
170
  * @param {boolean} value
178
171
  */
179
172
  progress: function progress(value) {
180
173
  options.progress = value;
181
174
  },
182
-
183
175
  /**
184
176
  * @param {{ pluginName?: string, percent: number, msg: string }} data
185
177
  */
@@ -187,29 +179,27 @@ var onSocketMessage = {
187
179
  if (options.progress) {
188
180
  log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "").concat(data.percent, "% - ").concat(data.msg, "."));
189
181
  }
190
-
191
182
  sendMessage("Progress", data);
192
183
  },
193
184
  "still-ok": function stillOk() {
194
185
  log.info("Nothing changed.");
195
-
196
186
  if (options.overlay) {
197
- hide();
187
+ overlay.send({
188
+ type: "DISMISS"
189
+ });
198
190
  }
199
-
200
191
  sendMessage("StillOk");
201
192
  },
202
193
  ok: function ok() {
203
194
  sendMessage("Ok");
204
-
205
195
  if (options.overlay) {
206
- hide();
196
+ overlay.send({
197
+ type: "DISMISS"
198
+ });
207
199
  }
208
-
209
200
  reloadApp(options, status);
210
201
  },
211
202
  // TODO: remove in v5 in favor of 'static-changed'
212
-
213
203
  /**
214
204
  * @param {string} file
215
205
  */
@@ -217,7 +207,6 @@ var onSocketMessage = {
217
207
  log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
218
208
  self.location.reload();
219
209
  },
220
-
221
210
  /**
222
211
  * @param {string} file
223
212
  */
@@ -225,70 +214,59 @@ var onSocketMessage = {
225
214
  log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
226
215
  self.location.reload();
227
216
  },
228
-
229
217
  /**
230
218
  * @param {Error[]} warnings
231
219
  * @param {any} params
232
220
  */
233
221
  warnings: function warnings(_warnings, params) {
234
222
  log.warn("Warnings while compiling.");
235
-
236
223
  var printableWarnings = _warnings.map(function (error) {
237
224
  var _formatProblem = formatProblem("warning", error),
238
- header = _formatProblem.header,
239
- body = _formatProblem.body;
240
-
225
+ header = _formatProblem.header,
226
+ body = _formatProblem.body;
241
227
  return "".concat(header, "\n").concat(stripAnsi(body));
242
228
  });
243
-
244
229
  sendMessage("Warnings", printableWarnings);
245
-
246
230
  for (var i = 0; i < printableWarnings.length; i++) {
247
231
  log.warn(printableWarnings[i]);
248
232
  }
249
-
250
233
  var needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings;
251
-
252
234
  if (needShowOverlayForWarnings) {
253
- var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
254
- show("warning", _warnings, trustedTypesPolicyName || null);
235
+ overlay.send({
236
+ type: "BUILD_ERROR",
237
+ level: "warning",
238
+ messages: _warnings
239
+ });
255
240
  }
256
-
257
241
  if (params && params.preventReloading) {
258
242
  return;
259
243
  }
260
-
261
244
  reloadApp(options, status);
262
245
  },
263
-
264
246
  /**
265
247
  * @param {Error[]} errors
266
248
  */
267
249
  errors: function errors(_errors) {
268
250
  log.error("Errors while compiling. Reload prevented.");
269
-
270
251
  var printableErrors = _errors.map(function (error) {
271
252
  var _formatProblem2 = formatProblem("error", error),
272
- header = _formatProblem2.header,
273
- body = _formatProblem2.body;
274
-
253
+ header = _formatProblem2.header,
254
+ body = _formatProblem2.body;
275
255
  return "".concat(header, "\n").concat(stripAnsi(body));
276
256
  });
277
-
278
257
  sendMessage("Errors", printableErrors);
279
-
280
258
  for (var i = 0; i < printableErrors.length; i++) {
281
259
  log.error(printableErrors[i]);
282
260
  }
283
-
284
261
  var needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors;
285
-
286
262
  if (needShowOverlayForErrors) {
287
- var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
288
- show("error", _errors, trustedTypesPolicyName || null);
263
+ overlay.send({
264
+ type: "BUILD_ERROR",
265
+ level: "error",
266
+ messages: _errors
267
+ });
289
268
  }
290
269
  },
291
-
292
270
  /**
293
271
  * @param {Error} error
294
272
  */
@@ -297,11 +275,11 @@ var onSocketMessage = {
297
275
  },
298
276
  close: function close() {
299
277
  log.info("Disconnected!");
300
-
301
278
  if (options.overlay) {
302
- hide();
279
+ overlay.send({
280
+ type: "DISMISS"
281
+ });
303
282
  }
304
-
305
283
  sendMessage("Close");
306
284
  }
307
285
  };