@rspack/dev-server 2.0.0-beta.1 → 2.0.0-beta.3
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 +4 -3
- package/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +28 -28
- package/client/index.d.ts +17 -0
- package/client/index.js +224 -363
- package/client/modules/logger/Logger.d.ts +40 -0
- package/client/modules/logger/Logger.js +123 -0
- package/client/modules/logger/createConsoleLogger.d.ts +12 -0
- package/client/modules/logger/createConsoleLogger.js +119 -0
- package/client/modules/logger/index.d.ts +18 -0
- package/client/modules/logger/index.js +20 -712
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +44 -0
- package/client/overlay.js +241 -290
- package/client/progress.d.ts +11 -0
- package/client/progress.js +178 -111
- package/client/socket.d.ts +15 -0
- package/client/socket.js +19 -46
- package/client/type.d.ts +15 -0
- package/client/type.js +0 -0
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +106 -153
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +7 -17
- package/client/utils/sendMessage.d.ts +11 -0
- package/client/utils/sendMessage.js +6 -15
- package/dist/0~launch-editor.js +618 -0
- package/dist/0~open.js +547 -0
- package/dist/0~p-retry.js +158 -0
- package/dist/131.js +1402 -0
- package/dist/getPort.d.ts +4 -1
- package/dist/index.js +1 -5
- package/dist/rslib-runtime.js +66 -0
- package/dist/server.d.ts +10 -9
- package/dist/servers/WebsocketServer.d.ts +8 -1
- package/dist/types.d.ts +16 -14
- package/package.json +62 -65
- package/dist/config.js +0 -2
- package/dist/getPort.js +0 -141
- package/dist/server.js +0 -1971
- package/dist/servers/BaseServer.js +0 -20
- package/dist/servers/WebsocketServer.js +0 -72
- package/dist/types.js +0 -5
package/client/index.js
CHANGED
|
@@ -1,66 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
if (typeof resourceQuery
|
|
44
|
-
|
|
45
|
-
for
|
|
46
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
-
|
|
65
|
+
const client_src_status = {
|
|
72
66
|
isUnloading: false,
|
|
73
|
-
currentHash: __webpack_hash__
|
|
67
|
+
currentHash: __webpack_hash__
|
|
74
68
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
74
|
+
const currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
|
86
75
|
return currentScript.getAttribute('src');
|
|
87
76
|
}
|
|
88
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
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
|
|
92
|
+
if ('true' === parsedResourceQuery.hot) {
|
|
105
93
|
options.hot = true;
|
|
106
94
|
enabledFeatures['Hot Module Replacement'] = true;
|
|
107
95
|
}
|
|
108
|
-
if (parsedResourceQuery['live-reload']
|
|
96
|
+
if ('true' === parsedResourceQuery['live-reload']) {
|
|
109
97
|
options.liveReload = true;
|
|
110
98
|
enabledFeatures['Live Reloading'] = true;
|
|
111
99
|
}
|
|
112
|
-
if (parsedResourceQuery.progress
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
136
|
+
log_js_log.info(logString);
|
|
158
137
|
};
|
|
159
138
|
logEnabledFeatures(enabledFeatures);
|
|
160
|
-
self.addEventListener('beforeunload',
|
|
161
|
-
|
|
139
|
+
self.addEventListener('beforeunload', ()=>{
|
|
140
|
+
client_src_status.isUnloading = true;
|
|
162
141
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (
|
|
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
|
-
|
|
158
|
+
log_js_log.info('App updated. Reloading...');
|
|
187
159
|
rootWindow.location.reload();
|
|
188
160
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
if (typeof self
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
211
|
-
if (
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
'(
|
|
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
|
-
|
|
237
|
-
hot
|
|
238
|
-
if (parsedResourceQuery.hot
|
|
239
|
-
return;
|
|
240
|
-
}
|
|
184
|
+
const onSocketMessage = {
|
|
185
|
+
hot () {
|
|
186
|
+
if ('false' === parsedResourceQuery.hot) return;
|
|
241
187
|
options.hot = true;
|
|
242
188
|
},
|
|
243
|
-
liveReload
|
|
244
|
-
if (parsedResourceQuery['live-reload']
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
189
|
+
liveReload () {
|
|
190
|
+
if ('false' === parsedResourceQuery['live-reload']) return;
|
|
247
191
|
options.liveReload = true;
|
|
248
192
|
},
|
|
249
|
-
invalid
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
|
258
|
-
if (!_hash)
|
|
259
|
-
|
|
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
|
|
266
|
-
if (typeof document
|
|
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
|
|
273
|
-
if (parsedResourceQuery.reconnect
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
211
|
+
reconnect (value) {
|
|
212
|
+
if ('false' === parsedResourceQuery.reconnect) return;
|
|
276
213
|
options.reconnect = value;
|
|
277
214
|
},
|
|
278
|
-
progress
|
|
215
|
+
progress (value) {
|
|
279
216
|
options.progress = value;
|
|
280
217
|
},
|
|
281
|
-
'progress-update': function
|
|
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
|
|
287
|
-
|
|
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
|
|
300
|
-
|
|
301
|
-
if (options.overlay) {
|
|
302
|
-
|
|
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
|
|
241
|
+
ok () {
|
|
307
242
|
sendMessage('Ok');
|
|
308
|
-
if (options.overlay) {
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
reloadApp(options,
|
|
243
|
+
if (options.overlay) overlay.send({
|
|
244
|
+
type: 'DISMISS'
|
|
245
|
+
});
|
|
246
|
+
reloadApp(options, client_src_status);
|
|
312
247
|
},
|
|
313
|
-
'static-changed': function
|
|
314
|
-
|
|
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
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
return
|
|
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
|
|
325
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
:
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
-
|
|
344
|
-
}
|
|
345
|
-
reloadApp(options, status);
|
|
269
|
+
if (params && params.preventReloading) return;
|
|
270
|
+
reloadApp(options, client_src_status);
|
|
346
271
|
},
|
|
347
|
-
errors
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return
|
|
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
|
|
355
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
:
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
|
374
|
-
|
|
290
|
+
error (error) {
|
|
291
|
+
log_js_log.error(error);
|
|
375
292
|
},
|
|
376
|
-
close
|
|
377
|
-
|
|
378
|
-
if (options.overlay) {
|
|
379
|
-
|
|
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
|
-
|
|
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
|
-
|
|
310
|
+
let host = '';
|
|
396
311
|
if (objURL.hostname) {
|
|
397
|
-
host =
|
|
398
|
-
|
|
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
|
-
|
|
315
|
+
let pathname = objURL.pathname || '';
|
|
407
316
|
if (objURL.slashes) {
|
|
408
|
-
host =
|
|
409
|
-
if (pathname && pathname.charAt(0)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
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
|
|
326
|
+
return `${protocol}${host}${pathname}${search}${hash}`;
|
|
429
327
|
};
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
354
|
+
const socketURL = createSocketURL(parsedResourceQuery);
|
|
494
355
|
socket(socketURL, onSocketMessage, options.reconnect);
|
|
495
|
-
export { getCurrentScriptSource, parseURL
|
|
356
|
+
export { createSocketURL, getCurrentScriptSource, parseURL };
|