webpack-dev-server 4.11.1 → 4.12.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.
@@ -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,20 +1,20 @@
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
@@ -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,84 @@ 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
82
  warnings: true
88
83
  }, options.overlay);
89
84
  }
90
-
91
85
  enabledFeatures.Overlay = true;
92
86
  }
93
-
94
87
  if (parsedResourceQuery.logging) {
95
88
  options.logging = parsedResourceQuery.logging;
96
89
  }
97
-
98
90
  if (typeof parsedResourceQuery.reconnect !== "undefined") {
99
91
  options.reconnect = Number(parsedResourceQuery.reconnect);
100
92
  }
93
+
101
94
  /**
102
95
  * @param {string} level
103
96
  */
104
-
105
-
106
97
  function setAllLogLevel(level) {
107
98
  // This is needed because the HMR logger operate separately from dev server logger
108
99
  webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
109
100
  setLogLevel(level);
110
101
  }
111
-
112
102
  if (options.logging) {
113
103
  setAllLogLevel(options.logging);
114
104
  }
115
-
116
105
  logEnabledFeatures(enabledFeatures);
117
106
  self.addEventListener("beforeunload", function () {
118
107
  status.isUnloading = true;
119
108
  });
109
+ var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
110
+ var overlay = createOverlay({
111
+ trustedTypesPolicyName: trustedTypesPolicyName
112
+ });
120
113
  var onSocketMessage = {
121
114
  hot: function hot() {
122
115
  if (parsedResourceQuery.hot === "false") {
123
116
  return;
124
117
  }
125
-
126
118
  options.hot = true;
127
119
  },
128
120
  liveReload: function liveReload() {
129
121
  if (parsedResourceQuery["live-reload"] === "false") {
130
122
  return;
131
123
  }
132
-
133
124
  options.liveReload = true;
134
125
  },
135
126
  invalid: function invalid() {
136
- log.info("App updated. Recompiling..."); // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
127
+ log.info("App updated. Recompiling...");
137
128
 
129
+ // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
138
130
  if (options.overlay) {
139
- hide();
131
+ overlay.send({
132
+ type: "DISMISS"
133
+ });
140
134
  }
141
-
142
135
  sendMessage("Invalid");
143
136
  },
144
-
145
137
  /**
146
138
  * @param {string} hash
147
139
  */
@@ -150,7 +142,6 @@ var onSocketMessage = {
150
142
  status.currentHash = _hash;
151
143
  },
152
144
  logging: setAllLogLevel,
153
-
154
145
  /**
155
146
  * @param {boolean} value
156
147
  */
@@ -158,10 +149,8 @@ var onSocketMessage = {
158
149
  if (typeof document === "undefined") {
159
150
  return;
160
151
  }
161
-
162
152
  options.overlay = value;
163
153
  },
164
-
165
154
  /**
166
155
  * @param {number} value
167
156
  */
@@ -169,17 +158,14 @@ var onSocketMessage = {
169
158
  if (parsedResourceQuery.reconnect === "false") {
170
159
  return;
171
160
  }
172
-
173
161
  options.reconnect = value;
174
162
  },
175
-
176
163
  /**
177
164
  * @param {boolean} value
178
165
  */
179
166
  progress: function progress(value) {
180
167
  options.progress = value;
181
168
  },
182
-
183
169
  /**
184
170
  * @param {{ pluginName?: string, percent: number, msg: string }} data
185
171
  */
@@ -187,29 +173,27 @@ var onSocketMessage = {
187
173
  if (options.progress) {
188
174
  log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "").concat(data.percent, "% - ").concat(data.msg, "."));
189
175
  }
190
-
191
176
  sendMessage("Progress", data);
192
177
  },
193
178
  "still-ok": function stillOk() {
194
179
  log.info("Nothing changed.");
195
-
196
180
  if (options.overlay) {
197
- hide();
181
+ overlay.send({
182
+ type: "DISMISS"
183
+ });
198
184
  }
199
-
200
185
  sendMessage("StillOk");
201
186
  },
202
187
  ok: function ok() {
203
188
  sendMessage("Ok");
204
-
205
189
  if (options.overlay) {
206
- hide();
190
+ overlay.send({
191
+ type: "DISMISS"
192
+ });
207
193
  }
208
-
209
194
  reloadApp(options, status);
210
195
  },
211
196
  // TODO: remove in v5 in favor of 'static-changed'
212
-
213
197
  /**
214
198
  * @param {string} file
215
199
  */
@@ -217,7 +201,6 @@ var onSocketMessage = {
217
201
  log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
218
202
  self.location.reload();
219
203
  },
220
-
221
204
  /**
222
205
  * @param {string} file
223
206
  */
@@ -225,70 +208,59 @@ var onSocketMessage = {
225
208
  log.info("".concat(file ? "\"".concat(file, "\"") : "Content", " from static directory was changed. Reloading..."));
226
209
  self.location.reload();
227
210
  },
228
-
229
211
  /**
230
212
  * @param {Error[]} warnings
231
213
  * @param {any} params
232
214
  */
233
215
  warnings: function warnings(_warnings, params) {
234
216
  log.warn("Warnings while compiling.");
235
-
236
217
  var printableWarnings = _warnings.map(function (error) {
237
218
  var _formatProblem = formatProblem("warning", error),
238
- header = _formatProblem.header,
239
- body = _formatProblem.body;
240
-
219
+ header = _formatProblem.header,
220
+ body = _formatProblem.body;
241
221
  return "".concat(header, "\n").concat(stripAnsi(body));
242
222
  });
243
-
244
223
  sendMessage("Warnings", printableWarnings);
245
-
246
224
  for (var i = 0; i < printableWarnings.length; i++) {
247
225
  log.warn(printableWarnings[i]);
248
226
  }
249
-
250
227
  var needShowOverlayForWarnings = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.warnings;
251
-
252
228
  if (needShowOverlayForWarnings) {
253
- var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
254
- show("warning", _warnings, trustedTypesPolicyName || null);
229
+ overlay.send({
230
+ type: "BUILD_ERROR",
231
+ level: "warning",
232
+ messages: _warnings
233
+ });
255
234
  }
256
-
257
235
  if (params && params.preventReloading) {
258
236
  return;
259
237
  }
260
-
261
238
  reloadApp(options, status);
262
239
  },
263
-
264
240
  /**
265
241
  * @param {Error[]} errors
266
242
  */
267
243
  errors: function errors(_errors) {
268
244
  log.error("Errors while compiling. Reload prevented.");
269
-
270
245
  var printableErrors = _errors.map(function (error) {
271
246
  var _formatProblem2 = formatProblem("error", error),
272
- header = _formatProblem2.header,
273
- body = _formatProblem2.body;
274
-
247
+ header = _formatProblem2.header,
248
+ body = _formatProblem2.body;
275
249
  return "".concat(header, "\n").concat(stripAnsi(body));
276
250
  });
277
-
278
251
  sendMessage("Errors", printableErrors);
279
-
280
252
  for (var i = 0; i < printableErrors.length; i++) {
281
253
  log.error(printableErrors[i]);
282
254
  }
283
-
284
255
  var needShowOverlayForErrors = typeof options.overlay === "boolean" ? options.overlay : options.overlay && options.overlay.errors;
285
-
286
256
  if (needShowOverlayForErrors) {
287
- var trustedTypesPolicyName = typeof options.overlay === "object" && options.overlay.trustedTypesPolicyName;
288
- show("error", _errors, trustedTypesPolicyName || null);
257
+ overlay.send({
258
+ type: "BUILD_ERROR",
259
+ level: "error",
260
+ messages: _errors
261
+ });
289
262
  }
290
263
  },
291
-
292
264
  /**
293
265
  * @param {Error} error
294
266
  */
@@ -297,11 +269,11 @@ var onSocketMessage = {
297
269
  },
298
270
  close: function close() {
299
271
  log.info("Disconnected!");
300
-
301
272
  if (options.overlay) {
302
- hide();
273
+ overlay.send({
274
+ type: "DISMISS"
275
+ });
303
276
  }
304
-
305
277
  sendMessage("Close");
306
278
  }
307
279
  };