@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
|
@@ -0,0 +1,503 @@
|
|
|
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
|
+
// The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
|
|
22
|
+
// They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).
|
|
23
|
+
import ansiHTML from './utils/ansiHTML';
|
|
24
|
+
var getCodePoint = !!String.prototype.codePointAt
|
|
25
|
+
? function (input, position) {
|
|
26
|
+
return input.codePointAt(position);
|
|
27
|
+
}
|
|
28
|
+
: function (input, position) {
|
|
29
|
+
return (input.charCodeAt(position) - 0xd800) * 0x400 +
|
|
30
|
+
input.charCodeAt(position + 1) -
|
|
31
|
+
0xdc00 +
|
|
32
|
+
0x10000;
|
|
33
|
+
};
|
|
34
|
+
var replaceUsingRegExp = function (macroText, macroRegExp, macroReplacer) {
|
|
35
|
+
macroRegExp.lastIndex = 0;
|
|
36
|
+
var replaceMatch = macroRegExp.exec(macroText);
|
|
37
|
+
var replaceResult;
|
|
38
|
+
if (replaceMatch) {
|
|
39
|
+
replaceResult = '';
|
|
40
|
+
var replaceLastIndex = 0;
|
|
41
|
+
do {
|
|
42
|
+
if (replaceLastIndex !== replaceMatch.index) {
|
|
43
|
+
replaceResult += macroText.slice(replaceLastIndex, replaceMatch.index);
|
|
44
|
+
}
|
|
45
|
+
var replaceInput = replaceMatch[0];
|
|
46
|
+
replaceResult += macroReplacer(replaceInput);
|
|
47
|
+
replaceLastIndex = replaceMatch.index + replaceInput.length;
|
|
48
|
+
} while ((replaceMatch = macroRegExp.exec(macroText)));
|
|
49
|
+
if (replaceLastIndex !== macroText.length) {
|
|
50
|
+
replaceResult += macroText.slice(replaceLastIndex);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
replaceResult = macroText;
|
|
55
|
+
}
|
|
56
|
+
return replaceResult;
|
|
57
|
+
};
|
|
58
|
+
var references = {
|
|
59
|
+
'<': '<',
|
|
60
|
+
'>': '>',
|
|
61
|
+
'"': '"',
|
|
62
|
+
"'": ''',
|
|
63
|
+
'&': '&',
|
|
64
|
+
};
|
|
65
|
+
function encode(text) {
|
|
66
|
+
if (!text) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
return replaceUsingRegExp(text, /[<>'"&]/g, function (input) {
|
|
70
|
+
var result = references[input];
|
|
71
|
+
if (!result) {
|
|
72
|
+
var code = input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0);
|
|
73
|
+
result = "&#".concat(code, ";");
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A simplified `createMachine` from `@xstate/fsm` with the following differences:
|
|
80
|
+
* - the returned machine is technically a "service". No `interpret(machine).start()` is needed.
|
|
81
|
+
* - the state definition only support `on` and target must be declared with { target: 'nextState', actions: [] } explicitly.
|
|
82
|
+
* - event passed to `send` must be an object with `type` property.
|
|
83
|
+
* - actions implementation will be [assign action](https://xstate.js.org/docs/guides/context.html#assign-action) if you return any value.
|
|
84
|
+
* Do not return anything if you just want to invoke side effect.
|
|
85
|
+
*
|
|
86
|
+
* The goal of this custom function is to avoid installing the entire `'xstate/fsm'` package, while enabling modeling using
|
|
87
|
+
* state machine. You can copy the first parameter into the editor at https://stately.ai/viz to visualize the state machine.
|
|
88
|
+
*/
|
|
89
|
+
function createMachine(_a, _b) {
|
|
90
|
+
var states = _a.states, context = _a.context, initial = _a.initial;
|
|
91
|
+
var actions = _b.actions;
|
|
92
|
+
var currentState = initial;
|
|
93
|
+
var currentContext = context;
|
|
94
|
+
return {
|
|
95
|
+
send: function (event) {
|
|
96
|
+
var currentStateOn = states[currentState].on;
|
|
97
|
+
var transitionConfig = currentStateOn && currentStateOn[event.type];
|
|
98
|
+
if (transitionConfig) {
|
|
99
|
+
currentState = transitionConfig.target;
|
|
100
|
+
if (transitionConfig.actions) {
|
|
101
|
+
transitionConfig.actions.forEach(function (actName) {
|
|
102
|
+
var actionImpl = actions[actName];
|
|
103
|
+
var nextContextValue = actionImpl && actionImpl(currentContext, event);
|
|
104
|
+
if (nextContextValue) {
|
|
105
|
+
currentContext = __assign(__assign({}, currentContext), nextContextValue);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
var createOverlayMachine = function (options) {
|
|
114
|
+
var hideOverlay = options.hideOverlay, showOverlay = options.showOverlay;
|
|
115
|
+
return createMachine({
|
|
116
|
+
initial: 'hidden',
|
|
117
|
+
context: {
|
|
118
|
+
level: 'error',
|
|
119
|
+
messages: [],
|
|
120
|
+
messageSource: 'build',
|
|
121
|
+
},
|
|
122
|
+
states: {
|
|
123
|
+
hidden: {
|
|
124
|
+
on: {
|
|
125
|
+
BUILD_ERROR: {
|
|
126
|
+
target: 'displayBuildError',
|
|
127
|
+
actions: ['setMessages', 'showOverlay'],
|
|
128
|
+
},
|
|
129
|
+
RUNTIME_ERROR: {
|
|
130
|
+
target: 'displayRuntimeError',
|
|
131
|
+
actions: ['setMessages', 'showOverlay'],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
displayBuildError: {
|
|
136
|
+
on: {
|
|
137
|
+
DISMISS: {
|
|
138
|
+
target: 'hidden',
|
|
139
|
+
actions: ['dismissMessages', 'hideOverlay'],
|
|
140
|
+
},
|
|
141
|
+
BUILD_ERROR: {
|
|
142
|
+
target: 'displayBuildError',
|
|
143
|
+
actions: ['appendMessages', 'showOverlay'],
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
displayRuntimeError: {
|
|
148
|
+
on: {
|
|
149
|
+
DISMISS: {
|
|
150
|
+
target: 'hidden',
|
|
151
|
+
actions: ['dismissMessages', 'hideOverlay'],
|
|
152
|
+
},
|
|
153
|
+
RUNTIME_ERROR: {
|
|
154
|
+
target: 'displayRuntimeError',
|
|
155
|
+
actions: ['appendMessages', 'showOverlay'],
|
|
156
|
+
},
|
|
157
|
+
BUILD_ERROR: {
|
|
158
|
+
target: 'displayBuildError',
|
|
159
|
+
actions: ['setMessages', 'showOverlay'],
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}, {
|
|
165
|
+
actions: {
|
|
166
|
+
dismissMessages: function () {
|
|
167
|
+
return {
|
|
168
|
+
messages: [],
|
|
169
|
+
level: 'error',
|
|
170
|
+
messageSource: 'build',
|
|
171
|
+
};
|
|
172
|
+
},
|
|
173
|
+
appendMessages: function (context, event) {
|
|
174
|
+
return {
|
|
175
|
+
messages: context.messages.concat(event.messages),
|
|
176
|
+
level: event.level || context.level,
|
|
177
|
+
messageSource: event.type === 'RUNTIME_ERROR' ? 'runtime' : 'build',
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
setMessages: function (context, event) {
|
|
181
|
+
return {
|
|
182
|
+
messages: event.messages,
|
|
183
|
+
level: event.level || context.level,
|
|
184
|
+
messageSource: event.type === 'RUNTIME_ERROR' ? 'runtime' : 'build',
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
hideOverlay: hideOverlay,
|
|
188
|
+
showOverlay: showOverlay,
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
var parseErrorToStacks = function (error) {
|
|
193
|
+
if (!error || !(error instanceof Error)) {
|
|
194
|
+
throw new Error('parseErrorToStacks expects Error object');
|
|
195
|
+
}
|
|
196
|
+
if (typeof error.stack === 'string') {
|
|
197
|
+
return error.stack
|
|
198
|
+
.split('\n')
|
|
199
|
+
.filter(function (stack) { return stack !== "Error: ".concat(error.message); });
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var listenToRuntimeError = function (callback) {
|
|
203
|
+
window.addEventListener('error', callback);
|
|
204
|
+
return function cleanup() {
|
|
205
|
+
window.removeEventListener('error', callback);
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
var listenToUnhandledRejection = function (callback) {
|
|
209
|
+
window.addEventListener('unhandledrejection', callback);
|
|
210
|
+
return function cleanup() {
|
|
211
|
+
window.removeEventListener('unhandledrejection', callback);
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
// Styles are inspired by `react-error-overlay`
|
|
215
|
+
var msgStyles = {
|
|
216
|
+
error: {
|
|
217
|
+
backgroundColor: 'rgba(206, 17, 38, 0.1)',
|
|
218
|
+
color: '#fccfcf',
|
|
219
|
+
},
|
|
220
|
+
warning: {
|
|
221
|
+
backgroundColor: 'rgba(251, 245, 180, 0.1)',
|
|
222
|
+
color: '#fbf5b4',
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
var iframeStyle = {
|
|
226
|
+
position: 'fixed',
|
|
227
|
+
top: '0px',
|
|
228
|
+
left: '0px',
|
|
229
|
+
right: '0px',
|
|
230
|
+
bottom: '0px',
|
|
231
|
+
width: '100vw',
|
|
232
|
+
height: '100vh',
|
|
233
|
+
border: 'none',
|
|
234
|
+
'z-index': 9999999999,
|
|
235
|
+
};
|
|
236
|
+
var containerStyle = {
|
|
237
|
+
position: 'fixed',
|
|
238
|
+
boxSizing: 'border-box',
|
|
239
|
+
left: '0px',
|
|
240
|
+
top: '0px',
|
|
241
|
+
right: '0px',
|
|
242
|
+
bottom: '0px',
|
|
243
|
+
width: '100vw',
|
|
244
|
+
height: '100vh',
|
|
245
|
+
fontSize: 'large',
|
|
246
|
+
padding: '2rem 2rem 4rem 2rem',
|
|
247
|
+
lineHeight: '1.2',
|
|
248
|
+
whiteSpace: 'pre-wrap',
|
|
249
|
+
overflow: 'auto',
|
|
250
|
+
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
|
251
|
+
color: 'white',
|
|
252
|
+
};
|
|
253
|
+
var headerStyle = {
|
|
254
|
+
color: '#e83b46',
|
|
255
|
+
fontSize: '2em',
|
|
256
|
+
whiteSpace: 'pre-wrap',
|
|
257
|
+
fontFamily: 'sans-serif',
|
|
258
|
+
margin: '0 2rem 2rem 0',
|
|
259
|
+
flex: '0 0 auto',
|
|
260
|
+
maxHeight: '50%',
|
|
261
|
+
overflow: 'auto',
|
|
262
|
+
};
|
|
263
|
+
var dismissButtonStyle = {
|
|
264
|
+
color: '#ffffff',
|
|
265
|
+
lineHeight: '1rem',
|
|
266
|
+
fontSize: '1.5rem',
|
|
267
|
+
padding: '1rem',
|
|
268
|
+
cursor: 'pointer',
|
|
269
|
+
position: 'absolute',
|
|
270
|
+
right: '0px',
|
|
271
|
+
top: '0px',
|
|
272
|
+
backgroundColor: 'transparent',
|
|
273
|
+
border: 'none',
|
|
274
|
+
};
|
|
275
|
+
var msgTypeStyle = {
|
|
276
|
+
color: '#e83b46',
|
|
277
|
+
fontSize: '1.2em',
|
|
278
|
+
marginBottom: '1rem',
|
|
279
|
+
fontFamily: 'sans-serif',
|
|
280
|
+
};
|
|
281
|
+
var msgTextStyle = {
|
|
282
|
+
lineHeight: '1.5',
|
|
283
|
+
fontSize: '1rem',
|
|
284
|
+
fontFamily: 'Menlo, Consolas, monospace',
|
|
285
|
+
};
|
|
286
|
+
// ANSI HTML
|
|
287
|
+
var colors = {
|
|
288
|
+
reset: ['transparent', 'transparent'],
|
|
289
|
+
black: '181818',
|
|
290
|
+
red: 'E36049',
|
|
291
|
+
green: 'B3CB74',
|
|
292
|
+
yellow: 'FFD080',
|
|
293
|
+
blue: '7CAFC2',
|
|
294
|
+
magenta: '7FACCA',
|
|
295
|
+
cyan: 'C3C2EF',
|
|
296
|
+
lightgrey: 'EBE7E3',
|
|
297
|
+
darkgrey: '6D7891',
|
|
298
|
+
};
|
|
299
|
+
ansiHTML.setColors(colors);
|
|
300
|
+
var formatProblem = function (type, item) {
|
|
301
|
+
var header = type === 'warning' ? 'WARNING' : 'ERROR';
|
|
302
|
+
var body = '';
|
|
303
|
+
if (typeof item === 'string') {
|
|
304
|
+
body += item;
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
var file = item.file || '';
|
|
308
|
+
var moduleName = item.moduleName
|
|
309
|
+
? item.moduleName.indexOf('!') !== -1
|
|
310
|
+
? "".concat(item.moduleName.replace(/^(\s|\S)*!/, ''), " (").concat(item.moduleName, ")")
|
|
311
|
+
: "".concat(item.moduleName)
|
|
312
|
+
: '';
|
|
313
|
+
var loc = item.loc;
|
|
314
|
+
header += "".concat(moduleName || file
|
|
315
|
+
? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : '') : file).concat(loc ? " ".concat(loc) : '')
|
|
316
|
+
: '');
|
|
317
|
+
body += item.message || '';
|
|
318
|
+
}
|
|
319
|
+
if (typeof item !== 'string' && Array.isArray(item.stack)) {
|
|
320
|
+
item.stack.forEach(function (stack) {
|
|
321
|
+
if (typeof stack === 'string') {
|
|
322
|
+
body += "\r\n".concat(stack);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
return { header: header, body: body };
|
|
327
|
+
};
|
|
328
|
+
var createOverlay = function (options) {
|
|
329
|
+
var iframeContainerElement;
|
|
330
|
+
var containerElement;
|
|
331
|
+
var headerElement;
|
|
332
|
+
var onLoadQueue = [];
|
|
333
|
+
var overlayTrustedTypesPolicy;
|
|
334
|
+
function applyStyle(element, style) {
|
|
335
|
+
Object.keys(style).forEach(function (prop) {
|
|
336
|
+
element.style[prop] =
|
|
337
|
+
style[prop];
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function createContainer(trustedTypesPolicyName) {
|
|
341
|
+
// Enable Trusted Types if they are available in the current browser.
|
|
342
|
+
if (window.trustedTypes) {
|
|
343
|
+
overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || 'webpack-dev-server#overlay', {
|
|
344
|
+
createHTML: function (value) { return value; },
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
iframeContainerElement = document.createElement('iframe');
|
|
348
|
+
iframeContainerElement.id = 'webpack-dev-server-client-overlay';
|
|
349
|
+
iframeContainerElement.src = 'about:blank';
|
|
350
|
+
applyStyle(iframeContainerElement, iframeStyle);
|
|
351
|
+
iframeContainerElement.onload = function () {
|
|
352
|
+
var contentElement = (iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
353
|
+
containerElement = (iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
354
|
+
contentElement.id = 'webpack-dev-server-client-overlay-div';
|
|
355
|
+
applyStyle(contentElement, containerStyle);
|
|
356
|
+
headerElement = document.createElement('div');
|
|
357
|
+
headerElement.innerText = 'Compiled with problems:';
|
|
358
|
+
applyStyle(headerElement, headerStyle);
|
|
359
|
+
var closeButtonElement = document.createElement('button');
|
|
360
|
+
applyStyle(closeButtonElement, dismissButtonStyle);
|
|
361
|
+
closeButtonElement.innerText = '×';
|
|
362
|
+
closeButtonElement.ariaLabel = 'Dismiss';
|
|
363
|
+
closeButtonElement.addEventListener('click', function () {
|
|
364
|
+
// eslint-disable-next-line no-use-before-define
|
|
365
|
+
overlayService.send({ type: 'DISMISS' });
|
|
366
|
+
});
|
|
367
|
+
contentElement.appendChild(headerElement);
|
|
368
|
+
contentElement.appendChild(closeButtonElement);
|
|
369
|
+
contentElement.appendChild(containerElement);
|
|
370
|
+
(iframeContainerElement === null || iframeContainerElement === void 0 ? void 0 : iframeContainerElement.contentDocument).body.appendChild(contentElement);
|
|
371
|
+
onLoadQueue.forEach(function (onLoad) {
|
|
372
|
+
onLoad(contentElement);
|
|
373
|
+
});
|
|
374
|
+
onLoadQueue = [];
|
|
375
|
+
iframeContainerElement.onload = null;
|
|
376
|
+
};
|
|
377
|
+
document.body.appendChild(iframeContainerElement);
|
|
378
|
+
}
|
|
379
|
+
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
380
|
+
if (containerElement) {
|
|
381
|
+
containerElement.innerHTML = overlayTrustedTypesPolicy
|
|
382
|
+
? overlayTrustedTypesPolicy.createHTML('')
|
|
383
|
+
: '';
|
|
384
|
+
// Everything is ready, call the callback right away.
|
|
385
|
+
callback(containerElement);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
onLoadQueue.push(callback);
|
|
389
|
+
if (iframeContainerElement) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
createContainer(trustedTypesPolicyName);
|
|
393
|
+
}
|
|
394
|
+
// Successful compilation.
|
|
395
|
+
function hide() {
|
|
396
|
+
if (!iframeContainerElement) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
// Clean up and reset internal state.
|
|
400
|
+
document.body.removeChild(iframeContainerElement);
|
|
401
|
+
iframeContainerElement = null;
|
|
402
|
+
containerElement = null;
|
|
403
|
+
}
|
|
404
|
+
// Compilation with errors (e.g. syntax error or missing modules).
|
|
405
|
+
function show(type, messages, trustedTypesPolicyName, messageSource) {
|
|
406
|
+
ensureOverlayExists(function () {
|
|
407
|
+
headerElement.innerText =
|
|
408
|
+
messageSource === 'runtime'
|
|
409
|
+
? 'Uncaught runtime errors:'
|
|
410
|
+
: 'Compiled with problems:';
|
|
411
|
+
messages.forEach(function (message) {
|
|
412
|
+
var entryElement = document.createElement('div');
|
|
413
|
+
var msgStyle = type === 'warning' ? msgStyles.warning : msgStyles.error;
|
|
414
|
+
applyStyle(entryElement, __assign(__assign({}, msgStyle), { padding: '1rem 1rem 1.5rem 1rem' }));
|
|
415
|
+
var typeElement = document.createElement('div');
|
|
416
|
+
var _a = formatProblem(type, message), header = _a.header, body = _a.body;
|
|
417
|
+
typeElement.innerText = header;
|
|
418
|
+
applyStyle(typeElement, msgTypeStyle);
|
|
419
|
+
if (typeof message !== 'string' && message.moduleIdentifier) {
|
|
420
|
+
applyStyle(typeElement, { cursor: 'pointer' });
|
|
421
|
+
// element.dataset not supported in IE
|
|
422
|
+
typeElement.setAttribute('data-can-open', 'true');
|
|
423
|
+
typeElement.addEventListener('click', function () {
|
|
424
|
+
fetch("/webpack-dev-server/open-editor?fileName=".concat(message.moduleIdentifier));
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
// Make it look similar to our terminal.
|
|
428
|
+
var text = ansiHTML(encode(body));
|
|
429
|
+
var messageTextNode = document.createElement('div');
|
|
430
|
+
applyStyle(messageTextNode, msgTextStyle);
|
|
431
|
+
messageTextNode.innerHTML = overlayTrustedTypesPolicy
|
|
432
|
+
? overlayTrustedTypesPolicy.createHTML(text)
|
|
433
|
+
: text;
|
|
434
|
+
entryElement.appendChild(typeElement);
|
|
435
|
+
entryElement.appendChild(messageTextNode);
|
|
436
|
+
containerElement === null || containerElement === void 0 ? void 0 : containerElement.appendChild(entryElement);
|
|
437
|
+
});
|
|
438
|
+
}, trustedTypesPolicyName);
|
|
439
|
+
}
|
|
440
|
+
var handleEscapeKey;
|
|
441
|
+
var hideOverlayWithEscCleanup = function () {
|
|
442
|
+
window.removeEventListener('keydown', handleEscapeKey);
|
|
443
|
+
hide();
|
|
444
|
+
};
|
|
445
|
+
var overlayService = createOverlayMachine({
|
|
446
|
+
showOverlay: function (_a) {
|
|
447
|
+
var _b = _a.level, level = _b === void 0 ? 'error' : _b, messages = _a.messages, messageSource = _a.messageSource;
|
|
448
|
+
return show(level, messages, options.trustedTypesPolicyName, messageSource);
|
|
449
|
+
},
|
|
450
|
+
hideOverlay: hideOverlayWithEscCleanup,
|
|
451
|
+
});
|
|
452
|
+
/**
|
|
453
|
+
* ESC key press to dismiss the overlay.
|
|
454
|
+
*/
|
|
455
|
+
handleEscapeKey = function (event) {
|
|
456
|
+
if (event.key === 'Escape' || event.key === 'Esc' || event.keyCode === 27) {
|
|
457
|
+
overlayService.send({ type: 'DISMISS' });
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
window.addEventListener('keydown', handleEscapeKey);
|
|
461
|
+
if (options.catchRuntimeError) {
|
|
462
|
+
var handleError_1 = function (error, fallbackMessage) {
|
|
463
|
+
var errorObject = error instanceof Error
|
|
464
|
+
? error
|
|
465
|
+
: // @ts-expect-error error options
|
|
466
|
+
new Error(error || fallbackMessage, { cause: error });
|
|
467
|
+
var shouldDisplay = typeof options.catchRuntimeError === 'function'
|
|
468
|
+
? options.catchRuntimeError(errorObject)
|
|
469
|
+
: true;
|
|
470
|
+
if (shouldDisplay) {
|
|
471
|
+
overlayService.send({
|
|
472
|
+
type: 'RUNTIME_ERROR',
|
|
473
|
+
messages: [
|
|
474
|
+
{
|
|
475
|
+
message: errorObject.message,
|
|
476
|
+
stack: parseErrorToStacks(errorObject),
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
listenToRuntimeError(function (errorEvent) {
|
|
483
|
+
// error property may be empty in older browser like IE
|
|
484
|
+
var error = errorEvent.error, message = errorEvent.message;
|
|
485
|
+
if (!error && !message) {
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
// if error stack indicates a React error boundary caught the error, do not show overlay.
|
|
489
|
+
if (error &&
|
|
490
|
+
error.stack &&
|
|
491
|
+
error.stack.includes('invokeGuardedCallbackDev')) {
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
handleError_1(error, message);
|
|
495
|
+
});
|
|
496
|
+
listenToUnhandledRejection(function (promiseRejectionEvent) {
|
|
497
|
+
var reason = promiseRejectionEvent.reason;
|
|
498
|
+
handleError_1(reason, 'Unknown promise rejection reason');
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
return overlayService;
|
|
502
|
+
};
|
|
503
|
+
export { createOverlay, formatProblem };
|
|
@@ -0,0 +1,130 @@
|
|
|
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 __extends = (this && this.__extends) || (function () {
|
|
11
|
+
var extendStatics = function (d, b) {
|
|
12
|
+
extendStatics = Object.setPrototypeOf ||
|
|
13
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
14
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
15
|
+
return extendStatics(d, b);
|
|
16
|
+
};
|
|
17
|
+
return function (d, b) {
|
|
18
|
+
if (typeof b !== "function" && b !== null)
|
|
19
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
20
|
+
extendStatics(d, b);
|
|
21
|
+
function __() { this.constructor = d; }
|
|
22
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
23
|
+
};
|
|
24
|
+
})();
|
|
25
|
+
export function isProgressSupported() {
|
|
26
|
+
return ('customElements' in self && Boolean(HTMLElement.prototype.attachShadow));
|
|
27
|
+
}
|
|
28
|
+
export function defineProgressElement() {
|
|
29
|
+
if (customElements.get('wds-progress')) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var WebpackDevServerProgress = /** @class */ (function (_super) {
|
|
33
|
+
__extends(WebpackDevServerProgress, _super);
|
|
34
|
+
function WebpackDevServerProgress() {
|
|
35
|
+
var _this = _super.call(this) || this;
|
|
36
|
+
_this.attachShadow({ mode: 'open' });
|
|
37
|
+
_this.maxDashOffset = -219.99078369140625;
|
|
38
|
+
_this.animationTimer = undefined;
|
|
39
|
+
_this.type = 'circular';
|
|
40
|
+
_this.initialProgress = 0;
|
|
41
|
+
return _this;
|
|
42
|
+
}
|
|
43
|
+
WebpackDevServerProgress.prototype.reset = function () {
|
|
44
|
+
var _a;
|
|
45
|
+
clearTimeout(this.animationTimer);
|
|
46
|
+
this.animationTimer = undefined;
|
|
47
|
+
var typeAttr = (_a = this.getAttribute('type')) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
48
|
+
this.type = typeAttr === 'circular' ? 'circular' : 'linear';
|
|
49
|
+
var innerHTML = this.type === 'circular'
|
|
50
|
+
? WebpackDevServerProgress.circularTemplate()
|
|
51
|
+
: WebpackDevServerProgress.linearTemplate();
|
|
52
|
+
this.shadowRoot.innerHTML = innerHTML;
|
|
53
|
+
var progressValue = this.getAttribute('progress');
|
|
54
|
+
this.initialProgress = progressValue ? Number(progressValue) : 0;
|
|
55
|
+
this.update(this.initialProgress);
|
|
56
|
+
};
|
|
57
|
+
WebpackDevServerProgress.circularTemplate = function () {
|
|
58
|
+
return "\n <style>\n :host {\n width: 200px;\n height: 200px;\n position: fixed;\n right: 5%;\n top: 5%;\n pointer-events: none;\n transition: opacity .25s ease-in-out;\n z-index: 2147483645;\n }\n\n circle {\n fill: #282d35;\n }\n\n path {\n fill: rgba(0, 0, 0, 0);\n stroke: rgb(186, 223, 172);\n stroke-dasharray: 219.99078369140625;\n stroke-dashoffset: -219.99078369140625;\n stroke-width: 10;\n transform: rotate(90deg) translate(0px, -80px);\n }\n\n text {\n font-family: 'Open Sans', sans-serif;\n font-size: 18px;\n fill: #ffffff;\n dominant-baseline: middle;\n text-anchor: middle;\n }\n\n tspan#percent-super {\n fill: #bdc3c7;\n font-size: 0.45em;\n baseline-shift: 10%;\n }\n\n @keyframes fade {\n 0% { opacity: 1; transform: scale(1); }\n 100% { opacity: 0; transform: scale(0); }\n }\n\n .disappear {\n animation: fade 0.3s;\n animation-fill-mode: forwards;\n animation-delay: 0.5s;\n }\n\n .hidden {\n display: none;\n }\n </style>\n <svg id=\"progress\" class=\"hidden noselect\" viewBox=\"0 0 80 80\">\n <circle cx=\"50%\" cy=\"50%\" r=\"35\"></circle>\n <path d=\"M5,40a35,35 0 1,0 70,0a35,35 0 1,0 -70,0\"></path>\n <text x=\"50%\" y=\"51%\">\n <tspan id=\"percent-value\">0</tspan>\n <tspan id=\"percent-super\">%</tspan>\n </text>\n </svg>\n ";
|
|
59
|
+
};
|
|
60
|
+
WebpackDevServerProgress.linearTemplate = function () {
|
|
61
|
+
return "\n <style>\n :host {\n position: fixed;\n top: 0;\n left: 0;\n pointer-events: none;\n height: 4px;\n width: 100vw;\n z-index: 2147483645;\n }\n\n #bar {\n width: 0%;\n height: 4px;\n background-color: rgb(186, 223, 172);\n }\n\n @keyframes fade {\n 0% { opacity: 1; }\n 100% { opacity: 0; }\n }\n\n .disappear {\n animation: fade 0.3s;\n animation-fill-mode: forwards;\n animation-delay: 0.5s;\n }\n\n .hidden {\n display: none;\n }\n </style>\n <div id=\"progress\"></div>\n ";
|
|
62
|
+
};
|
|
63
|
+
WebpackDevServerProgress.prototype.connectedCallback = function () {
|
|
64
|
+
this.reset();
|
|
65
|
+
};
|
|
66
|
+
Object.defineProperty(WebpackDevServerProgress, "observedAttributes", {
|
|
67
|
+
get: function () {
|
|
68
|
+
return ['progress', 'type'];
|
|
69
|
+
},
|
|
70
|
+
enumerable: false,
|
|
71
|
+
configurable: true
|
|
72
|
+
});
|
|
73
|
+
WebpackDevServerProgress.prototype.attributeChangedCallback = function (name, oldValue, newValue) {
|
|
74
|
+
if (name === 'progress') {
|
|
75
|
+
this.update(Number(newValue));
|
|
76
|
+
}
|
|
77
|
+
else if (name === 'type') {
|
|
78
|
+
this.reset();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
WebpackDevServerProgress.prototype.update = function (percent) {
|
|
82
|
+
var shadowRoot = this.shadowRoot;
|
|
83
|
+
var element = shadowRoot.querySelector('#progress');
|
|
84
|
+
if (this.type === 'circular') {
|
|
85
|
+
var path = shadowRoot.querySelector('path');
|
|
86
|
+
var value = shadowRoot.querySelector('#percent-value');
|
|
87
|
+
var offset = ((100 - percent) / 100) * this.maxDashOffset;
|
|
88
|
+
path.style.strokeDashoffset = String(offset);
|
|
89
|
+
value.textContent = String(percent);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
element.style.width = "".concat(percent, "%");
|
|
93
|
+
}
|
|
94
|
+
if (percent >= 100) {
|
|
95
|
+
this.hide();
|
|
96
|
+
}
|
|
97
|
+
else if (percent > 0) {
|
|
98
|
+
this.show();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
WebpackDevServerProgress.prototype.show = function () {
|
|
102
|
+
var shadowRoot = this.shadowRoot;
|
|
103
|
+
var element = shadowRoot.querySelector('#progress');
|
|
104
|
+
element.classList.remove('hidden');
|
|
105
|
+
};
|
|
106
|
+
WebpackDevServerProgress.prototype.hide = function () {
|
|
107
|
+
var _this = this;
|
|
108
|
+
var shadowRoot = this.shadowRoot;
|
|
109
|
+
var element = shadowRoot.querySelector('#progress');
|
|
110
|
+
if (this.type === 'circular') {
|
|
111
|
+
element.classList.add('disappear');
|
|
112
|
+
element.addEventListener('animationend', function () {
|
|
113
|
+
element.classList.add('hidden');
|
|
114
|
+
_this.update(0);
|
|
115
|
+
}, { once: true });
|
|
116
|
+
}
|
|
117
|
+
else if (this.type === 'linear') {
|
|
118
|
+
element.classList.add('disappear');
|
|
119
|
+
this.animationTimer = setTimeout(function () {
|
|
120
|
+
element.classList.remove('disappear');
|
|
121
|
+
element.classList.add('hidden');
|
|
122
|
+
element.style.width = '0%';
|
|
123
|
+
_this.animationTimer = undefined;
|
|
124
|
+
}, 800);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return WebpackDevServerProgress;
|
|
128
|
+
}(HTMLElement));
|
|
129
|
+
customElements.define('wds-progress', WebpackDevServerProgress);
|
|
130
|
+
}
|