webpack-dev-server 5.2.2 → 5.2.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 -4
- package/bin/webpack-dev-server.js +17 -16
- package/client/clients/SockJSClient.js +18 -20
- package/client/clients/WebSocketClient.js +17 -11
- package/client/index.js +111 -72
- package/client/modules/logger/index.js +42 -35
- package/client/modules/sockjs-client/index.js +0 -1
- package/client/overlay.js +129 -79
- package/client/progress.js +40 -13
- package/client/socket.js +17 -13
- package/client/utils/log.js +1 -1
- package/client/utils/sendMessage.js +5 -3
- package/lib/Server.js +336 -317
- package/lib/getPort.js +21 -22
- package/lib/servers/BaseServer.js +1 -1
- package/lib/servers/SockJSServer.js +16 -14
- package/lib/servers/WebsocketServer.js +17 -22
- package/package.json +36 -31
- package/types/bin/webpack-dev-server.d.ts +1 -1
- package/types/lib/Server.d.ts +216 -149
- package/types/lib/getPort.d.ts +3 -3
- package/types/lib/servers/BaseServer.d.ts +1 -1
package/client/overlay.js
CHANGED
|
@@ -9,20 +9,25 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
9
9
|
|
|
10
10
|
import ansiHTML from "ansi-html-community";
|
|
11
11
|
|
|
12
|
+
/** @typedef {import("./index").EXPECTED_ANY} EXPECTED_ANY */
|
|
13
|
+
|
|
12
14
|
/**
|
|
13
|
-
* @type {(input: string, position: number) =>
|
|
15
|
+
* @type {(input: string, position: number) => number | undefined}
|
|
14
16
|
*/
|
|
15
|
-
|
|
17
|
+
// @ts-expect-error
|
|
18
|
+
var getCodePoint = String.prototype.codePointAt ?
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
function (input, position) {
|
|
16
21
|
return input.codePointAt(position);
|
|
17
22
|
} : function (input, position) {
|
|
18
23
|
return (input.charCodeAt(position) - 0xd800) * 0x400 + input.charCodeAt(position + 1) - 0xdc00 + 0x10000;
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
|
-
* @param {string} macroText
|
|
23
|
-
* @param {RegExp} macroRegExp
|
|
24
|
-
* @param {(input: string) => string} macroReplacer
|
|
25
|
-
* @returns {string}
|
|
27
|
+
* @param {string} macroText macro text
|
|
28
|
+
* @param {RegExp} macroRegExp macro reg exp
|
|
29
|
+
* @param {(input: string) => string} macroReplacer macro replacer
|
|
30
|
+
* @returns {string} result
|
|
26
31
|
*/
|
|
27
32
|
var replaceUsingRegExp = function replaceUsingRegExp(macroText, macroRegExp, macroReplacer) {
|
|
28
33
|
macroRegExp.lastIndex = 0;
|
|
@@ -33,15 +38,14 @@ var replaceUsingRegExp = function replaceUsingRegExp(macroText, macroRegExp, mac
|
|
|
33
38
|
var replaceLastIndex = 0;
|
|
34
39
|
do {
|
|
35
40
|
if (replaceLastIndex !== replaceMatch.index) {
|
|
36
|
-
replaceResult += macroText.
|
|
41
|
+
replaceResult += macroText.slice(replaceLastIndex, replaceMatch.index);
|
|
37
42
|
}
|
|
38
43
|
var replaceInput = replaceMatch[0];
|
|
39
44
|
replaceResult += macroReplacer(replaceInput);
|
|
40
45
|
replaceLastIndex = replaceMatch.index + replaceInput.length;
|
|
41
|
-
// eslint-disable-next-line no-cond-assign
|
|
42
46
|
} while (replaceMatch = macroRegExp.exec(macroText));
|
|
43
47
|
if (replaceLastIndex !== macroText.length) {
|
|
44
|
-
replaceResult += macroText.
|
|
48
|
+
replaceResult += macroText.slice(replaceLastIndex);
|
|
45
49
|
}
|
|
46
50
|
} else {
|
|
47
51
|
replaceResult = macroText;
|
|
@@ -58,14 +62,14 @@ var references = {
|
|
|
58
62
|
|
|
59
63
|
/**
|
|
60
64
|
* @param {string} text text
|
|
61
|
-
* @returns {string}
|
|
65
|
+
* @returns {string} encoded text
|
|
62
66
|
*/
|
|
63
67
|
function encode(text) {
|
|
64
68
|
if (!text) {
|
|
65
69
|
return "";
|
|
66
70
|
}
|
|
67
71
|
return replaceUsingRegExp(text, /[<>'"&]/g, function (input) {
|
|
68
|
-
var result = references[input];
|
|
72
|
+
var result = references[(/** @type {keyof typeof references} */input)];
|
|
69
73
|
if (!result) {
|
|
70
74
|
var code = input.length > 1 ? getCodePoint(input, 0) : input.charCodeAt(0);
|
|
71
75
|
result = "&#".concat(code, ";");
|
|
@@ -75,36 +79,43 @@ function encode(text) {
|
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
/**
|
|
78
|
-
* @typedef {
|
|
79
|
-
* @property {
|
|
82
|
+
* @typedef {object} Context
|
|
83
|
+
* @property {'warning' | 'error'} level level
|
|
84
|
+
* @property {(string | Message)[]} messages messages
|
|
85
|
+
* @property {'build' | 'runtime'} messageSource message source
|
|
80
86
|
*/
|
|
81
87
|
|
|
88
|
+
/** @typedef {{ type: string } & Record<string, EXPECTED_ANY>} Event */
|
|
89
|
+
|
|
82
90
|
/**
|
|
83
|
-
* @typedef {
|
|
84
|
-
* @property {{[state: string]:
|
|
85
|
-
* @property {
|
|
86
|
-
* @property {string} initial
|
|
91
|
+
* @typedef {object} Options
|
|
92
|
+
* @property {{ [state: string]: { on: Record<string, { target: string; actions?: Array<string> }> } }} states states
|
|
93
|
+
* @property {Context} context context
|
|
94
|
+
* @property {string} initial initial
|
|
87
95
|
*/
|
|
88
96
|
|
|
89
97
|
/**
|
|
90
|
-
* @typedef {
|
|
91
|
-
* @property {{[actionName: string]: (ctx:
|
|
98
|
+
* @typedef {object} Implementation
|
|
99
|
+
* @property {{ [actionName: string]: (ctx: Context, event: Event) => Context | void }} actions actions
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @typedef {{ send: (event: Event) => void }} StateMachine
|
|
92
104
|
*/
|
|
93
105
|
|
|
94
106
|
/**
|
|
95
107
|
* A simplified `createMachine` from `@xstate/fsm` with the following differences:
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* Do not return anything if you just want to invoke side effect.
|
|
108
|
+
* - the returned machine is technically a "service". No `interpret(machine).start()` is needed.
|
|
109
|
+
* - the state definition only support `on` and target must be declared with { target: 'nextState', actions: [] } explicitly.
|
|
110
|
+
* - event passed to `send` must be an object with `type` property.
|
|
111
|
+
* - actions implementation will be [assign action](https://xstate.js.org/docs/guides/context.html#assign-action) if you return any value.
|
|
112
|
+
* Do not return anything if you just want to invoke side effect.
|
|
102
113
|
*
|
|
103
114
|
* The goal of this custom function is to avoid installing the entire `'xstate/fsm'` package, while enabling modeling using
|
|
104
115
|
* state machine. You can copy the first parameter into the editor at https://stately.ai/viz to visualize the state machine.
|
|
105
|
-
*
|
|
106
|
-
* @param {
|
|
107
|
-
* @
|
|
116
|
+
* @param {Options} options options
|
|
117
|
+
* @param {Implementation} implementation implementation
|
|
118
|
+
* @returns {StateMachine} state machine
|
|
108
119
|
*/
|
|
109
120
|
function createMachine(_ref, _ref2) {
|
|
110
121
|
var states = _ref.states,
|
|
@@ -134,20 +145,21 @@ function createMachine(_ref, _ref2) {
|
|
|
134
145
|
}
|
|
135
146
|
|
|
136
147
|
/**
|
|
137
|
-
* @typedef {
|
|
138
|
-
* @property {'warning' | 'error'} level
|
|
139
|
-
* @property {
|
|
140
|
-
* @property {'build' | 'runtime'} messageSource
|
|
148
|
+
* @typedef {object} ShowOverlayData
|
|
149
|
+
* @property {'warning' | 'error'} level level
|
|
150
|
+
* @property {(string | Message)[]} messages messages
|
|
151
|
+
* @property {'build' | 'runtime'} messageSource message source
|
|
141
152
|
*/
|
|
142
153
|
|
|
143
154
|
/**
|
|
144
|
-
* @typedef {
|
|
145
|
-
* @property {(data: ShowOverlayData) => void} showOverlay
|
|
146
|
-
* @property {() => void} hideOverlay
|
|
155
|
+
* @typedef {object} CreateOverlayMachineOptions
|
|
156
|
+
* @property {(data: ShowOverlayData) => void} showOverlay show overlay
|
|
157
|
+
* @property {() => void} hideOverlay hide overlay
|
|
147
158
|
*/
|
|
148
159
|
|
|
149
160
|
/**
|
|
150
|
-
* @param {CreateOverlayMachineOptions} options
|
|
161
|
+
* @param {CreateOverlayMachineOptions} options options
|
|
162
|
+
* @returns {StateMachine} state machine
|
|
151
163
|
*/
|
|
152
164
|
var createOverlayMachine = function createOverlayMachine(options) {
|
|
153
165
|
var hideOverlay = options.hideOverlay,
|
|
@@ -231,8 +243,8 @@ var createOverlayMachine = function createOverlayMachine(options) {
|
|
|
231
243
|
};
|
|
232
244
|
|
|
233
245
|
/**
|
|
234
|
-
*
|
|
235
|
-
* @
|
|
246
|
+
* @param {Error} error error
|
|
247
|
+
* @returns {undefined | string[]} stack
|
|
236
248
|
*/
|
|
237
249
|
var parseErrorToStacks = function parseErrorToStacks(error) {
|
|
238
250
|
if (!error || !(error instanceof Error)) {
|
|
@@ -252,7 +264,8 @@ var parseErrorToStacks = function parseErrorToStacks(error) {
|
|
|
252
264
|
*/
|
|
253
265
|
|
|
254
266
|
/**
|
|
255
|
-
* @param {ErrorCallback} callback
|
|
267
|
+
* @param {ErrorCallback} callback callback
|
|
268
|
+
* @returns {() => void} cleanup
|
|
256
269
|
*/
|
|
257
270
|
var listenToRuntimeError = function listenToRuntimeError(callback) {
|
|
258
271
|
window.addEventListener("error", callback);
|
|
@@ -268,7 +281,8 @@ var listenToRuntimeError = function listenToRuntimeError(callback) {
|
|
|
268
281
|
*/
|
|
269
282
|
|
|
270
283
|
/**
|
|
271
|
-
* @param {UnhandledRejectionCallback} callback
|
|
284
|
+
* @param {UnhandledRejectionCallback} callback callback
|
|
285
|
+
* @returns {() => void} cleanup
|
|
272
286
|
*/
|
|
273
287
|
var listenToUnhandledRejection = function listenToUnhandledRejection(callback) {
|
|
274
288
|
window.addEventListener("unhandledrejection", callback);
|
|
@@ -291,10 +305,10 @@ var msgStyles = {
|
|
|
291
305
|
};
|
|
292
306
|
var iframeStyle = {
|
|
293
307
|
position: "fixed",
|
|
294
|
-
top:
|
|
295
|
-
left:
|
|
296
|
-
right:
|
|
297
|
-
bottom:
|
|
308
|
+
top: "0px",
|
|
309
|
+
left: "0px",
|
|
310
|
+
right: "0px",
|
|
311
|
+
bottom: "0px",
|
|
298
312
|
width: "100vw",
|
|
299
313
|
height: "100vh",
|
|
300
314
|
border: "none",
|
|
@@ -303,10 +317,10 @@ var iframeStyle = {
|
|
|
303
317
|
var containerStyle = {
|
|
304
318
|
position: "fixed",
|
|
305
319
|
boxSizing: "border-box",
|
|
306
|
-
left:
|
|
307
|
-
top:
|
|
308
|
-
right:
|
|
309
|
-
bottom:
|
|
320
|
+
left: "0px",
|
|
321
|
+
top: "0px",
|
|
322
|
+
right: "0px",
|
|
323
|
+
bottom: "0px",
|
|
310
324
|
width: "100vw",
|
|
311
325
|
height: "100vh",
|
|
312
326
|
fontSize: "large",
|
|
@@ -334,8 +348,8 @@ var dismissButtonStyle = {
|
|
|
334
348
|
padding: "1rem",
|
|
335
349
|
cursor: "pointer",
|
|
336
350
|
position: "absolute",
|
|
337
|
-
right:
|
|
338
|
-
top:
|
|
351
|
+
right: "0px",
|
|
352
|
+
top: "0px",
|
|
339
353
|
backgroundColor: "transparent",
|
|
340
354
|
border: "none"
|
|
341
355
|
};
|
|
@@ -367,10 +381,12 @@ var colors = {
|
|
|
367
381
|
};
|
|
368
382
|
ansiHTML.setColors(colors);
|
|
369
383
|
|
|
384
|
+
/** @typedef {Error & { file?: string, moduleName?: string, moduleIdentifier?: string, loc?: string, message?: string; stack?: string | string[] }} Message */
|
|
385
|
+
|
|
370
386
|
/**
|
|
371
|
-
* @param {string} type
|
|
372
|
-
* @param {string
|
|
373
|
-
* @returns {{ header: string, body: string }}
|
|
387
|
+
* @param {string} type type
|
|
388
|
+
* @param {string | Message} item item
|
|
389
|
+
* @returns {{ header: string, body: string }} formatted problem
|
|
374
390
|
*/
|
|
375
391
|
var formatProblem = function formatProblem(type, item) {
|
|
376
392
|
var header = type === "warning" ? "WARNING" : "ERROR";
|
|
@@ -379,13 +395,12 @@ var formatProblem = function formatProblem(type, item) {
|
|
|
379
395
|
body += item;
|
|
380
396
|
} else {
|
|
381
397
|
var file = item.file || "";
|
|
382
|
-
// eslint-disable-next-line no-nested-ternary
|
|
383
398
|
var moduleName = item.moduleName ? item.moduleName.indexOf("!") !== -1 ? "".concat(item.moduleName.replace(/^(\s|\S)*!/, ""), " (").concat(item.moduleName, ")") : "".concat(item.moduleName) : "";
|
|
384
399
|
var loc = item.loc;
|
|
385
400
|
header += "".concat(moduleName || file ? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : "") : file).concat(loc ? " ".concat(loc) : "") : "");
|
|
386
401
|
body += item.message || "";
|
|
387
402
|
}
|
|
388
|
-
if (Array.isArray(item.stack)) {
|
|
403
|
+
if (typeof item !== "string" && Array.isArray(item.stack)) {
|
|
389
404
|
item.stack.forEach(function (stack) {
|
|
390
405
|
if (typeof stack === "string") {
|
|
391
406
|
body += "\r\n".concat(stack);
|
|
@@ -399,14 +414,14 @@ var formatProblem = function formatProblem(type, item) {
|
|
|
399
414
|
};
|
|
400
415
|
|
|
401
416
|
/**
|
|
402
|
-
* @typedef {
|
|
403
|
-
* @property {
|
|
404
|
-
* @property {boolean | (error: Error) => void}
|
|
417
|
+
* @typedef {object} CreateOverlayOptions
|
|
418
|
+
* @property {(false | string)=} trustedTypesPolicyName trusted types policy name
|
|
419
|
+
* @property {(boolean | ((error: Error) => void))=} catchRuntimeError runtime error catcher
|
|
405
420
|
*/
|
|
406
421
|
|
|
407
422
|
/**
|
|
408
|
-
*
|
|
409
|
-
* @
|
|
423
|
+
* @param {CreateOverlayOptions} options options
|
|
424
|
+
* @returns {StateMachine} overlay
|
|
410
425
|
*/
|
|
411
426
|
var createOverlay = function createOverlay(options) {
|
|
412
427
|
/** @type {HTMLIFrameElement | null | undefined} */
|
|
@@ -417,22 +432,24 @@ var createOverlay = function createOverlay(options) {
|
|
|
417
432
|
var headerElement;
|
|
418
433
|
/** @type {Array<(element: HTMLDivElement) => void>} */
|
|
419
434
|
var onLoadQueue = [];
|
|
420
|
-
/** @type {TrustedTypePolicy | undefined} */
|
|
435
|
+
/** @type {Omit<TrustedTypePolicy, "createScript" | "createScriptURL"> | undefined} */
|
|
421
436
|
var overlayTrustedTypesPolicy;
|
|
422
437
|
|
|
438
|
+
/** @typedef {Extract<keyof CSSStyleDeclaration, "string">} CSSStyleDeclarationKeys */
|
|
439
|
+
|
|
423
440
|
/**
|
|
424
|
-
*
|
|
425
|
-
* @param {
|
|
426
|
-
* @param {CSSStyleDeclaration} style
|
|
441
|
+
* @param {HTMLElement} element element
|
|
442
|
+
* @param {Partial<CSSStyleDeclaration>} style style
|
|
427
443
|
*/
|
|
428
444
|
function applyStyle(element, style) {
|
|
429
445
|
Object.keys(style).forEach(function (prop) {
|
|
430
|
-
element.style[prop] =
|
|
446
|
+
element.style[(/** @type {CSSStyleDeclarationKeys} */prop)] = /** @type {string} */
|
|
447
|
+
style[(/** @type {CSSStyleDeclarationKeys} */prop)];
|
|
431
448
|
});
|
|
432
449
|
}
|
|
433
450
|
|
|
434
451
|
/**
|
|
435
|
-
* @param {string |
|
|
452
|
+
* @param {string | false | undefined} trustedTypesPolicyName trusted types police name
|
|
436
453
|
*/
|
|
437
454
|
function createContainer(trustedTypesPolicyName) {
|
|
438
455
|
// Enable Trusted Types if they are available in the current browser.
|
|
@@ -488,11 +505,12 @@ var createOverlay = function createOverlay(options) {
|
|
|
488
505
|
}
|
|
489
506
|
|
|
490
507
|
/**
|
|
491
|
-
* @param {(element: HTMLDivElement) => void} callback
|
|
492
|
-
* @param {string |
|
|
508
|
+
* @param {(element: HTMLDivElement) => void} callback callback
|
|
509
|
+
* @param {string | false | undefined} trustedTypesPolicyName trusted types policy name
|
|
493
510
|
*/
|
|
494
511
|
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
495
512
|
if (containerElement) {
|
|
513
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/30024
|
|
496
514
|
containerElement.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML("") : "";
|
|
497
515
|
// Everything is ready, call the callback right away.
|
|
498
516
|
callback(containerElement);
|
|
@@ -506,6 +524,9 @@ var createOverlay = function createOverlay(options) {
|
|
|
506
524
|
}
|
|
507
525
|
|
|
508
526
|
// Successful compilation.
|
|
527
|
+
/**
|
|
528
|
+
* @returns {void}
|
|
529
|
+
*/
|
|
509
530
|
function hide() {
|
|
510
531
|
if (!iframeContainerElement) {
|
|
511
532
|
return;
|
|
@@ -519,13 +540,14 @@ var createOverlay = function createOverlay(options) {
|
|
|
519
540
|
|
|
520
541
|
// Compilation with errors (e.g. syntax error or missing modules).
|
|
521
542
|
/**
|
|
522
|
-
* @param {string} type
|
|
523
|
-
* @param {
|
|
524
|
-
* @param {
|
|
525
|
-
* @param {'build' | 'runtime'} messageSource
|
|
543
|
+
* @param {string} type type
|
|
544
|
+
* @param {(string | Message)[]} messages messages
|
|
545
|
+
* @param {undefined | false | string} trustedTypesPolicyName trusted types policy name
|
|
546
|
+
* @param {'build' | 'runtime'} messageSource message source
|
|
526
547
|
*/
|
|
527
548
|
function show(type, messages, trustedTypesPolicyName, messageSource) {
|
|
528
549
|
ensureOverlayExists(function () {
|
|
550
|
+
/** @type {HTMLDivElement} */
|
|
529
551
|
headerElement.innerText = messageSource === "runtime" ? "Uncaught runtime errors:" : "Compiled with problems:";
|
|
530
552
|
messages.forEach(function (message) {
|
|
531
553
|
var entryElement = document.createElement("div");
|
|
@@ -539,12 +561,12 @@ var createOverlay = function createOverlay(options) {
|
|
|
539
561
|
body = _formatProblem.body;
|
|
540
562
|
typeElement.innerText = header;
|
|
541
563
|
applyStyle(typeElement, msgTypeStyle);
|
|
542
|
-
if (message.moduleIdentifier) {
|
|
564
|
+
if (typeof message !== "string" && message.moduleIdentifier) {
|
|
543
565
|
applyStyle(typeElement, {
|
|
544
566
|
cursor: "pointer"
|
|
545
567
|
});
|
|
546
568
|
// element.dataset not supported in IE
|
|
547
|
-
typeElement.setAttribute("data-can-open", true);
|
|
569
|
+
typeElement.setAttribute("data-can-open", "true");
|
|
548
570
|
typeElement.addEventListener("click", function () {
|
|
549
571
|
fetch("/webpack-dev-server/open-editor?fileName=".concat(message.moduleIdentifier));
|
|
550
572
|
});
|
|
@@ -554,6 +576,8 @@ var createOverlay = function createOverlay(options) {
|
|
|
554
576
|
var text = ansiHTML(encode(body));
|
|
555
577
|
var messageTextNode = document.createElement("div");
|
|
556
578
|
applyStyle(messageTextNode, msgTextStyle);
|
|
579
|
+
|
|
580
|
+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/30024
|
|
557
581
|
messageTextNode.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML(text) : text;
|
|
558
582
|
entryElement.appendChild(typeElement);
|
|
559
583
|
entryElement.appendChild(messageTextNode);
|
|
@@ -563,6 +587,18 @@ var createOverlay = function createOverlay(options) {
|
|
|
563
587
|
});
|
|
564
588
|
}, trustedTypesPolicyName);
|
|
565
589
|
}
|
|
590
|
+
|
|
591
|
+
/** @type {(event: KeyboardEvent) => void} */
|
|
592
|
+
var handleEscapeKey;
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* @returns {void}
|
|
596
|
+
*/
|
|
597
|
+
|
|
598
|
+
var hideOverlayWithEscCleanup = function hideOverlayWithEscCleanup() {
|
|
599
|
+
window.removeEventListener("keydown", handleEscapeKey);
|
|
600
|
+
hide();
|
|
601
|
+
};
|
|
566
602
|
var overlayService = createOverlayMachine({
|
|
567
603
|
showOverlay: function showOverlay(_ref3) {
|
|
568
604
|
var _ref3$level = _ref3.level,
|
|
@@ -571,15 +607,29 @@ var createOverlay = function createOverlay(options) {
|
|
|
571
607
|
messageSource = _ref3.messageSource;
|
|
572
608
|
return show(level, messages, options.trustedTypesPolicyName, messageSource);
|
|
573
609
|
},
|
|
574
|
-
hideOverlay:
|
|
610
|
+
hideOverlay: hideOverlayWithEscCleanup
|
|
575
611
|
});
|
|
612
|
+
/**
|
|
613
|
+
* ESC key press to dismiss the overlay.
|
|
614
|
+
* @param {KeyboardEvent} event Keydown event
|
|
615
|
+
*/
|
|
616
|
+
handleEscapeKey = function handleEscapeKey(event) {
|
|
617
|
+
if (event.key === "Escape" || event.key === "Esc" || event.keyCode === 27) {
|
|
618
|
+
overlayService.send({
|
|
619
|
+
type: "DISMISS"
|
|
620
|
+
});
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
window.addEventListener("keydown", handleEscapeKey);
|
|
576
624
|
if (options.catchRuntimeError) {
|
|
577
625
|
/**
|
|
578
|
-
* @param {Error | undefined} error
|
|
579
|
-
* @param {string} fallbackMessage
|
|
626
|
+
* @param {Error | undefined} error error
|
|
627
|
+
* @param {string} fallbackMessage fallback message
|
|
580
628
|
*/
|
|
581
629
|
var handleError = function handleError(error, fallbackMessage) {
|
|
582
|
-
var errorObject = error instanceof Error ? error : new Error(error || fallbackMessage
|
|
630
|
+
var errorObject = error instanceof Error ? error : new Error(error || fallbackMessage, {
|
|
631
|
+
cause: error
|
|
632
|
+
});
|
|
583
633
|
var shouldDisplay = typeof options.catchRuntimeError === "function" ? options.catchRuntimeError(errorObject) : true;
|
|
584
634
|
if (shouldDisplay) {
|
|
585
635
|
overlayService.send({
|
|
@@ -612,4 +662,4 @@ var createOverlay = function createOverlay(options) {
|
|
|
612
662
|
}
|
|
613
663
|
return overlayService;
|
|
614
664
|
};
|
|
615
|
-
export {
|
|
665
|
+
export { createOverlay, formatProblem };
|
package/client/progress.js
CHANGED
|
@@ -17,9 +17,16 @@ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? O
|
|
|
17
17
|
function _classPrivateMethodInitSpec(e, a) { _checkPrivateRedeclaration(e, a), a.add(e); }
|
|
18
18
|
function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
|
|
19
19
|
function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
|
|
20
|
+
/**
|
|
21
|
+
* @returns {boolean} true when custom elements supported, otherwise false
|
|
22
|
+
*/
|
|
20
23
|
export function isProgressSupported() {
|
|
21
|
-
return "customElements" in self &&
|
|
24
|
+
return "customElements" in self && Boolean(HTMLElement.prototype.attachShadow);
|
|
22
25
|
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @returns {void}
|
|
29
|
+
*/
|
|
23
30
|
export function defineProgressElement() {
|
|
24
31
|
var _WebpackDevServerProgress;
|
|
25
32
|
if (customElements.get("wds-progress")) {
|
|
@@ -47,13 +54,23 @@ export function defineProgressElement() {
|
|
|
47
54
|
}
|
|
48
55
|
}, {
|
|
49
56
|
key: "attributeChangedCallback",
|
|
50
|
-
value:
|
|
57
|
+
value:
|
|
58
|
+
/**
|
|
59
|
+
* @param {string} name name
|
|
60
|
+
* @param {string} oldValue old value
|
|
61
|
+
* @param {string} newValue new value
|
|
62
|
+
*/
|
|
63
|
+
function attributeChangedCallback(name, oldValue, newValue) {
|
|
51
64
|
if (name === "progress") {
|
|
52
65
|
_assertClassBrand(_WebpackDevServerProgress_brand, this, _update).call(this, Number(newValue));
|
|
53
66
|
} else if (name === "type") {
|
|
54
67
|
_assertClassBrand(_WebpackDevServerProgress_brand, this, _reset).call(this);
|
|
55
68
|
}
|
|
56
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {number} percent percent
|
|
73
|
+
*/
|
|
57
74
|
}], [{
|
|
58
75
|
key: "observedAttributes",
|
|
59
76
|
get: function get() {
|
|
@@ -63,30 +80,36 @@ export function defineProgressElement() {
|
|
|
63
80
|
}(/*#__PURE__*/_wrapNativeSuper(HTMLElement));
|
|
64
81
|
_WebpackDevServerProgress = WebpackDevServerProgress;
|
|
65
82
|
function _reset() {
|
|
66
|
-
var _this$getAttribute
|
|
83
|
+
var _this$getAttribute;
|
|
67
84
|
clearTimeout(this.animationTimer);
|
|
68
85
|
this.animationTimer = null;
|
|
69
86
|
var typeAttr = (_this$getAttribute = this.getAttribute("type")) === null || _this$getAttribute === void 0 ? void 0 : _this$getAttribute.toLowerCase();
|
|
70
87
|
this.type = typeAttr === "circular" ? "circular" : "linear";
|
|
71
88
|
var innerHTML = this.type === "circular" ? _circularTemplate.call(_WebpackDevServerProgress) : _linearTemplate.call(_WebpackDevServerProgress);
|
|
89
|
+
/** @type {ShadowRoot} */
|
|
72
90
|
this.shadowRoot.innerHTML = innerHTML;
|
|
73
|
-
|
|
91
|
+
var progressValue = this.getAttribute("progress");
|
|
92
|
+
this.initialProgress = progressValue ? Number(progressValue) : 0;
|
|
74
93
|
_assertClassBrand(_WebpackDevServerProgress_brand, this, _update).call(this, this.initialProgress);
|
|
75
94
|
}
|
|
76
95
|
function _circularTemplate() {
|
|
77
|
-
return "\n <style>\n :host {\n width: 200px;\n height: 200px;\n position: fixed;\n right: 5%;\n top: 5%;\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 ";
|
|
96
|
+
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 ";
|
|
78
97
|
}
|
|
79
98
|
function _linearTemplate() {
|
|
80
|
-
return "\n <style>\n :host {\n position: fixed;\n top: 0;\n left: 0;\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 ";
|
|
99
|
+
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 ";
|
|
81
100
|
}
|
|
82
101
|
function _update(percent) {
|
|
83
|
-
var
|
|
102
|
+
var shadowRoot = /** @type {ShadowRoot} */this.shadowRoot;
|
|
103
|
+
var element = /** @type {HTMLElement} */
|
|
104
|
+
shadowRoot.querySelector("#progress");
|
|
84
105
|
if (this.type === "circular") {
|
|
85
|
-
var path =
|
|
86
|
-
|
|
106
|
+
var path = /** @type {SVGPathElement} */
|
|
107
|
+
shadowRoot.querySelector("path");
|
|
108
|
+
var value = /** @type {HTMLElement} */
|
|
109
|
+
shadowRoot.querySelector("#percent-value");
|
|
87
110
|
var offset = (100 - percent) / 100 * this.maxDashOffset;
|
|
88
|
-
path.style.strokeDashoffset = offset;
|
|
89
|
-
value.textContent = percent;
|
|
111
|
+
path.style.strokeDashoffset = String(offset);
|
|
112
|
+
value.textContent = String(percent);
|
|
90
113
|
} else {
|
|
91
114
|
element.style.width = "".concat(percent, "%");
|
|
92
115
|
}
|
|
@@ -97,12 +120,16 @@ export function defineProgressElement() {
|
|
|
97
120
|
}
|
|
98
121
|
}
|
|
99
122
|
function _show() {
|
|
100
|
-
var
|
|
123
|
+
var shadowRoot = /** @type {ShadowRoot} */this.shadowRoot;
|
|
124
|
+
var element = /** @type {HTMLElement} */
|
|
125
|
+
shadowRoot.querySelector("#progress");
|
|
101
126
|
element.classList.remove("hidden");
|
|
102
127
|
}
|
|
103
128
|
function _hide() {
|
|
104
129
|
var _this2 = this;
|
|
105
|
-
var
|
|
130
|
+
var shadowRoot = /** @type {ShadowRoot} */this.shadowRoot;
|
|
131
|
+
var element = /** @type {HTMLElement} */
|
|
132
|
+
shadowRoot.querySelector("#progress");
|
|
106
133
|
if (this.type === "circular") {
|
|
107
134
|
element.classList.add("disappear");
|
|
108
135
|
element.addEventListener("animationend", function () {
|
package/client/socket.js
CHANGED
|
@@ -3,28 +3,33 @@
|
|
|
3
3
|
import WebSocketClient from "./clients/WebSocketClient.js";
|
|
4
4
|
import { log } from "./utils/log.js";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var Client =
|
|
9
|
-
// eslint-disable-next-line no-nested-ternary
|
|
10
|
-
typeof __webpack_dev_server_client__ !== "undefined" ? typeof __webpack_dev_server_client__.default !== "undefined" ? __webpack_dev_server_client__.default : __webpack_dev_server_client__ : WebSocketClient;
|
|
11
|
-
/* eslint-enable camelcase */
|
|
6
|
+
/** @typedef {import("./index.js").EXPECTED_ANY} EXPECTED_ANY */
|
|
7
|
+
/** @typedef {import("./clients/SockJSClient")} SockJSClient */
|
|
12
8
|
|
|
9
|
+
// this WebsocketClient is here as a default fallback, in case the client is not injected
|
|
10
|
+
/** @type {CommunicationClientConstructor} */
|
|
11
|
+
var Client = typeof __webpack_dev_server_client__ !== "undefined" ? typeof (/** @type {{ default: CommunicationClientConstructor }} */
|
|
12
|
+
__webpack_dev_server_client__.default) !== "undefined" ? /** @type {{ default: CommunicationClientConstructor }} */
|
|
13
|
+
__webpack_dev_server_client__.default : (/** @type {CommunicationClientConstructor} */
|
|
14
|
+
__webpack_dev_server_client__) : WebSocketClient;
|
|
13
15
|
var retries = 0;
|
|
14
16
|
var maxRetries = 10;
|
|
15
17
|
|
|
16
18
|
// Initialized client is exported so external consumers can utilize the same instance
|
|
17
19
|
// It is mutable to enforce singleton
|
|
20
|
+
/** @type {CommunicationClient | null} */
|
|
18
21
|
// eslint-disable-next-line import/no-mutable-exports
|
|
19
22
|
export var client = null;
|
|
23
|
+
|
|
24
|
+
/** @type {ReturnType<typeof setTimeout> | undefined} */
|
|
20
25
|
var timeout;
|
|
21
26
|
|
|
22
27
|
/**
|
|
23
|
-
* @param {string} url
|
|
24
|
-
* @param {{ [handler: string]: (data?:
|
|
25
|
-
* @param {number}
|
|
28
|
+
* @param {string} url url
|
|
29
|
+
* @param {{ [handler: string]: (data?: EXPECTED_ANY, params?: EXPECTED_ANY) => EXPECTED_ANY }} handlers handlers
|
|
30
|
+
* @param {number=} reconnect count of reconnections
|
|
26
31
|
*/
|
|
27
|
-
|
|
32
|
+
function socket(url, handlers, reconnect) {
|
|
28
33
|
client = new Client(url);
|
|
29
34
|
client.onOpen(function () {
|
|
30
35
|
retries = 0;
|
|
@@ -47,7 +52,6 @@ var socket = function initSocket(url, handlers, reconnect) {
|
|
|
47
52
|
if (retries < maxRetries) {
|
|
48
53
|
// Exponentially increase timeout to reconnect.
|
|
49
54
|
// Respectfully copied from the package `got`.
|
|
50
|
-
// eslint-disable-next-line no-restricted-properties
|
|
51
55
|
var retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
|
|
52
56
|
retries += 1;
|
|
53
57
|
log.info("Trying to reconnect...");
|
|
@@ -58,7 +62,7 @@ var socket = function initSocket(url, handlers, reconnect) {
|
|
|
58
62
|
});
|
|
59
63
|
client.onMessage(
|
|
60
64
|
/**
|
|
61
|
-
* @param {
|
|
65
|
+
* @param {EXPECTED_ANY} data data
|
|
62
66
|
*/
|
|
63
67
|
function (data) {
|
|
64
68
|
var message = JSON.parse(data);
|
|
@@ -66,5 +70,5 @@ var socket = function initSocket(url, handlers, reconnect) {
|
|
|
66
70
|
handlers[message.type](message.data, message.params);
|
|
67
71
|
}
|
|
68
72
|
});
|
|
69
|
-
}
|
|
73
|
+
}
|
|
70
74
|
export default socket;
|
package/client/utils/log.js
CHANGED
|
@@ -6,7 +6,7 @@ var defaultLevel = "info";
|
|
|
6
6
|
|
|
7
7
|
// options new options, merge with old options
|
|
8
8
|
/**
|
|
9
|
-
* @param {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level
|
|
9
|
+
* @param {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level level
|
|
10
10
|
* @returns {void}
|
|
11
11
|
*/
|
|
12
12
|
function setLogLevel(level) {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
/* global
|
|
1
|
+
/* global WorkerGlobalScope */
|
|
2
|
+
|
|
3
|
+
/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */
|
|
2
4
|
|
|
3
5
|
// Send messages to the outside, so plugins can consume it.
|
|
4
6
|
/**
|
|
5
|
-
* @param {string} type
|
|
6
|
-
* @param {
|
|
7
|
+
* @param {string} type type
|
|
8
|
+
* @param {EXPECTED_ANY=} data data
|
|
7
9
|
*/
|
|
8
10
|
function sendMsg(type, data) {
|
|
9
11
|
if (typeof self !== "undefined" && (typeof WorkerGlobalScope === "undefined" || !(self instanceof WorkerGlobalScope))) {
|