webpack-dev-server 3.5.0 → 3.5.1

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/client/index.js CHANGED
@@ -15,31 +15,33 @@ var socket = require('./socket');
15
15
 
16
16
  var overlay = require('./overlay');
17
17
 
18
- function getCurrentScriptSource() {
19
- // `document.currentScript` is the most accurate way to find the current script,
20
- // but is not supported in all browsers.
21
- if (document.currentScript) {
22
- return document.currentScript.getAttribute('src');
23
- } // Fall back to getting all scripts in the document.
18
+ var sendMessage = require('./utils/sendMessage');
24
19
 
20
+ var reloadApp = require('./utils/reloadApp');
25
21
 
26
- var scriptElements = document.scripts || [];
27
- var currentScript = scriptElements[scriptElements.length - 1];
28
-
29
- if (currentScript) {
30
- return currentScript.getAttribute('src');
31
- } // Fail as there was no script to use.
32
-
33
-
34
- throw new Error('[WDS] Failed to get current script source.');
35
- }
22
+ var getCurrentScriptSource = require('./utils/getCurrentScriptSource');
36
23
 
37
24
  var urlParts;
38
- var hotReload = true;
25
+ var status = {
26
+ isUnloading: false,
27
+ currentHash: ''
28
+ };
29
+ var options = {
30
+ hot: false,
31
+ hotReload: true,
32
+ liveReload: false,
33
+ initial: true,
34
+ useWarningOverlay: false,
35
+ useErrorOverlay: false,
36
+ useProgress: false
37
+ };
38
+ self.addEventListener('beforeunload', function () {
39
+ status.isUnloading = true;
40
+ });
39
41
 
40
42
  if (typeof window !== 'undefined') {
41
43
  var qs = window.location.search.toLowerCase();
42
- hotReload = qs.indexOf('hotreload=false') === -1;
44
+ options.hotReload = qs.indexOf('hotreload=false') === -1;
43
45
  }
44
46
 
45
47
  if (typeof __resourceQuery === 'string' && __resourceQuery) {
@@ -57,13 +59,6 @@ if (!urlParts.port || urlParts.port === '0') {
57
59
  urlParts.port = self.location.port;
58
60
  }
59
61
 
60
- var _hot = false;
61
- var _liveReload = false;
62
- var initial = true;
63
- var currentHash = '';
64
- var useWarningOverlay = false;
65
- var useErrorOverlay = false;
66
- var useProgress = false;
67
62
  var INFO = 'info';
68
63
  var WARN = 'warn';
69
64
  var ERROR = 'error';
@@ -76,46 +71,36 @@ var SILENT = 'silent'; // deprecated
76
71
  var WARNING = 'warning';
77
72
  var NONE = 'none'; // Set the default log level
78
73
 
79
- log.setDefaultLevel(INFO); // Send messages to the outside, so plugins can consume it.
80
-
81
- function sendMsg(type, data) {
82
- if (typeof self !== 'undefined' && (typeof WorkerGlobalScope === 'undefined' || !(self instanceof WorkerGlobalScope))) {
83
- self.postMessage({
84
- type: "webpack".concat(type),
85
- data: data
86
- }, '*');
87
- }
88
- }
89
-
74
+ log.setDefaultLevel(INFO);
90
75
  var onSocketMsg = {
91
76
  hot: function hot() {
92
- _hot = true;
77
+ options.hot = true;
93
78
  log.info('[WDS] Hot Module Replacement enabled.');
94
79
  },
95
80
  liveReload: function liveReload() {
96
- _liveReload = true;
81
+ options.liveReload = true;
97
82
  log.info('[WDS] Live Reloading enabled.');
98
83
  },
99
84
  invalid: function invalid() {
100
85
  log.info('[WDS] App updated. Recompiling...'); // fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
101
86
 
102
- if (useWarningOverlay || useErrorOverlay) {
87
+ if (options.useWarningOverlay || options.useErrorOverlay) {
103
88
  overlay.clear();
104
89
  }
105
90
 
106
- sendMsg('Invalid');
91
+ sendMessage('Invalid');
107
92
  },
108
93
  hash: function hash(_hash) {
109
- currentHash = _hash;
94
+ status.currentHash = _hash;
110
95
  },
111
96
  'still-ok': function stillOk() {
112
97
  log.info('[WDS] Nothing changed.');
113
98
 
114
- if (useWarningOverlay || useErrorOverlay) {
99
+ if (options.useWarningOverlay || options.useErrorOverlay) {
115
100
  overlay.clear();
116
101
  }
117
102
 
118
- sendMsg('StillOk');
103
+ sendMessage('StillOk');
119
104
  },
120
105
  'log-level': function logLevel(level) {
121
106
  var hotCtx = require.context('webpack/hot', false, /^\.\/log$/);
@@ -152,39 +137,39 @@ var onSocketMsg = {
152
137
  overlay: function overlay(value) {
153
138
  if (typeof document !== 'undefined') {
154
139
  if (typeof value === 'boolean') {
155
- useWarningOverlay = false;
156
- useErrorOverlay = value;
140
+ options.useWarningOverlay = false;
141
+ options.useErrorOverlay = value;
157
142
  } else if (value) {
158
- useWarningOverlay = value.warnings;
159
- useErrorOverlay = value.errors;
143
+ options.useWarningOverlay = value.warnings;
144
+ options.useErrorOverlay = value.errors;
160
145
  }
161
146
  }
162
147
  },
163
148
  progress: function progress(_progress) {
164
149
  if (typeof document !== 'undefined') {
165
- useProgress = _progress;
150
+ options.useProgress = _progress;
166
151
  }
167
152
  },
168
153
  'progress-update': function progressUpdate(data) {
169
- if (useProgress) {
154
+ if (options.useProgress) {
170
155
  log.info("[WDS] ".concat(data.percent, "% - ").concat(data.msg, "."));
171
156
  }
172
157
 
173
- sendMsg('Progress', data);
158
+ sendMessage('Progress', data);
174
159
  },
175
160
  ok: function ok() {
176
- sendMsg('Ok');
161
+ sendMessage('Ok');
177
162
 
178
- if (useWarningOverlay || useErrorOverlay) {
163
+ if (options.useWarningOverlay || options.useErrorOverlay) {
179
164
  overlay.clear();
180
165
  }
181
166
 
182
- if (initial) {
183
- return initial = false;
167
+ if (options.initial) {
168
+ return options.initial = false;
184
169
  } // eslint-disable-line no-return-assign
185
170
 
186
171
 
187
- reloadApp();
172
+ reloadApp(options, status);
188
173
  },
189
174
  'content-changed': function contentChanged() {
190
175
  log.info('[WDS] Content base changed. Reloading...');
@@ -197,22 +182,22 @@ var onSocketMsg = {
197
182
  return stripAnsi(warning);
198
183
  });
199
184
 
200
- sendMsg('Warnings', strippedWarnings);
185
+ sendMessage('Warnings', strippedWarnings);
201
186
 
202
187
  for (var i = 0; i < strippedWarnings.length; i++) {
203
188
  log.warn(strippedWarnings[i]);
204
189
  }
205
190
 
206
- if (useWarningOverlay) {
191
+ if (options.useWarningOverlay) {
207
192
  overlay.showMessage(_warnings);
208
193
  }
209
194
 
210
- if (initial) {
211
- return initial = false;
195
+ if (options.initial) {
196
+ return options.initial = false;
212
197
  } // eslint-disable-line no-return-assign
213
198
 
214
199
 
215
- reloadApp();
200
+ reloadApp(options, status);
216
201
  },
217
202
  errors: function errors(_errors) {
218
203
  log.error('[WDS] Errors while compiling. Reload prevented.');
@@ -221,28 +206,29 @@ var onSocketMsg = {
221
206
  return stripAnsi(error);
222
207
  });
223
208
 
224
- sendMsg('Errors', strippedErrors);
209
+ sendMessage('Errors', strippedErrors);
225
210
 
226
211
  for (var i = 0; i < strippedErrors.length; i++) {
227
212
  log.error(strippedErrors[i]);
228
213
  }
229
214
 
230
- if (useErrorOverlay) {
215
+ if (options.useErrorOverlay) {
231
216
  overlay.showMessage(_errors);
232
217
  }
233
218
 
234
- initial = false;
219
+ options.initial = false;
235
220
  },
236
221
  error: function error(_error) {
237
222
  log.error(_error);
238
223
  },
239
224
  close: function close() {
240
225
  log.error('[WDS] Disconnected!');
241
- sendMsg('Close');
226
+ sendMessage('Close');
242
227
  }
243
228
  };
244
- var hostname = urlParts.hostname;
245
- var protocol = urlParts.protocol; // check ipv4 and ipv6 `all hostname`
229
+ var _urlParts = urlParts,
230
+ hostname = _urlParts.hostname,
231
+ protocol = _urlParts.protocol; // check ipv4 and ipv6 `all hostname`
246
232
 
247
233
  if (hostname === '0.0.0.0' || hostname === '::') {
248
234
  // why do we need this check?
@@ -288,50 +274,4 @@ var socketUrl = url.format({
288
274
  // client to open the socket to the correct location.
289
275
  pathname: sockPath
290
276
  });
291
- socket(socketUrl, onSocketMsg);
292
- var isUnloading = false;
293
- self.addEventListener('beforeunload', function () {
294
- isUnloading = true;
295
- });
296
-
297
- function reloadApp() {
298
- if (isUnloading || !hotReload) {
299
- return;
300
- }
301
-
302
- if (_hot) {
303
- log.info('[WDS] App hot update...'); // eslint-disable-next-line global-require
304
-
305
- var hotEmitter = require('webpack/hot/emitter');
306
-
307
- hotEmitter.emit('webpackHotUpdate', currentHash);
308
-
309
- if (typeof self !== 'undefined' && self.window) {
310
- // broadcast update to window
311
- self.postMessage("webpackHotUpdate".concat(currentHash), '*');
312
- }
313
- } // allow refreshing the page only if liveReload isn't disabled
314
- else if (_liveReload) {
315
- var rootWindow = self; // use parent window for reload (in case we're in an iframe with no valid src)
316
-
317
- var intervalId = self.setInterval(function () {
318
- if (rootWindow.location.protocol !== 'about:') {
319
- // reload immediately if protocol is valid
320
- applyReload(rootWindow, intervalId);
321
- } else {
322
- rootWindow = rootWindow.parent;
323
-
324
- if (rootWindow.parent === rootWindow) {
325
- // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
326
- applyReload(rootWindow, intervalId);
327
- }
328
- }
329
- });
330
- }
331
-
332
- function applyReload(rootWindow, intervalId) {
333
- clearInterval(intervalId);
334
- log.info('[WDS] App updated. Reloading...');
335
- rootWindow.location.reload();
336
- }
337
- }
277
+ socket(socketUrl, onSocketMsg);
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ function getCurrentScriptSource() {
4
+ // `document.currentScript` is the most accurate way to find the current script,
5
+ // but is not supported in all browsers.
6
+ if (document.currentScript) {
7
+ return document.currentScript.getAttribute('src');
8
+ } // Fall back to getting all scripts in the document.
9
+
10
+
11
+ var scriptElements = document.scripts || [];
12
+ var currentScript = scriptElements[scriptElements.length - 1];
13
+
14
+ if (currentScript) {
15
+ return currentScript.getAttribute('src');
16
+ } // Fail as there was no script to use.
17
+
18
+
19
+ throw new Error('[WDS] Failed to get current script source.');
20
+ }
21
+
22
+ module.exports = getCurrentScriptSource;
@@ -0,0 +1,54 @@
1
+ 'use strict';
2
+ /* global WorkerGlobalScope self */
3
+
4
+ var log = require('loglevel').getLogger('webpack-dev-server');
5
+
6
+ function reloadApp(_ref, _ref2) {
7
+ var hotReload = _ref.hotReload,
8
+ hot = _ref.hot,
9
+ liveReload = _ref.liveReload;
10
+ var isUnloading = _ref2.isUnloading,
11
+ currentHash = _ref2.currentHash;
12
+
13
+ if (isUnloading || !hotReload) {
14
+ return;
15
+ }
16
+
17
+ if (hot) {
18
+ log.info('[WDS] App hot update...'); // eslint-disable-next-line global-require
19
+
20
+ var hotEmitter = require('webpack/hot/emitter');
21
+
22
+ hotEmitter.emit('webpackHotUpdate', currentHash);
23
+
24
+ if (typeof self !== 'undefined' && self.window) {
25
+ // broadcast update to window
26
+ self.postMessage("webpackHotUpdate".concat(currentHash), '*');
27
+ }
28
+ } // allow refreshing the page only if liveReload isn't disabled
29
+ else if (liveReload) {
30
+ var rootWindow = self; // use parent window for reload (in case we're in an iframe with no valid src)
31
+
32
+ var intervalId = self.setInterval(function () {
33
+ if (rootWindow.location.protocol !== 'about:') {
34
+ // reload immediately if protocol is valid
35
+ applyReload(rootWindow, intervalId);
36
+ } else {
37
+ rootWindow = rootWindow.parent;
38
+
39
+ if (rootWindow.parent === rootWindow) {
40
+ // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
41
+ applyReload(rootWindow, intervalId);
42
+ }
43
+ }
44
+ });
45
+ }
46
+
47
+ function applyReload(rootWindow, intervalId) {
48
+ clearInterval(intervalId);
49
+ log.info('[WDS] App updated. Reloading...');
50
+ rootWindow.location.reload();
51
+ }
52
+ }
53
+
54
+ module.exports = reloadApp;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+ /* global __resourceQuery WorkerGlobalScope self */
3
+ // Send messages to the outside, so plugins can consume it.
4
+
5
+ function sendMsg(type, data) {
6
+ if (typeof self !== 'undefined' && (typeof WorkerGlobalScope === 'undefined' || !(self instanceof WorkerGlobalScope))) {
7
+ self.postMessage({
8
+ type: "webpack".concat(type),
9
+ data: data
10
+ }, '*');
11
+ }
12
+ }
13
+
14
+ module.exports = sendMsg;
package/lib/Server.js CHANGED
@@ -711,6 +711,21 @@ class Server {
711
711
  });
712
712
  }
713
713
 
714
+ showStatus() {
715
+ const suffix =
716
+ this.options.inline !== false || this.options.lazy === true
717
+ ? '/'
718
+ : '/webpack-dev-server/';
719
+ const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;
720
+
721
+ status(
722
+ uri,
723
+ this.options,
724
+ this.log,
725
+ this.options.stats && this.options.stats.colors
726
+ );
727
+ }
728
+
714
729
  listen(port, hostname, fn) {
715
730
  this.hostname = hostname;
716
731
 
@@ -878,21 +893,6 @@ class Server {
878
893
  return false;
879
894
  }
880
895
 
881
- showStatus() {
882
- const suffix =
883
- this.options.inline !== false || this.options.lazy === true
884
- ? '/'
885
- : '/webpack-dev-server/';
886
- const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;
887
-
888
- status(
889
- uri,
890
- this.options,
891
- this.log,
892
- this.options.stats && this.options.stats.colors
893
- );
894
- }
895
-
896
896
  // eslint-disable-next-line
897
897
  sockWrite(sockets, type, data) {
898
898
  sockets.forEach((socket) => {
@@ -6,12 +6,14 @@ const defaultPort = require('./defaultPort');
6
6
  function processOptions(config, argv, callback) {
7
7
  // processOptions {Promise}
8
8
  if (typeof config.then === 'function') {
9
- config.then(processOptions).catch((err) => {
10
- // eslint-disable-next-line no-console
11
- console.error(err.stack || err);
12
- // eslint-disable-next-line no-process-exit
13
- process.exit();
14
- });
9
+ config
10
+ .then((conf) => processOptions(conf, argv, callback))
11
+ .catch((err) => {
12
+ // eslint-disable-next-line no-console
13
+ console.error(err.stack || err);
14
+ // eslint-disable-next-line no-process-exit
15
+ process.exit(1);
16
+ });
15
17
 
16
18
  return;
17
19
  }
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const open = require('opn');
4
+
5
+ function runOpen(uri, options, log) {
6
+ let openOptions = {};
7
+ let openMessage = 'Unable to open browser';
8
+
9
+ if (typeof options.open === 'string') {
10
+ openOptions = { app: options.open };
11
+ openMessage += `: ${options.open}`;
12
+ }
13
+
14
+ open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
15
+ log.warn(
16
+ `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
17
+ );
18
+ });
19
+ }
20
+
21
+ module.exports = runOpen;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- const open = require('opn');
4
3
  const colors = require('./colors');
4
+ const runOpen = require('./runOpen');
5
5
 
6
6
  // TODO: don't emit logs when webpack-dev-server is used via Node.js API
7
7
  function status(uri, options, log, useColor) {
@@ -44,19 +44,7 @@ function status(uri, options, log, useColor) {
44
44
  }
45
45
 
46
46
  if (options.open) {
47
- let openOptions = {};
48
- let openMessage = 'Unable to open browser';
49
-
50
- if (typeof options.open === 'string') {
51
- openOptions = { app: options.open };
52
- openMessage += `: ${options.open}`;
53
- }
54
-
55
- open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
56
- log.warn(
57
- `${openMessage}. If you are running in a headless environment, please do not use the --open flag`
58
- );
59
- });
47
+ runOpen(uri, options, log);
60
48
  }
61
49
  }
62
50
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack-dev-server",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
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",
@@ -91,7 +91,7 @@
91
91
  "less-loader": "^5.0.0",
92
92
  "lint-staged": "^8.1.7",
93
93
  "marked": "^0.6.2",
94
- "memfs": "^2.15.2",
94
+ "memfs": "^2.15.4",
95
95
  "npm-run-all": "^4.1.5",
96
96
  "nyc": "^14.1.1",
97
97
  "prettier": "^1.17.1",