@rspack/dev-server 2.0.2 → 2.0.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/client/clients/WebSocketClient.d.ts +17 -0
- package/client/clients/WebSocketClient.js +32 -0
- package/client/index.d.ts +17 -0
- package/client/index.js +356 -0
- package/client/modules/logger/Logger.d.ts +39 -0
- package/client/modules/logger/Logger.js +121 -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 +26 -0
- package/client/modules/logger/index.js +32 -0
- package/client/modules/types.d.ts +45 -0
- package/client/modules/types.js +17 -0
- package/client/overlay.d.ts +47 -0
- package/client/overlay.js +454 -0
- package/client/progress.d.ts +11 -0
- package/client/progress.js +197 -0
- package/client/socket.d.ts +15 -0
- package/client/socket.js +34 -0
- package/client/type.d.ts +15 -0
- package/client/type.js +1 -0
- package/client/utils/ansiHTML.d.ts +30 -0
- package/client/utils/ansiHTML.js +195 -0
- package/client/utils/log.d.ts +13 -0
- package/client/utils/log.js +11 -0
- package/client/utils/sendMessage.d.ts +11 -0
- package/client/utils/sendMessage.js +8 -0
- package/dist/0~chokidar.js +1477 -0
- package/dist/0~chokidar.js.LICENSE.txt +1 -0
- package/dist/0~connect-history-api-fallback.js +76 -0
- package/dist/0~connect-next.js +1245 -0
- package/dist/0~connect-next.js.LICENSE.txt +57 -0
- package/dist/0~debug.js +621 -0
- package/dist/0~http-proxy-middleware.js +3817 -0
- package/dist/0~http-proxy-middleware.js.LICENSE.txt +34 -0
- package/dist/0~launch-editor.js +601 -0
- package/dist/0~open.js +555 -0
- package/dist/0~p-retry.js +161 -0
- package/dist/0~serve-static.js +1595 -0
- package/dist/0~serve-static.js.LICENSE.txt +108 -0
- package/dist/465.js +5192 -0
- package/dist/index.d.ts +1008 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import ansiHTML from "./utils/ansiHTML.js";
|
|
2
|
+
function _define_property(obj, key, value) {
|
|
3
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
else obj[key] = value;
|
|
10
|
+
return obj;
|
|
11
|
+
}
|
|
12
|
+
function _object_spread(target) {
|
|
13
|
+
for(var i = 1; i < arguments.length; i++){
|
|
14
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
15
|
+
var ownKeys = Object.keys(source);
|
|
16
|
+
if ("function" == typeof Object.getOwnPropertySymbols) ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
17
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
18
|
+
}));
|
|
19
|
+
ownKeys.forEach(function(key) {
|
|
20
|
+
_define_property(target, key, source[key]);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return target;
|
|
24
|
+
}
|
|
25
|
+
function overlay_ownKeys(object, enumerableOnly) {
|
|
26
|
+
var keys = Object.keys(object);
|
|
27
|
+
if (Object.getOwnPropertySymbols) {
|
|
28
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
29
|
+
if (enumerableOnly) symbols = symbols.filter(function(sym) {
|
|
30
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
31
|
+
});
|
|
32
|
+
keys.push.apply(keys, symbols);
|
|
33
|
+
}
|
|
34
|
+
return keys;
|
|
35
|
+
}
|
|
36
|
+
function _object_spread_props(target, source) {
|
|
37
|
+
source = null != source ? source : {};
|
|
38
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
39
|
+
else overlay_ownKeys(Object(source)).forEach(function(key) {
|
|
40
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
41
|
+
});
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
const getCodePoint = String.prototype.codePointAt ? (input, position)=>input.codePointAt(position) : (input, position)=>(input.charCodeAt(position) - 0xd800) * 0x400 + input.charCodeAt(position + 1) - 0xdc00 + 0x10000;
|
|
45
|
+
const replaceUsingRegExp = (macroText, macroRegExp, macroReplacer)=>{
|
|
46
|
+
macroRegExp.lastIndex = 0;
|
|
47
|
+
let replaceMatch = macroRegExp.exec(macroText);
|
|
48
|
+
let replaceResult;
|
|
49
|
+
if (replaceMatch) {
|
|
50
|
+
replaceResult = '';
|
|
51
|
+
let replaceLastIndex = 0;
|
|
52
|
+
do {
|
|
53
|
+
if (replaceLastIndex !== replaceMatch.index) replaceResult += macroText.slice(replaceLastIndex, replaceMatch.index);
|
|
54
|
+
const replaceInput = replaceMatch[0];
|
|
55
|
+
replaceResult += macroReplacer(replaceInput);
|
|
56
|
+
replaceLastIndex = replaceMatch.index + replaceInput.length;
|
|
57
|
+
}while (replaceMatch = macroRegExp.exec(macroText));
|
|
58
|
+
if (replaceLastIndex !== macroText.length) replaceResult += macroText.slice(replaceLastIndex);
|
|
59
|
+
} else replaceResult = macroText;
|
|
60
|
+
return replaceResult;
|
|
61
|
+
};
|
|
62
|
+
const references = {
|
|
63
|
+
'<': '<',
|
|
64
|
+
'>': '>',
|
|
65
|
+
'"': '"',
|
|
66
|
+
"'": ''',
|
|
67
|
+
'&': '&'
|
|
68
|
+
};
|
|
69
|
+
function encode(text) {
|
|
70
|
+
if (!text) return '';
|
|
71
|
+
return replaceUsingRegExp(text, /[<>'"&]/g, (input)=>{
|
|
72
|
+
let result = references[input];
|
|
73
|
+
if (!result) {
|
|
74
|
+
const code = input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0);
|
|
75
|
+
result = `&#${code};`;
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function createMachine({ states, context, initial }, { actions }) {
|
|
81
|
+
let currentState = initial;
|
|
82
|
+
let currentContext = context;
|
|
83
|
+
return {
|
|
84
|
+
send: (event)=>{
|
|
85
|
+
const currentStateOn = states[currentState].on;
|
|
86
|
+
const transitionConfig = currentStateOn && currentStateOn[event.type];
|
|
87
|
+
if (transitionConfig) {
|
|
88
|
+
currentState = transitionConfig.target;
|
|
89
|
+
if (transitionConfig.actions) transitionConfig.actions.forEach((actName)=>{
|
|
90
|
+
const actionImpl = actions[actName];
|
|
91
|
+
const nextContextValue = actionImpl && actionImpl(currentContext, event);
|
|
92
|
+
if (nextContextValue) currentContext = _object_spread({}, currentContext, nextContextValue);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const createOverlayMachine = (options)=>{
|
|
99
|
+
const { hideOverlay, showOverlay } = options;
|
|
100
|
+
return createMachine({
|
|
101
|
+
initial: 'hidden',
|
|
102
|
+
context: {
|
|
103
|
+
level: 'error',
|
|
104
|
+
messages: [],
|
|
105
|
+
messageSource: 'build'
|
|
106
|
+
},
|
|
107
|
+
states: {
|
|
108
|
+
hidden: {
|
|
109
|
+
on: {
|
|
110
|
+
BUILD_ERROR: {
|
|
111
|
+
target: 'displayBuildError',
|
|
112
|
+
actions: [
|
|
113
|
+
'setMessages',
|
|
114
|
+
'showOverlay'
|
|
115
|
+
]
|
|
116
|
+
},
|
|
117
|
+
RUNTIME_ERROR: {
|
|
118
|
+
target: 'displayRuntimeError',
|
|
119
|
+
actions: [
|
|
120
|
+
'setMessages',
|
|
121
|
+
'showOverlay'
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
displayBuildError: {
|
|
127
|
+
on: {
|
|
128
|
+
DISMISS: {
|
|
129
|
+
target: 'hidden',
|
|
130
|
+
actions: [
|
|
131
|
+
'dismissMessages',
|
|
132
|
+
'hideOverlay'
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
BUILD_ERROR: {
|
|
136
|
+
target: 'displayBuildError',
|
|
137
|
+
actions: [
|
|
138
|
+
'appendMessages',
|
|
139
|
+
'showOverlay'
|
|
140
|
+
]
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
displayRuntimeError: {
|
|
145
|
+
on: {
|
|
146
|
+
DISMISS: {
|
|
147
|
+
target: 'hidden',
|
|
148
|
+
actions: [
|
|
149
|
+
'dismissMessages',
|
|
150
|
+
'hideOverlay'
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
RUNTIME_ERROR: {
|
|
154
|
+
target: 'displayRuntimeError',
|
|
155
|
+
actions: [
|
|
156
|
+
'appendMessages',
|
|
157
|
+
'showOverlay'
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
BUILD_ERROR: {
|
|
161
|
+
target: 'displayBuildError',
|
|
162
|
+
actions: [
|
|
163
|
+
'setMessages',
|
|
164
|
+
'showOverlay'
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}, {
|
|
171
|
+
actions: {
|
|
172
|
+
dismissMessages: ()=>({
|
|
173
|
+
messages: [],
|
|
174
|
+
level: 'error',
|
|
175
|
+
messageSource: 'build'
|
|
176
|
+
}),
|
|
177
|
+
appendMessages: (context, event)=>({
|
|
178
|
+
messages: context.messages.concat(event.messages),
|
|
179
|
+
level: event.level || context.level,
|
|
180
|
+
messageSource: 'RUNTIME_ERROR' === event.type ? 'runtime' : 'build'
|
|
181
|
+
}),
|
|
182
|
+
setMessages: (context, event)=>({
|
|
183
|
+
messages: event.messages,
|
|
184
|
+
level: event.level || context.level,
|
|
185
|
+
messageSource: 'RUNTIME_ERROR' === event.type ? 'runtime' : 'build'
|
|
186
|
+
}),
|
|
187
|
+
hideOverlay,
|
|
188
|
+
showOverlay
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
const parseErrorToStacks = (error)=>{
|
|
193
|
+
if (!error || !(error instanceof Error)) throw new Error('parseErrorToStacks expects Error object');
|
|
194
|
+
if ('string' == typeof error.stack) return error.stack.split('\n').filter((stack)=>stack !== `Error: ${error.message}`);
|
|
195
|
+
};
|
|
196
|
+
const listenToRuntimeError = (callback)=>{
|
|
197
|
+
window.addEventListener('error', callback);
|
|
198
|
+
return function() {
|
|
199
|
+
window.removeEventListener('error', callback);
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
const listenToUnhandledRejection = (callback)=>{
|
|
203
|
+
window.addEventListener('unhandledrejection', callback);
|
|
204
|
+
return function() {
|
|
205
|
+
window.removeEventListener('unhandledrejection', callback);
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
const msgStyles = {
|
|
209
|
+
error: {
|
|
210
|
+
backgroundColor: 'rgba(206, 17, 38, 0.1)',
|
|
211
|
+
color: '#fccfcf'
|
|
212
|
+
},
|
|
213
|
+
warning: {
|
|
214
|
+
backgroundColor: 'rgba(251, 245, 180, 0.1)',
|
|
215
|
+
color: '#fbf5b4'
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const iframeStyle = {
|
|
219
|
+
position: 'fixed',
|
|
220
|
+
top: '0px',
|
|
221
|
+
left: '0px',
|
|
222
|
+
right: '0px',
|
|
223
|
+
bottom: '0px',
|
|
224
|
+
width: '100vw',
|
|
225
|
+
height: '100vh',
|
|
226
|
+
border: 'none',
|
|
227
|
+
'z-index': 9999999999
|
|
228
|
+
};
|
|
229
|
+
const containerStyle = {
|
|
230
|
+
position: 'fixed',
|
|
231
|
+
boxSizing: 'border-box',
|
|
232
|
+
left: '0px',
|
|
233
|
+
top: '0px',
|
|
234
|
+
right: '0px',
|
|
235
|
+
bottom: '0px',
|
|
236
|
+
width: '100vw',
|
|
237
|
+
height: '100vh',
|
|
238
|
+
fontSize: 'large',
|
|
239
|
+
padding: '2rem 2rem 4rem 2rem',
|
|
240
|
+
lineHeight: '1.2',
|
|
241
|
+
whiteSpace: 'pre-wrap',
|
|
242
|
+
overflow: 'auto',
|
|
243
|
+
backgroundColor: 'rgba(0, 0, 0, 0.9)',
|
|
244
|
+
color: 'white'
|
|
245
|
+
};
|
|
246
|
+
const headerStyle = {
|
|
247
|
+
color: '#e83b46',
|
|
248
|
+
fontSize: '2em',
|
|
249
|
+
whiteSpace: 'pre-wrap',
|
|
250
|
+
fontFamily: 'sans-serif',
|
|
251
|
+
margin: '0 2rem 2rem 0',
|
|
252
|
+
flex: '0 0 auto',
|
|
253
|
+
maxHeight: '50%',
|
|
254
|
+
overflow: 'auto'
|
|
255
|
+
};
|
|
256
|
+
const dismissButtonStyle = {
|
|
257
|
+
color: '#ffffff',
|
|
258
|
+
lineHeight: '1rem',
|
|
259
|
+
fontSize: '1.5rem',
|
|
260
|
+
padding: '1rem',
|
|
261
|
+
cursor: 'pointer',
|
|
262
|
+
position: 'absolute',
|
|
263
|
+
right: '0px',
|
|
264
|
+
top: '0px',
|
|
265
|
+
backgroundColor: 'transparent',
|
|
266
|
+
border: 'none'
|
|
267
|
+
};
|
|
268
|
+
const msgTypeStyle = {
|
|
269
|
+
color: '#e83b46',
|
|
270
|
+
fontSize: '1.2em',
|
|
271
|
+
marginBottom: '1rem',
|
|
272
|
+
fontFamily: 'sans-serif'
|
|
273
|
+
};
|
|
274
|
+
const msgTextStyle = {
|
|
275
|
+
lineHeight: '1.5',
|
|
276
|
+
fontSize: '1rem',
|
|
277
|
+
fontFamily: 'Menlo, Consolas, monospace'
|
|
278
|
+
};
|
|
279
|
+
const colors = {
|
|
280
|
+
reset: [
|
|
281
|
+
'transparent',
|
|
282
|
+
'transparent'
|
|
283
|
+
],
|
|
284
|
+
black: '181818',
|
|
285
|
+
red: 'E36049',
|
|
286
|
+
green: 'B3CB74',
|
|
287
|
+
yellow: 'FFD080',
|
|
288
|
+
blue: '7CAFC2',
|
|
289
|
+
magenta: '7FACCA',
|
|
290
|
+
cyan: 'C3C2EF',
|
|
291
|
+
lightgrey: 'EBE7E3',
|
|
292
|
+
darkgrey: '6D7891'
|
|
293
|
+
};
|
|
294
|
+
ansiHTML.setColors(colors);
|
|
295
|
+
const formatProblem = (type, item)=>{
|
|
296
|
+
let header = 'warning' === type ? 'WARNING' : 'ERROR';
|
|
297
|
+
let body = '';
|
|
298
|
+
if ('string' == typeof item) body += item;
|
|
299
|
+
else {
|
|
300
|
+
const file = item.file || '';
|
|
301
|
+
const moduleName = item.moduleName ? -1 !== item.moduleName.indexOf('!') ? `${item.moduleName.replace(/^(\s|\S)*!/, '')} (${item.moduleName})` : `${item.moduleName}` : '';
|
|
302
|
+
const loc = item.loc;
|
|
303
|
+
header += `${moduleName || file ? ` in ${moduleName ? `${moduleName}${file ? ` (${file})` : ''}` : file}${loc ? ` ${loc}` : ''}` : ''}`;
|
|
304
|
+
body += item.message || '';
|
|
305
|
+
}
|
|
306
|
+
if ('string' != typeof item && Array.isArray(item.stack)) item.stack.forEach((stack)=>{
|
|
307
|
+
if ('string' == typeof stack) body += `\r\n${stack}`;
|
|
308
|
+
});
|
|
309
|
+
return {
|
|
310
|
+
header,
|
|
311
|
+
body
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
const createOverlay = (options)=>{
|
|
315
|
+
let iframeContainerElement;
|
|
316
|
+
let containerElement;
|
|
317
|
+
let headerElement;
|
|
318
|
+
let onLoadQueue = [];
|
|
319
|
+
let overlayTrustedTypesPolicy;
|
|
320
|
+
function applyStyle(element, style) {
|
|
321
|
+
Object.keys(style).forEach((prop)=>{
|
|
322
|
+
element.style[prop] = style[prop];
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
function createContainer(trustedTypesPolicyName) {
|
|
326
|
+
if (window.trustedTypes) overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || 'rspack-dev-server#overlay', {
|
|
327
|
+
createHTML: (value)=>value
|
|
328
|
+
});
|
|
329
|
+
iframeContainerElement = document.createElement('iframe');
|
|
330
|
+
iframeContainerElement.id = 'rspack-dev-server-client-overlay';
|
|
331
|
+
iframeContainerElement.src = 'about:blank';
|
|
332
|
+
applyStyle(iframeContainerElement, iframeStyle);
|
|
333
|
+
iframeContainerElement.onload = ()=>{
|
|
334
|
+
const contentElement = (null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
335
|
+
containerElement = (null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).createElement('div');
|
|
336
|
+
contentElement.id = 'rspack-dev-server-client-overlay-div';
|
|
337
|
+
applyStyle(contentElement, containerStyle);
|
|
338
|
+
headerElement = document.createElement('div');
|
|
339
|
+
headerElement.innerText = 'Compiled with problems:';
|
|
340
|
+
applyStyle(headerElement, headerStyle);
|
|
341
|
+
const closeButtonElement = document.createElement('button');
|
|
342
|
+
applyStyle(closeButtonElement, dismissButtonStyle);
|
|
343
|
+
closeButtonElement.innerText = '×';
|
|
344
|
+
closeButtonElement.ariaLabel = 'Dismiss';
|
|
345
|
+
closeButtonElement.addEventListener('click', ()=>{
|
|
346
|
+
overlayService.send({
|
|
347
|
+
type: 'DISMISS'
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
contentElement.appendChild(headerElement);
|
|
351
|
+
contentElement.appendChild(closeButtonElement);
|
|
352
|
+
contentElement.appendChild(containerElement);
|
|
353
|
+
(null == iframeContainerElement ? void 0 : iframeContainerElement.contentDocument).body.appendChild(contentElement);
|
|
354
|
+
onLoadQueue.forEach((onLoad)=>{
|
|
355
|
+
onLoad(contentElement);
|
|
356
|
+
});
|
|
357
|
+
onLoadQueue = [];
|
|
358
|
+
iframeContainerElement.onload = null;
|
|
359
|
+
};
|
|
360
|
+
document.body.appendChild(iframeContainerElement);
|
|
361
|
+
}
|
|
362
|
+
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
363
|
+
if (containerElement) {
|
|
364
|
+
containerElement.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML('') : '';
|
|
365
|
+
callback(containerElement);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
onLoadQueue.push(callback);
|
|
369
|
+
if (iframeContainerElement) return;
|
|
370
|
+
createContainer(trustedTypesPolicyName);
|
|
371
|
+
}
|
|
372
|
+
function hide() {
|
|
373
|
+
if (!iframeContainerElement) return;
|
|
374
|
+
document.body.removeChild(iframeContainerElement);
|
|
375
|
+
iframeContainerElement = null;
|
|
376
|
+
containerElement = null;
|
|
377
|
+
}
|
|
378
|
+
function show(type, messages, trustedTypesPolicyName, messageSource) {
|
|
379
|
+
ensureOverlayExists(()=>{
|
|
380
|
+
headerElement.innerText = 'runtime' === messageSource ? 'Uncaught runtime errors:' : 'Compiled with problems:';
|
|
381
|
+
messages.forEach((message)=>{
|
|
382
|
+
const entryElement = document.createElement('div');
|
|
383
|
+
const msgStyle = 'warning' === type ? msgStyles.warning : msgStyles.error;
|
|
384
|
+
applyStyle(entryElement, _object_spread_props(_object_spread({}, msgStyle), {
|
|
385
|
+
padding: '1rem 1rem 1.5rem 1rem'
|
|
386
|
+
}));
|
|
387
|
+
const typeElement = document.createElement('div');
|
|
388
|
+
const { header, body } = formatProblem(type, message);
|
|
389
|
+
typeElement.innerText = header;
|
|
390
|
+
applyStyle(typeElement, msgTypeStyle);
|
|
391
|
+
if ('string' != typeof message && message.moduleIdentifier) {
|
|
392
|
+
applyStyle(typeElement, {
|
|
393
|
+
cursor: 'pointer'
|
|
394
|
+
});
|
|
395
|
+
typeElement.setAttribute('data-can-open', 'true');
|
|
396
|
+
typeElement.addEventListener('click', ()=>{
|
|
397
|
+
fetch(`/rspack-dev-server/open-editor?fileName=${message.moduleIdentifier}`);
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
const text = ansiHTML(encode(body));
|
|
401
|
+
const messageTextNode = document.createElement('div');
|
|
402
|
+
applyStyle(messageTextNode, msgTextStyle);
|
|
403
|
+
messageTextNode.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML(text) : text;
|
|
404
|
+
entryElement.appendChild(typeElement);
|
|
405
|
+
entryElement.appendChild(messageTextNode);
|
|
406
|
+
null == containerElement || containerElement.appendChild(entryElement);
|
|
407
|
+
});
|
|
408
|
+
}, trustedTypesPolicyName);
|
|
409
|
+
}
|
|
410
|
+
let handleEscapeKey;
|
|
411
|
+
const hideOverlayWithEscCleanup = ()=>{
|
|
412
|
+
window.removeEventListener('keydown', handleEscapeKey);
|
|
413
|
+
hide();
|
|
414
|
+
};
|
|
415
|
+
const overlayService = createOverlayMachine({
|
|
416
|
+
showOverlay: ({ level = 'error', messages, messageSource })=>show(level, messages, options.trustedTypesPolicyName, messageSource),
|
|
417
|
+
hideOverlay: hideOverlayWithEscCleanup
|
|
418
|
+
});
|
|
419
|
+
handleEscapeKey = (event)=>{
|
|
420
|
+
if ('Escape' === event.key || 'Esc' === event.key || 27 === event.keyCode) overlayService.send({
|
|
421
|
+
type: 'DISMISS'
|
|
422
|
+
});
|
|
423
|
+
};
|
|
424
|
+
window.addEventListener('keydown', handleEscapeKey);
|
|
425
|
+
if (options.catchRuntimeError) {
|
|
426
|
+
const handleError = (error, fallbackMessage)=>{
|
|
427
|
+
const errorObject = error instanceof Error ? error : new Error(error || fallbackMessage, {
|
|
428
|
+
cause: error
|
|
429
|
+
});
|
|
430
|
+
const shouldDisplay = 'function' == typeof options.catchRuntimeError ? options.catchRuntimeError(errorObject) : true;
|
|
431
|
+
if (shouldDisplay) overlayService.send({
|
|
432
|
+
type: 'RUNTIME_ERROR',
|
|
433
|
+
messages: [
|
|
434
|
+
{
|
|
435
|
+
message: errorObject.message,
|
|
436
|
+
stack: parseErrorToStacks(errorObject)
|
|
437
|
+
}
|
|
438
|
+
]
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
listenToRuntimeError((errorEvent)=>{
|
|
442
|
+
const { error, message } = errorEvent;
|
|
443
|
+
if (!error && !message) return;
|
|
444
|
+
if (error && error.stack && error.stack.includes('invokeGuardedCallbackDev')) return;
|
|
445
|
+
handleError(error, message);
|
|
446
|
+
});
|
|
447
|
+
listenToUnhandledRejection((promiseRejectionEvent)=>{
|
|
448
|
+
const { reason } = promiseRejectionEvent;
|
|
449
|
+
handleError(reason, 'Unknown promise rejection reason');
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
return overlayService;
|
|
453
|
+
};
|
|
454
|
+
export { createOverlay, formatProblem };
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
export declare function isProgressSupported(): boolean;
|
|
11
|
+
export declare function defineProgressElement(): void;
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
3
|
+
value: value,
|
|
4
|
+
enumerable: true,
|
|
5
|
+
configurable: true,
|
|
6
|
+
writable: true
|
|
7
|
+
});
|
|
8
|
+
else obj[key] = value;
|
|
9
|
+
return obj;
|
|
10
|
+
}
|
|
11
|
+
function isProgressSupported() {
|
|
12
|
+
return 'customElements' in self && Boolean(HTMLElement.prototype.attachShadow);
|
|
13
|
+
}
|
|
14
|
+
function defineProgressElement() {
|
|
15
|
+
if (customElements.get('wds-progress')) return;
|
|
16
|
+
class WebpackDevServerProgress extends HTMLElement {
|
|
17
|
+
reset() {
|
|
18
|
+
var _this_getAttribute;
|
|
19
|
+
clearTimeout(this.animationTimer);
|
|
20
|
+
this.animationTimer = void 0;
|
|
21
|
+
const typeAttr = null == (_this_getAttribute = this.getAttribute('type')) ? void 0 : _this_getAttribute.toLowerCase();
|
|
22
|
+
this.type = 'circular' === typeAttr ? 'circular' : 'linear';
|
|
23
|
+
const innerHTML = 'circular' === this.type ? WebpackDevServerProgress.circularTemplate() : WebpackDevServerProgress.linearTemplate();
|
|
24
|
+
this.shadowRoot.innerHTML = innerHTML;
|
|
25
|
+
const progressValue = this.getAttribute('progress');
|
|
26
|
+
this.initialProgress = progressValue ? Number(progressValue) : 0;
|
|
27
|
+
this.update(this.initialProgress);
|
|
28
|
+
}
|
|
29
|
+
static circularTemplate() {
|
|
30
|
+
return `
|
|
31
|
+
<style>
|
|
32
|
+
:host {
|
|
33
|
+
width: 200px;
|
|
34
|
+
height: 200px;
|
|
35
|
+
position: fixed;
|
|
36
|
+
right: 5%;
|
|
37
|
+
top: 5%;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
transition: opacity .25s ease-in-out;
|
|
40
|
+
z-index: 2147483645;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
circle {
|
|
44
|
+
fill: #282d35;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
path {
|
|
48
|
+
fill: rgba(0, 0, 0, 0);
|
|
49
|
+
stroke: rgb(186, 223, 172);
|
|
50
|
+
stroke-dasharray: 219.99078369140625;
|
|
51
|
+
stroke-dashoffset: -219.99078369140625;
|
|
52
|
+
stroke-width: 10;
|
|
53
|
+
transform: rotate(90deg) translate(0px, -80px);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
text {
|
|
57
|
+
font-family: 'Open Sans', sans-serif;
|
|
58
|
+
font-size: 18px;
|
|
59
|
+
fill: #ffffff;
|
|
60
|
+
dominant-baseline: middle;
|
|
61
|
+
text-anchor: middle;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
tspan#percent-super {
|
|
65
|
+
fill: #bdc3c7;
|
|
66
|
+
font-size: 0.45em;
|
|
67
|
+
baseline-shift: 10%;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@keyframes fade {
|
|
71
|
+
0% { opacity: 1; transform: scale(1); }
|
|
72
|
+
100% { opacity: 0; transform: scale(0); }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.disappear {
|
|
76
|
+
animation: fade 0.3s;
|
|
77
|
+
animation-fill-mode: forwards;
|
|
78
|
+
animation-delay: 0.5s;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.hidden {
|
|
82
|
+
display: none;
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
85
|
+
<svg id="progress" class="hidden noselect" viewBox="0 0 80 80">
|
|
86
|
+
<circle cx="50%" cy="50%" r="35"></circle>
|
|
87
|
+
<path d="M5,40a35,35 0 1,0 70,0a35,35 0 1,0 -70,0"></path>
|
|
88
|
+
<text x="50%" y="51%">
|
|
89
|
+
<tspan id="percent-value">0</tspan>
|
|
90
|
+
<tspan id="percent-super">%</tspan>
|
|
91
|
+
</text>
|
|
92
|
+
</svg>
|
|
93
|
+
`;
|
|
94
|
+
}
|
|
95
|
+
static linearTemplate() {
|
|
96
|
+
return `
|
|
97
|
+
<style>
|
|
98
|
+
:host {
|
|
99
|
+
position: fixed;
|
|
100
|
+
top: 0;
|
|
101
|
+
left: 0;
|
|
102
|
+
pointer-events: none;
|
|
103
|
+
height: 4px;
|
|
104
|
+
width: 100vw;
|
|
105
|
+
z-index: 2147483645;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#bar {
|
|
109
|
+
width: 0%;
|
|
110
|
+
height: 4px;
|
|
111
|
+
background-color: rgb(186, 223, 172);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@keyframes fade {
|
|
115
|
+
0% { opacity: 1; }
|
|
116
|
+
100% { opacity: 0; }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.disappear {
|
|
120
|
+
animation: fade 0.3s;
|
|
121
|
+
animation-fill-mode: forwards;
|
|
122
|
+
animation-delay: 0.5s;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.hidden {
|
|
126
|
+
display: none;
|
|
127
|
+
}
|
|
128
|
+
</style>
|
|
129
|
+
<div id="progress"></div>
|
|
130
|
+
`;
|
|
131
|
+
}
|
|
132
|
+
connectedCallback() {
|
|
133
|
+
this.reset();
|
|
134
|
+
}
|
|
135
|
+
static get observedAttributes() {
|
|
136
|
+
return [
|
|
137
|
+
'progress',
|
|
138
|
+
'type'
|
|
139
|
+
];
|
|
140
|
+
}
|
|
141
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
142
|
+
if ('progress' === name) this.update(Number(newValue));
|
|
143
|
+
else if ('type' === name) this.reset();
|
|
144
|
+
}
|
|
145
|
+
update(percent) {
|
|
146
|
+
const shadowRoot = this.shadowRoot;
|
|
147
|
+
const element = shadowRoot.querySelector('#progress');
|
|
148
|
+
if ('circular' === this.type) {
|
|
149
|
+
const path = shadowRoot.querySelector('path');
|
|
150
|
+
const value = shadowRoot.querySelector('#percent-value');
|
|
151
|
+
const offset = (100 - percent) / 100 * this.maxDashOffset;
|
|
152
|
+
path.style.strokeDashoffset = String(offset);
|
|
153
|
+
value.textContent = String(percent);
|
|
154
|
+
} else element.style.width = `${percent}%`;
|
|
155
|
+
if (percent >= 100) this.hide();
|
|
156
|
+
else if (percent > 0) this.show();
|
|
157
|
+
}
|
|
158
|
+
show() {
|
|
159
|
+
const shadowRoot = this.shadowRoot;
|
|
160
|
+
const element = shadowRoot.querySelector('#progress');
|
|
161
|
+
element.classList.remove('hidden');
|
|
162
|
+
}
|
|
163
|
+
hide() {
|
|
164
|
+
const shadowRoot = this.shadowRoot;
|
|
165
|
+
const element = shadowRoot.querySelector('#progress');
|
|
166
|
+
if ('circular' === this.type) {
|
|
167
|
+
element.classList.add('disappear');
|
|
168
|
+
element.addEventListener('animationend', ()=>{
|
|
169
|
+
element.classList.add('hidden');
|
|
170
|
+
this.update(0);
|
|
171
|
+
}, {
|
|
172
|
+
once: true
|
|
173
|
+
});
|
|
174
|
+
} else if ('linear' === this.type) {
|
|
175
|
+
element.classList.add('disappear');
|
|
176
|
+
this.animationTimer = setTimeout(()=>{
|
|
177
|
+
element.classList.remove('disappear');
|
|
178
|
+
element.classList.add('hidden');
|
|
179
|
+
element.style.width = '0%';
|
|
180
|
+
this.animationTimer = void 0;
|
|
181
|
+
}, 800);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
constructor(){
|
|
185
|
+
super(), _define_property(this, "maxDashOffset", void 0), _define_property(this, "animationTimer", void 0), _define_property(this, "type", void 0), _define_property(this, "initialProgress", void 0);
|
|
186
|
+
this.attachShadow({
|
|
187
|
+
mode: 'open'
|
|
188
|
+
});
|
|
189
|
+
this.maxDashOffset = -219.99078369140625;
|
|
190
|
+
this.animationTimer = void 0;
|
|
191
|
+
this.type = 'circular';
|
|
192
|
+
this.initialProgress = 0;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
customElements.define('wds-progress', WebpackDevServerProgress);
|
|
196
|
+
}
|
|
197
|
+
export { defineProgressElement, isProgressSupported };
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
import type { CommunicationClient, EXPECTED_ANY } from './type.js';
|
|
11
|
+
export declare let client: CommunicationClient | null;
|
|
12
|
+
declare function socket(url: string, handlers: {
|
|
13
|
+
[handler: string]: (data?: EXPECTED_ANY, params?: EXPECTED_ANY) => EXPECTED_ANY;
|
|
14
|
+
}, reconnect?: number): void;
|
|
15
|
+
export default socket;
|