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