@rspack/dev-server 2.0.0-beta.1 → 2.0.0-beta.2

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.
Files changed (42) hide show
  1. package/README.md +4 -3
  2. package/client/clients/WebSocketClient.d.ts +17 -0
  3. package/client/clients/WebSocketClient.js +28 -28
  4. package/client/index.d.ts +17 -0
  5. package/client/index.js +224 -363
  6. package/client/modules/logger/Logger.d.ts +40 -0
  7. package/client/modules/logger/Logger.js +123 -0
  8. package/client/modules/logger/createConsoleLogger.d.ts +12 -0
  9. package/client/modules/logger/createConsoleLogger.js +119 -0
  10. package/client/modules/logger/index.d.ts +18 -0
  11. package/client/modules/logger/index.js +20 -712
  12. package/client/modules/types.d.ts +45 -0
  13. package/client/modules/types.js +17 -0
  14. package/client/overlay.d.ts +44 -0
  15. package/client/overlay.js +241 -290
  16. package/client/progress.d.ts +11 -0
  17. package/client/progress.js +178 -111
  18. package/client/socket.d.ts +15 -0
  19. package/client/socket.js +19 -46
  20. package/client/utils/ansiHTML.d.ts +30 -0
  21. package/client/utils/ansiHTML.js +106 -153
  22. package/client/utils/log.d.ts +13 -0
  23. package/client/utils/log.js +7 -17
  24. package/client/utils/sendMessage.d.ts +11 -0
  25. package/client/utils/sendMessage.js +6 -15
  26. package/dist/0~launch-editor.js +618 -0
  27. package/dist/0~open.js +547 -0
  28. package/dist/0~p-retry.js +158 -0
  29. package/dist/131.js +1398 -0
  30. package/dist/getPort.d.ts +4 -1
  31. package/dist/index.js +1 -5
  32. package/dist/rslib-runtime.js +66 -0
  33. package/dist/server.d.ts +7 -7
  34. package/dist/servers/WebsocketServer.d.ts +8 -1
  35. package/dist/types.d.ts +7 -5
  36. package/package.json +55 -58
  37. package/dist/config.js +0 -2
  38. package/dist/getPort.js +0 -141
  39. package/dist/server.js +0 -1971
  40. package/dist/servers/BaseServer.js +0 -20
  41. package/dist/servers/WebsocketServer.js +0 -72
  42. package/dist/types.js +0 -5
package/client/index.js CHANGED
@@ -1,66 +1,60 @@
1
- /**
2
- * The following code is modified based on
3
- * https://github.com/webpack/webpack-dev-server
4
- *
5
- * MIT Licensed
6
- * Author Tobias Koppers @sokra
7
- * Copyright (c) JS Foundation and other contributors
8
- * https://github.com/webpack/webpack-dev-server/blob/main/LICENSE
9
- */
10
- var __assign = (this && this.__assign) || function () {
11
- __assign = Object.assign || function(t) {
12
- for (var s, i = 1, n = arguments.length; i < n; i++) {
13
- s = arguments[i];
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
15
- t[p] = s[p];
16
- }
17
- return t;
18
- };
19
- return __assign.apply(this, arguments);
20
- };
21
- // @ts-expect-error: No type definitions available for '@rspack/core/hot/emitter.js'
22
- import { emitter as hotEmitter } from '@rspack/core/hot/emitter.js';
23
- /* Rspack dev server runtime client */
24
- // @ts-expect-error: No type definitions available for '@rspack/core/hot/log.js'
25
- import { log as webpackHotLog } from '@rspack/core/hot/log.js';
26
- import { createOverlay, formatProblem } from './overlay.js';
27
- import socket from './socket.js';
28
- import { defineProgressElement, isProgressSupported } from './progress.js';
29
- import { log, setLogLevel } from './utils/log.js';
30
- import sendMessage from './utils/sendMessage.js';
31
- var decodeOverlayOptions = function (overlayOptions) {
32
- if (typeof overlayOptions === 'object') {
33
- ['warnings', 'errors', 'runtimeErrors'].forEach(function (property) {
34
- if (typeof overlayOptions[property] === 'string') {
35
- var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
36
- overlayOptions[property] = new Function('message', "var callback = ".concat(overlayFilterFunctionString, "\n\t\t\t\treturn callback(message)"));
37
- }
1
+ import { emitter } from "@rspack/core/hot/emitter.js";
2
+ import { log } from "@rspack/core/hot/log.js";
3
+ import { createOverlay, formatProblem } from "./overlay.js";
4
+ import socket from "./socket.js";
5
+ import { defineProgressElement, isProgressSupported } from "./progress.js";
6
+ import { log as log_js_log, setLogLevel } from "./utils/log.js";
7
+ import sendMessage from "./utils/sendMessage.js";
8
+ function _define_property(obj, key, value) {
9
+ if (key in obj) Object.defineProperty(obj, key, {
10
+ value: value,
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true
14
+ });
15
+ else obj[key] = value;
16
+ return obj;
17
+ }
18
+ function _object_spread(target) {
19
+ for(var i = 1; i < arguments.length; i++){
20
+ var source = null != arguments[i] ? arguments[i] : {};
21
+ var ownKeys = Object.keys(source);
22
+ if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
23
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
24
+ }));
25
+ ownKeys.forEach(function(key) {
26
+ _define_property(target, key, source[key]);
38
27
  });
39
28
  }
29
+ return target;
30
+ }
31
+ const decodeOverlayOptions = (overlayOptions)=>{
32
+ if ('object' == typeof overlayOptions) [
33
+ 'warnings',
34
+ 'errors',
35
+ 'runtimeErrors'
36
+ ].forEach((property)=>{
37
+ if ('string' == typeof overlayOptions[property]) {
38
+ const overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
39
+ overlayOptions[property] = new Function('message', `var callback = ${overlayFilterFunctionString}
40
+ return callback(message)`);
41
+ }
42
+ });
40
43
  };
41
- var parseURL = function (resourceQuery) {
42
- var result = {};
43
- if (typeof resourceQuery === 'string' && resourceQuery !== '') {
44
- var searchParams = resourceQuery.slice(1).split('&');
45
- for (var i = 0; i < searchParams.length; i++) {
46
- var pair = searchParams[i].split('=');
44
+ const parseURL = (resourceQuery)=>{
45
+ let result = {};
46
+ if ('string' == typeof resourceQuery && '' !== resourceQuery) {
47
+ const searchParams = resourceQuery.slice(1).split('&');
48
+ for(let i = 0; i < searchParams.length; i++){
49
+ const pair = searchParams[i].split('=');
47
50
  result[pair[0]] = decodeURIComponent(pair[1]);
48
51
  }
49
- }
50
- else {
51
- // Else, get the url from the <script> this file was called with.
52
- var scriptSource = getCurrentScriptSource();
53
- var scriptSourceURL = void 0;
52
+ } else {
53
+ const scriptSource = getCurrentScriptSource();
54
+ let scriptSourceURL;
54
55
  try {
55
- // The placeholder `baseURL` with `window.location.href`,
56
- // is to allow parsing of path-relative or protocol-relative URLs,
57
- // and will have no effect if `scriptSource` is a fully valid URL.
58
56
  scriptSourceURL = new URL(scriptSource, self.location.href);
59
- }
60
- catch (error) {
61
- // URL parsing failed, do nothing.
62
- // We will still proceed to see if we can recover using `resourceQuery`
63
- }
57
+ } catch (error) {}
64
58
  if (scriptSourceURL) {
65
59
  result = scriptSourceURL;
66
60
  result['fromCurrentScript'] = 'true';
@@ -68,223 +62,164 @@ var parseURL = function (resourceQuery) {
68
62
  }
69
63
  return result;
70
64
  };
71
- var status = {
65
+ const client_src_status = {
72
66
  isUnloading: false,
73
- currentHash: __webpack_hash__,
67
+ currentHash: __webpack_hash__
74
68
  };
75
- var getCurrentScriptSource = function () {
76
- // `document.currentScript` is the most accurate way to find the current script,
77
- // but is not supported in all browsers.
78
- if (document.currentScript) {
79
- return document.currentScript.getAttribute('src');
80
- }
81
- // Fallback to getting all scripts running in the document.
82
- var scriptElements = document.scripts || [];
83
- var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) { return element.getAttribute('src'); });
69
+ const getCurrentScriptSource = ()=>{
70
+ if (document.currentScript) return document.currentScript.getAttribute('src');
71
+ const scriptElements = document.scripts || [];
72
+ const scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, (element)=>element.getAttribute('src'));
84
73
  if (scriptElementsWithSrc.length > 0) {
85
- var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
74
+ const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
86
75
  return currentScript.getAttribute('src');
87
76
  }
88
- // Fail as there was no script to use.
89
- throw new Error('[rspack-dev-server] Failed to get current script source.');
77
+ throw new Error("[rspack-dev-server] Failed to get current script source.");
90
78
  };
91
- var parsedResourceQuery = parseURL(__resourceQuery);
92
- var enabledFeatures = {
79
+ const parsedResourceQuery = parseURL(__resourceQuery);
80
+ const enabledFeatures = {
93
81
  'Hot Module Replacement': false,
94
82
  'Live Reloading': false,
95
83
  Progress: false,
96
- Overlay: false,
84
+ Overlay: false
97
85
  };
98
- var options = {
86
+ const options = {
99
87
  hot: false,
100
88
  liveReload: false,
101
89
  progress: false,
102
- overlay: false,
90
+ overlay: false
103
91
  };
104
- if (parsedResourceQuery.hot === 'true') {
92
+ if ('true' === parsedResourceQuery.hot) {
105
93
  options.hot = true;
106
94
  enabledFeatures['Hot Module Replacement'] = true;
107
95
  }
108
- if (parsedResourceQuery['live-reload'] === 'true') {
96
+ if ('true' === parsedResourceQuery['live-reload']) {
109
97
  options.liveReload = true;
110
98
  enabledFeatures['Live Reloading'] = true;
111
99
  }
112
- if (parsedResourceQuery.progress === 'true') {
100
+ if ('true' === parsedResourceQuery.progress) {
113
101
  options.progress = true;
114
102
  enabledFeatures.Progress = true;
115
103
  }
116
104
  if (parsedResourceQuery.overlay) {
117
105
  try {
118
106
  options.overlay = JSON.parse(parsedResourceQuery.overlay);
107
+ } catch (e) {
108
+ log_js_log.error('Error parsing overlay options from resource query:', e);
119
109
  }
120
- catch (e) {
121
- log.error('Error parsing overlay options from resource query:', e);
122
- }
123
- // Fill in default "true" params for partially-specified objects.
124
- if (typeof options.overlay === 'object') {
125
- options.overlay = __assign({ errors: true, warnings: true, runtimeErrors: true }, options.overlay);
110
+ if ('object' == typeof options.overlay) {
111
+ options.overlay = _object_spread({
112
+ errors: true,
113
+ warnings: true,
114
+ runtimeErrors: true
115
+ }, options.overlay);
126
116
  decodeOverlayOptions(options.overlay);
127
117
  }
128
- enabledFeatures.Overlay = options.overlay !== false;
129
- }
130
- if (parsedResourceQuery.logging) {
131
- options.logging = parsedResourceQuery.logging;
132
- }
133
- if (typeof parsedResourceQuery.reconnect !== 'undefined') {
134
- options.reconnect = Number(parsedResourceQuery.reconnect);
118
+ enabledFeatures.Overlay = false !== options.overlay;
135
119
  }
136
- var setAllLogLevel = function (level) {
137
- // This is needed because the HMR logger operate separately from dev server logger
138
- webpackHotLog.setLogLevel(level === 'verbose' || level === 'log' ? 'info' : level);
120
+ if (parsedResourceQuery.logging) options.logging = parsedResourceQuery.logging;
121
+ if (void 0 !== parsedResourceQuery.reconnect) options.reconnect = Number(parsedResourceQuery.reconnect);
122
+ const setAllLogLevel = (level)=>{
123
+ log.setLogLevel('verbose' === level || 'log' === level ? 'info' : level);
139
124
  setLogLevel(level);
140
125
  };
141
- if (options.logging) {
142
- setAllLogLevel(options.logging);
143
- }
144
- var logEnabledFeatures = function (features) {
145
- var listEnabledFeatures = Object.keys(features);
146
- if (!features || listEnabledFeatures.length === 0) {
147
- return;
148
- }
149
- var logString = 'Server started:';
150
- // Server started: Hot Module Replacement enabled, Live Reloading enabled, Overlay disabled.
151
- for (var i = 0; i < listEnabledFeatures.length; i++) {
152
- var key = listEnabledFeatures[i];
153
- logString += " ".concat(key, " ").concat(features[key] ? 'enabled' : 'disabled', ",");
126
+ if (options.logging) setAllLogLevel(options.logging);
127
+ const logEnabledFeatures = (features)=>{
128
+ const listEnabledFeatures = Object.keys(features);
129
+ if (!features || 0 === listEnabledFeatures.length) return;
130
+ let logString = 'Server started:';
131
+ for(let i = 0; i < listEnabledFeatures.length; i++){
132
+ const key = listEnabledFeatures[i];
133
+ logString += ` ${key} ${features[key] ? 'enabled' : 'disabled'},`;
154
134
  }
155
- // replace last comma with a period
156
135
  logString = logString.slice(0, -1).concat('.');
157
- log.info(logString);
136
+ log_js_log.info(logString);
158
137
  };
159
138
  logEnabledFeatures(enabledFeatures);
160
- self.addEventListener('beforeunload', function () {
161
- status.isUnloading = true;
139
+ self.addEventListener('beforeunload', ()=>{
140
+ client_src_status.isUnloading = true;
162
141
  });
163
- var overlay = typeof window !== 'undefined'
164
- ? createOverlay(typeof options.overlay === 'object'
165
- ? {
166
- trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
167
- catchRuntimeError: options.overlay.runtimeErrors,
168
- }
169
- : {
170
- trustedTypesPolicyName: false,
171
- catchRuntimeError: options.overlay,
172
- })
173
- : { send: function () { } };
174
- var reloadApp = function (_a, currentStatus) {
175
- var hot = _a.hot, liveReload = _a.liveReload;
176
- if (currentStatus.isUnloading) {
177
- return;
178
- }
179
- var currentHash = currentStatus.currentHash, previousHash = currentStatus.previousHash;
180
- var isInitial = currentHash.indexOf(previousHash) >= 0;
181
- if (isInitial) {
182
- return;
183
- }
142
+ const overlay = "u" > typeof window ? createOverlay('object' == typeof options.overlay ? {
143
+ trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
144
+ catchRuntimeError: options.overlay.runtimeErrors
145
+ } : {
146
+ trustedTypesPolicyName: false,
147
+ catchRuntimeError: options.overlay
148
+ }) : {
149
+ send: ()=>{}
150
+ };
151
+ const reloadApp = ({ hot, liveReload }, currentStatus)=>{
152
+ if (currentStatus.isUnloading) return;
153
+ const { currentHash, previousHash } = currentStatus;
154
+ const isInitial = currentHash.indexOf(previousHash) >= 0;
155
+ if (isInitial) return;
184
156
  function applyReload(rootWindow, intervalId) {
185
157
  clearInterval(intervalId);
186
- log.info('App updated. Reloading...');
158
+ log_js_log.info('App updated. Reloading...');
187
159
  rootWindow.location.reload();
188
160
  }
189
- var search = self.location.search.toLowerCase();
190
- var allowToHot = search.indexOf('rspack-dev-server-hot=false') === -1;
191
- var allowToLiveReload = search.indexOf('rspack-dev-server-live-reload=false') === -1;
161
+ const search = self.location.search.toLowerCase();
162
+ const allowToHot = -1 === search.indexOf('rspack-dev-server-hot=false');
163
+ const allowToLiveReload = -1 === search.indexOf('rspack-dev-server-live-reload=false');
192
164
  if (hot && allowToHot) {
193
- log.info('App hot update...');
194
- hotEmitter.emit('webpackHotUpdate', currentStatus.currentHash);
195
- if (typeof self !== 'undefined' && self.window) {
196
- // broadcast update to window
197
- self.postMessage("webpackHotUpdate".concat(currentStatus.currentHash), '*');
198
- }
199
- }
200
- // allow refreshing the page only if liveReload isn't disabled
201
- else if (liveReload && allowToLiveReload) {
202
- var rootWindow_1 = self;
203
- // use parent window for reload (in case we're in an iframe with no valid src)
204
- var intervalId_1 = self.setInterval(function () {
205
- if (rootWindow_1.location.protocol !== 'about:') {
206
- // reload immediately if protocol is valid
207
- applyReload(rootWindow_1, intervalId_1);
208
- }
165
+ log_js_log.info('App hot update...');
166
+ emitter.emit('webpackHotUpdate', currentStatus.currentHash);
167
+ if ("u" > typeof self && self.window) self.postMessage(`webpackHotUpdate${currentStatus.currentHash}`, '*');
168
+ } else if (liveReload && allowToLiveReload) {
169
+ let rootWindow = self;
170
+ const intervalId = self.setInterval(()=>{
171
+ if ('about:' !== rootWindow.location.protocol) applyReload(rootWindow, intervalId);
209
172
  else {
210
- rootWindow_1 = rootWindow_1.parent;
211
- if (rootWindow_1.parent === rootWindow_1) {
212
- // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
213
- applyReload(rootWindow_1, intervalId_1);
214
- }
173
+ rootWindow = rootWindow.parent;
174
+ if (rootWindow.parent === rootWindow) applyReload(rootWindow, intervalId);
215
175
  }
216
176
  });
217
177
  }
218
178
  };
219
- var ansiRegex = new RegExp([
220
- '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
221
- '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
222
- ].join('|'), 'g');
223
- /**
224
- *
225
- * Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
226
- * Adapted from code originally released by Sindre Sorhus
227
- * Licensed the MIT License
228
- *
229
- */
230
- var stripAnsi = function (string) {
231
- if (typeof string !== 'string') {
232
- throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
233
- }
179
+ const ansiRegex = new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))", 'g');
180
+ const stripAnsi = (string)=>{
181
+ if ('string' != typeof string) throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
234
182
  return string.replace(ansiRegex, '');
235
183
  };
236
- var onSocketMessage = {
237
- hot: function () {
238
- if (parsedResourceQuery.hot === 'false') {
239
- return;
240
- }
184
+ const onSocketMessage = {
185
+ hot () {
186
+ if ('false' === parsedResourceQuery.hot) return;
241
187
  options.hot = true;
242
188
  },
243
- liveReload: function () {
244
- if (parsedResourceQuery['live-reload'] === 'false') {
245
- return;
246
- }
189
+ liveReload () {
190
+ if ('false' === parsedResourceQuery['live-reload']) return;
247
191
  options.liveReload = true;
248
192
  },
249
- invalid: function () {
250
- log.info('App updated. Recompiling...');
251
- // Fixes #1042. overlay doesn't clear if errors are fixed but warnings remain.
252
- if (options.overlay) {
253
- overlay.send({ type: 'DISMISS' });
254
- }
193
+ invalid () {
194
+ log_js_log.info('App updated. Recompiling...');
195
+ if (options.overlay) overlay.send({
196
+ type: 'DISMISS'
197
+ });
255
198
  sendMessage('Invalid');
256
199
  },
257
- hash: function hash(_hash) {
258
- if (!_hash) {
259
- return;
260
- }
261
- status.previousHash = status.currentHash;
262
- status.currentHash = _hash;
200
+ hash: function(_hash) {
201
+ if (!_hash) return;
202
+ client_src_status.previousHash = client_src_status.currentHash;
203
+ client_src_status.currentHash = _hash;
263
204
  },
264
205
  logging: setAllLogLevel,
265
- overlay: function (value) {
266
- if (typeof document === 'undefined') {
267
- return;
268
- }
206
+ overlay (value) {
207
+ if ("u" < typeof document) return;
269
208
  options.overlay = value;
270
209
  decodeOverlayOptions(options.overlay);
271
210
  },
272
- reconnect: function (value) {
273
- if (parsedResourceQuery.reconnect === 'false') {
274
- return;
275
- }
211
+ reconnect (value) {
212
+ if ('false' === parsedResourceQuery.reconnect) return;
276
213
  options.reconnect = value;
277
214
  },
278
- progress: function (value) {
215
+ progress (value) {
279
216
  options.progress = value;
280
217
  },
281
- 'progress-update': function progressUpdate(data) {
282
- if (options.progress) {
283
- log.info("".concat(data.percent, "% - ").concat(data.msg, "."));
284
- }
218
+ 'progress-update': function(data) {
219
+ if (options.progress) log_js_log.info(`${data.percent}% - ${data.msg}.`);
285
220
  if (isProgressSupported()) {
286
- if (typeof options.progress === 'string') {
287
- var progress = document.querySelector('wds-progress');
221
+ if ('string' == typeof options.progress) {
222
+ let progress = document.querySelector('wds-progress');
288
223
  if (!progress) {
289
224
  defineProgressElement();
290
225
  progress = document.createElement('wds-progress');
@@ -296,200 +231,126 @@ var onSocketMessage = {
296
231
  }
297
232
  sendMessage('Progress', data);
298
233
  },
299
- 'still-ok': function stillOk() {
300
- log.info('Nothing changed.');
301
- if (options.overlay) {
302
- overlay.send({ type: 'DISMISS' });
303
- }
234
+ 'still-ok': function() {
235
+ log_js_log.info('Nothing changed.');
236
+ if (options.overlay) overlay.send({
237
+ type: 'DISMISS'
238
+ });
304
239
  sendMessage('StillOk');
305
240
  },
306
- ok: function () {
241
+ ok () {
307
242
  sendMessage('Ok');
308
- if (options.overlay) {
309
- overlay.send({ type: 'DISMISS' });
310
- }
311
- reloadApp(options, status);
243
+ if (options.overlay) overlay.send({
244
+ type: 'DISMISS'
245
+ });
246
+ reloadApp(options, client_src_status);
312
247
  },
313
- 'static-changed': function staticChanged(file) {
314
- log.info("".concat(file ? "\"".concat(file, "\"") : 'Content', " from static directory was changed. Reloading..."));
248
+ 'static-changed': function(file) {
249
+ log_js_log.info(`${file ? `"${file}"` : 'Content'} from static directory was changed. Reloading...`);
315
250
  self.location.reload();
316
251
  },
317
- warnings: function (warnings, params) {
318
- log.warn('Warnings while compiling.');
319
- var printableWarnings = warnings.map(function (error) {
320
- var _a = formatProblem('warning', error), header = _a.header, body = _a.body;
321
- return "".concat(header, "\n").concat(stripAnsi(body));
252
+ warnings (warnings, params) {
253
+ log_js_log.warn('Warnings while compiling.');
254
+ const printableWarnings = warnings.map((error)=>{
255
+ const { header, body } = formatProblem('warning', error);
256
+ return `${header}\n${stripAnsi(body)}`;
322
257
  });
323
258
  sendMessage('Warnings', printableWarnings);
324
- for (var i = 0; i < printableWarnings.length; i++) {
325
- log.warn(printableWarnings[i]);
326
- }
327
- var overlayWarningsSetting = typeof options.overlay === 'boolean'
328
- ? options.overlay
329
- : options.overlay && options.overlay.warnings;
259
+ for(let i = 0; i < printableWarnings.length; i++)log_js_log.warn(printableWarnings[i]);
260
+ const overlayWarningsSetting = 'boolean' == typeof options.overlay ? options.overlay : options.overlay && options.overlay.warnings;
330
261
  if (overlayWarningsSetting) {
331
- var warningsToDisplay = typeof overlayWarningsSetting === 'function'
332
- ? warnings.filter(overlayWarningsSetting)
333
- : warnings;
334
- if (warningsToDisplay.length) {
335
- overlay.send({
336
- type: 'BUILD_ERROR',
337
- level: 'warning',
338
- messages: warnings,
339
- });
340
- }
262
+ const warningsToDisplay = 'function' == typeof overlayWarningsSetting ? warnings.filter(overlayWarningsSetting) : warnings;
263
+ if (warningsToDisplay.length) overlay.send({
264
+ type: 'BUILD_ERROR',
265
+ level: 'warning',
266
+ messages: warnings
267
+ });
341
268
  }
342
- if (params && params.preventReloading) {
343
- return;
344
- }
345
- reloadApp(options, status);
269
+ if (params && params.preventReloading) return;
270
+ reloadApp(options, client_src_status);
346
271
  },
347
- errors: function (errors) {
348
- log.error('Errors while compiling. Reload prevented.');
349
- var printableErrors = errors.map(function (error) {
350
- var _a = formatProblem('error', error), header = _a.header, body = _a.body;
351
- return "".concat(header, "\n").concat(stripAnsi(body));
272
+ errors (errors) {
273
+ log_js_log.error('Errors while compiling. Reload prevented.');
274
+ const printableErrors = errors.map((error)=>{
275
+ const { header, body } = formatProblem('error', error);
276
+ return `${header}\n${stripAnsi(body)}`;
352
277
  });
353
278
  sendMessage('Errors', printableErrors);
354
- for (var i = 0; i < printableErrors.length; i++) {
355
- log.error(printableErrors[i]);
356
- }
357
- var overlayErrorsSettings = typeof options.overlay === 'boolean'
358
- ? options.overlay
359
- : options.overlay && options.overlay.errors;
279
+ for(let i = 0; i < printableErrors.length; i++)log_js_log.error(printableErrors[i]);
280
+ const overlayErrorsSettings = 'boolean' == typeof options.overlay ? options.overlay : options.overlay && options.overlay.errors;
360
281
  if (overlayErrorsSettings) {
361
- var errorsToDisplay = typeof overlayErrorsSettings === 'function'
362
- ? errors.filter(overlayErrorsSettings)
363
- : errors;
364
- if (errorsToDisplay.length) {
365
- overlay.send({
366
- type: 'BUILD_ERROR',
367
- level: 'error',
368
- messages: errors,
369
- });
370
- }
282
+ const errorsToDisplay = 'function' == typeof overlayErrorsSettings ? errors.filter(overlayErrorsSettings) : errors;
283
+ if (errorsToDisplay.length) overlay.send({
284
+ type: 'BUILD_ERROR',
285
+ level: 'error',
286
+ messages: errors
287
+ });
371
288
  }
372
289
  },
373
- error: function (error) {
374
- log.error(error);
290
+ error (error) {
291
+ log_js_log.error(error);
375
292
  },
376
- close: function () {
377
- log.info('Disconnected!');
378
- if (options.overlay) {
379
- overlay.send({ type: 'DISMISS' });
380
- }
293
+ close () {
294
+ log_js_log.info('Disconnected!');
295
+ if (options.overlay) overlay.send({
296
+ type: 'DISMISS'
297
+ });
381
298
  sendMessage('Close');
382
- },
383
- };
384
- var formatURL = function (objURL) {
385
- var protocol = objURL.protocol || '';
386
- if (protocol && protocol.substr(-1) !== ':') {
387
- protocol += ':';
388
299
  }
389
- var auth = objURL.auth || '';
300
+ };
301
+ const formatURL = (objURL)=>{
302
+ let protocol = objURL.protocol || '';
303
+ if (protocol && ':' !== protocol.substr(-1)) protocol += ':';
304
+ let auth = objURL.auth || '';
390
305
  if (auth) {
391
306
  auth = encodeURIComponent(auth);
392
307
  auth = auth.replace(/%3A/i, ':');
393
308
  auth += '@';
394
309
  }
395
- var host = '';
310
+ let host = '';
396
311
  if (objURL.hostname) {
397
- host =
398
- auth +
399
- (objURL.hostname.indexOf(':') === -1
400
- ? objURL.hostname
401
- : "[".concat(objURL.hostname, "]"));
402
- if (objURL.port) {
403
- host += ":".concat(objURL.port);
404
- }
312
+ host = auth + (-1 === objURL.hostname.indexOf(':') ? objURL.hostname : `[${objURL.hostname}]`);
313
+ if (objURL.port) host += `:${objURL.port}`;
405
314
  }
406
- var pathname = objURL.pathname || '';
315
+ let pathname = objURL.pathname || '';
407
316
  if (objURL.slashes) {
408
- host = "//".concat(host || '');
409
- if (pathname && pathname.charAt(0) !== '/') {
410
- pathname = "/".concat(pathname);
411
- }
412
- }
413
- else if (!host) {
414
- host = '';
415
- }
416
- var search = objURL.search || '';
417
- if (search && search.charAt(0) !== '?') {
418
- search = "?".concat(search);
419
- }
420
- var hash = objURL.hash || '';
421
- if (hash && hash.charAt(0) !== '#') {
422
- hash = "#".concat(hash);
423
- }
424
- pathname = pathname.replace(/[?#]/g, function (match) {
425
- return encodeURIComponent(match);
426
- });
317
+ host = `//${host || ''}`;
318
+ if (pathname && '/' !== pathname.charAt(0)) pathname = `/${pathname}`;
319
+ } else if (!host) host = '';
320
+ let search = objURL.search || '';
321
+ if (search && '?' !== search.charAt(0)) search = `?${search}`;
322
+ let hash = objURL.hash || '';
323
+ if (hash && '#' !== hash.charAt(0)) hash = `#${hash}`;
324
+ pathname = pathname.replace(/[?#]/g, (match)=>encodeURIComponent(match));
427
325
  search = search.replace('#', '%23');
428
- return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
326
+ return `${protocol}${host}${pathname}${search}${hash}`;
429
327
  };
430
- var createSocketURL = function (parsedURL) {
431
- var hostname = parsedURL.hostname;
432
- // Node.js module parses it as `::`
433
- // `new URL(urlString, [baseURLString])` parses it as '[::]'
434
- var isInAddrAny = hostname === '0.0.0.0' || hostname === '::' || hostname === '[::]';
435
- // why do we need this check?
436
- // hostname n/a for file protocol (example, when using electron, ionic)
437
- // see: https://github.com/webpack/webpack-dev-server/pull/384
438
- if (isInAddrAny &&
439
- self.location.hostname &&
440
- self.location.protocol.indexOf('http') === 0) {
441
- hostname = self.location.hostname;
442
- }
443
- var socketURLProtocol = parsedURL.protocol || self.location.protocol;
444
- // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
445
- if (socketURLProtocol === 'auto:' ||
446
- (hostname && isInAddrAny && self.location.protocol === 'https:')) {
447
- socketURLProtocol = self.location.protocol;
448
- }
328
+ const createSocketURL = (parsedURL)=>{
329
+ let { hostname } = parsedURL;
330
+ const isInAddrAny = '0.0.0.0' === hostname || '::' === hostname || '[::]' === hostname;
331
+ if (isInAddrAny && self.location.hostname && 0 === self.location.protocol.indexOf('http')) hostname = self.location.hostname;
332
+ let socketURLProtocol = parsedURL.protocol || self.location.protocol;
333
+ if ('auto:' === socketURLProtocol || hostname && isInAddrAny && 'https:' === self.location.protocol) socketURLProtocol = self.location.protocol;
449
334
  socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, 'ws');
450
- var socketURLAuth = '';
451
- // `new URL(urlString, [baseURLstring])` doesn't have `auth` property
452
- // Parse authentication credentials in case we need them
335
+ let socketURLAuth = '';
453
336
  if (parsedURL.username) {
454
337
  socketURLAuth = parsedURL.username;
455
- // Since HTTP basic authentication does not allow empty username,
456
- // we only include password if the username is not empty.
457
- if (parsedURL.password) {
458
- // Result: <username>:<password>
459
- socketURLAuth = socketURLAuth.concat(':', parsedURL.password);
460
- }
461
- }
462
- // In case the host is a raw IPv6 address, it can be enclosed in
463
- // the brackets as the brackets are needed in the final URL string.
464
- // Need to remove those as url.format blindly adds its own set of brackets
465
- // if the host string contains colons. That would lead to non-working
466
- // double brackets (e.g. [[::]]) host
467
- //
468
- // All of these web socket url params are optionally passed in through resourceQuery,
469
- // so we need to fall back to the default if they are not provided
470
- var socketURLHostname = (hostname ||
471
- self.location.hostname ||
472
- 'localhost').replace(/^\[(.*)\]$/, '$1');
473
- var socketURLPort = parsedURL.port;
474
- if (!socketURLPort || socketURLPort === '0') {
475
- socketURLPort = self.location.port;
476
- }
477
- // If path is provided it'll be passed in via the resourceQuery as a
478
- // query param so it has to be parsed out of the querystring in order for the
479
- // client to open the socket to the correct location.
480
- var socketURLPathname = '/ws';
481
- if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
482
- socketURLPathname = parsedURL.pathname;
338
+ if (parsedURL.password) socketURLAuth = socketURLAuth.concat(':', parsedURL.password);
483
339
  }
340
+ const socketURLHostname = (hostname || self.location.hostname || 'localhost').replace(/^\[(.*)\]$/, '$1');
341
+ let socketURLPort = parsedURL.port;
342
+ if (!socketURLPort || '0' === socketURLPort) socketURLPort = self.location.port;
343
+ let socketURLPathname = '/ws';
344
+ if (parsedURL.pathname && !parsedURL.fromCurrentScript) socketURLPathname = parsedURL.pathname;
484
345
  return formatURL({
485
346
  protocol: socketURLProtocol,
486
347
  auth: socketURLAuth,
487
348
  hostname: socketURLHostname,
488
349
  port: socketURLPort,
489
350
  pathname: socketURLPathname,
490
- slashes: true,
351
+ slashes: true
491
352
  });
492
353
  };
493
- var socketURL = createSocketURL(parsedResourceQuery);
354
+ const socketURL = createSocketURL(parsedResourceQuery);
494
355
  socket(socketURL, onSocketMessage, options.reconnect);
495
- export { getCurrentScriptSource, parseURL, createSocketURL };
356
+ export { createSocketURL, getCurrentScriptSource, parseURL };