webpack-dev-server 4.11.1 → 4.13.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/bin/cli-flags.js +17 -0
- package/bin/webpack-dev-server.js +12 -0
- package/client/clients/SockJSClient.js +7 -14
- package/client/clients/WebSocketClient.js +7 -14
- package/client/index.js +49 -71
- package/client/modules/logger/index.js +66 -165
- package/client/modules/sockjs-client/index.js +516 -1166
- package/client/overlay/fsm.js +64 -0
- package/client/overlay/runtime-error.js +31 -0
- package/client/overlay/state-machine.js +95 -0
- package/client/overlay/styles.js +74 -0
- package/client/overlay.js +202 -167
- package/client/socket.js +13 -12
- package/client/utils/createSocketURL.js +20 -36
- package/client/utils/getCurrentScriptSource.js +4 -6
- package/client/utils/log.js +8 -13
- package/client/utils/parseURL.js +3 -8
- package/client/utils/reloadApp.js +9 -18
- package/client/utils/sendMessage.js +1 -2
- package/client/utils/stripAnsi.js +1 -3
- package/lib/Server.js +56 -16
- package/lib/options.json +7 -0
- package/lib/servers/SockJSServer.js +22 -10
- package/package.json +15 -12
- package/types/bin/cli-flags.d.ts +12 -0
- package/types/lib/Server.d.ts +173 -196
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {Object} StateDefinitions
|
|
8
|
+
* @property {{[event: string]: { target: string; actions?: Array<string> }}} [on]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Object} Options
|
|
13
|
+
* @property {{[state: string]: StateDefinitions}} states
|
|
14
|
+
* @property {object} context;
|
|
15
|
+
* @property {string} initial
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {Object} Implementation
|
|
20
|
+
* @property {{[actionName: string]: (ctx: object, event: any) => object}} actions
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A simplified `createMachine` from `@xstate/fsm` with the following differences:
|
|
25
|
+
*
|
|
26
|
+
* - the returned machine is technically a "service". No `interpret(machine).start()` is needed.
|
|
27
|
+
* - the state definition only support `on` and target must be declared with { target: 'nextState', actions: [] } explicitly.
|
|
28
|
+
* - event passed to `send` must be an object with `type` property.
|
|
29
|
+
* - actions implementation will be [assign action](https://xstate.js.org/docs/guides/context.html#assign-action) if you return any value.
|
|
30
|
+
* Do not return anything if you just want to invoke side effect.
|
|
31
|
+
*
|
|
32
|
+
* The goal of this custom function is to avoid installing the entire `'xstate/fsm'` package, while enabling modeling using
|
|
33
|
+
* state machine. You can copy the first parameter into the editor at https://stately.ai/viz to visualize the state machine.
|
|
34
|
+
*
|
|
35
|
+
* @param {Options} options
|
|
36
|
+
* @param {Implementation} implementation
|
|
37
|
+
*/
|
|
38
|
+
function createMachine(_ref, _ref2) {
|
|
39
|
+
var states = _ref.states,
|
|
40
|
+
context = _ref.context,
|
|
41
|
+
initial = _ref.initial;
|
|
42
|
+
var actions = _ref2.actions;
|
|
43
|
+
var currentState = initial;
|
|
44
|
+
var currentContext = context;
|
|
45
|
+
return {
|
|
46
|
+
send: function send(event) {
|
|
47
|
+
var currentStateOn = states[currentState].on;
|
|
48
|
+
var transitionConfig = currentStateOn && currentStateOn[event.type];
|
|
49
|
+
if (transitionConfig) {
|
|
50
|
+
currentState = transitionConfig.target;
|
|
51
|
+
if (transitionConfig.actions) {
|
|
52
|
+
transitionConfig.actions.forEach(function (actName) {
|
|
53
|
+
var actionImpl = actions[actName];
|
|
54
|
+
var nextContextValue = actionImpl && actionImpl(currentContext, event);
|
|
55
|
+
if (nextContextValue) {
|
|
56
|
+
currentContext = _objectSpread(_objectSpread({}, currentContext), nextContextValue);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export default createMachine;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Error} error
|
|
4
|
+
*/
|
|
5
|
+
function parseErrorToStacks(error) {
|
|
6
|
+
if (!error || !(error instanceof Error)) {
|
|
7
|
+
throw new Error("parseErrorToStacks expects Error object");
|
|
8
|
+
}
|
|
9
|
+
if (typeof error.stack === "string") {
|
|
10
|
+
return error.stack.split("\n").filter(function (stack) {
|
|
11
|
+
return stack !== "Error: ".concat(error.message);
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @callback ErrorCallback
|
|
18
|
+
* @param {ErrorEvent} error
|
|
19
|
+
* @returns {void}
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {ErrorCallback} callback
|
|
24
|
+
*/
|
|
25
|
+
function listenToRuntimeError(callback) {
|
|
26
|
+
window.addEventListener("error", callback);
|
|
27
|
+
return function cleanup() {
|
|
28
|
+
window.removeEventListener("error", callback);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export { listenToRuntimeError, parseErrorToStacks };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import createMachine from "./fsm.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {Object} ShowOverlayData
|
|
5
|
+
* @property {'warning' | 'error'} level
|
|
6
|
+
* @property {Array<string | { moduleIdentifier?: string, moduleName?: string, loc?: string, message?: string }>} messages
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @typedef {Object} CreateOverlayMachineOptions
|
|
11
|
+
* @property {(data: ShowOverlayData) => void} showOverlay
|
|
12
|
+
* @property {() => void} hideOverlay
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {CreateOverlayMachineOptions} options
|
|
17
|
+
*/
|
|
18
|
+
var createOverlayMachine = function createOverlayMachine(options) {
|
|
19
|
+
var hideOverlay = options.hideOverlay,
|
|
20
|
+
showOverlay = options.showOverlay;
|
|
21
|
+
var overlayMachine = createMachine({
|
|
22
|
+
initial: "hidden",
|
|
23
|
+
context: {
|
|
24
|
+
level: "error",
|
|
25
|
+
messages: []
|
|
26
|
+
},
|
|
27
|
+
states: {
|
|
28
|
+
hidden: {
|
|
29
|
+
on: {
|
|
30
|
+
BUILD_ERROR: {
|
|
31
|
+
target: "displayBuildError",
|
|
32
|
+
actions: ["setMessages", "showOverlay"]
|
|
33
|
+
},
|
|
34
|
+
RUNTIME_ERROR: {
|
|
35
|
+
target: "displayRuntimeError",
|
|
36
|
+
actions: ["setMessages", "showOverlay"]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
displayBuildError: {
|
|
41
|
+
on: {
|
|
42
|
+
DISMISS: {
|
|
43
|
+
target: "hidden",
|
|
44
|
+
actions: ["dismissMessages", "hideOverlay"]
|
|
45
|
+
},
|
|
46
|
+
BUILD_ERROR: {
|
|
47
|
+
target: "displayBuildError",
|
|
48
|
+
actions: ["appendMessages", "showOverlay"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
displayRuntimeError: {
|
|
53
|
+
on: {
|
|
54
|
+
DISMISS: {
|
|
55
|
+
target: "hidden",
|
|
56
|
+
actions: ["dismissMessages", "hideOverlay"]
|
|
57
|
+
},
|
|
58
|
+
RUNTIME_ERROR: {
|
|
59
|
+
target: "displayRuntimeError",
|
|
60
|
+
actions: ["appendMessages", "showOverlay"]
|
|
61
|
+
},
|
|
62
|
+
BUILD_ERROR: {
|
|
63
|
+
target: "displayBuildError",
|
|
64
|
+
actions: ["setMessages", "showOverlay"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
actions: {
|
|
71
|
+
dismissMessages: function dismissMessages() {
|
|
72
|
+
return {
|
|
73
|
+
messages: [],
|
|
74
|
+
level: "error"
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
appendMessages: function appendMessages(context, event) {
|
|
78
|
+
return {
|
|
79
|
+
messages: context.messages.concat(event.messages),
|
|
80
|
+
level: event.level || context.level
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
setMessages: function setMessages(context, event) {
|
|
84
|
+
return {
|
|
85
|
+
messages: event.messages,
|
|
86
|
+
level: event.level || context.level
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
hideOverlay: hideOverlay,
|
|
90
|
+
showOverlay: showOverlay
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return overlayMachine;
|
|
94
|
+
};
|
|
95
|
+
export default createOverlayMachine;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// styles are inspired by `react-error-overlay`
|
|
2
|
+
|
|
3
|
+
var msgStyles = {
|
|
4
|
+
error: {
|
|
5
|
+
backgroundColor: "rgba(206, 17, 38, 0.1)",
|
|
6
|
+
color: "#fccfcf"
|
|
7
|
+
},
|
|
8
|
+
warning: {
|
|
9
|
+
backgroundColor: "rgba(251, 245, 180, 0.1)",
|
|
10
|
+
color: "#fbf5b4"
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var iframeStyle = {
|
|
14
|
+
position: "fixed",
|
|
15
|
+
top: 0,
|
|
16
|
+
left: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
bottom: 0,
|
|
19
|
+
width: "100vw",
|
|
20
|
+
height: "100vh",
|
|
21
|
+
border: "none",
|
|
22
|
+
"z-index": 9999999999
|
|
23
|
+
};
|
|
24
|
+
var containerStyle = {
|
|
25
|
+
position: "fixed",
|
|
26
|
+
boxSizing: "border-box",
|
|
27
|
+
left: 0,
|
|
28
|
+
top: 0,
|
|
29
|
+
right: 0,
|
|
30
|
+
bottom: 0,
|
|
31
|
+
width: "100vw",
|
|
32
|
+
height: "100vh",
|
|
33
|
+
fontSize: "large",
|
|
34
|
+
padding: "2rem 2rem 4rem 2rem",
|
|
35
|
+
lineHeight: "1.2",
|
|
36
|
+
whiteSpace: "pre-wrap",
|
|
37
|
+
overflow: "auto",
|
|
38
|
+
backgroundColor: "rgba(0, 0, 0, 0.9)",
|
|
39
|
+
color: "white"
|
|
40
|
+
};
|
|
41
|
+
var headerStyle = {
|
|
42
|
+
color: "#e83b46",
|
|
43
|
+
fontSize: "2em",
|
|
44
|
+
whiteSpace: "pre-wrap",
|
|
45
|
+
fontFamily: "sans-serif",
|
|
46
|
+
margin: "0 2rem 2rem 0",
|
|
47
|
+
flex: "0 0 auto",
|
|
48
|
+
maxHeight: "50%",
|
|
49
|
+
overflow: "auto"
|
|
50
|
+
};
|
|
51
|
+
var dismissButtonStyle = {
|
|
52
|
+
color: "#ffffff",
|
|
53
|
+
lineHeight: "1rem",
|
|
54
|
+
fontSize: "1.5rem",
|
|
55
|
+
padding: "1rem",
|
|
56
|
+
cursor: "pointer",
|
|
57
|
+
position: "absolute",
|
|
58
|
+
right: 0,
|
|
59
|
+
top: 0,
|
|
60
|
+
backgroundColor: "transparent",
|
|
61
|
+
border: "none"
|
|
62
|
+
};
|
|
63
|
+
var msgTypeStyle = {
|
|
64
|
+
color: "#e83b46",
|
|
65
|
+
fontSize: "1.2em",
|
|
66
|
+
marginBottom: "1rem",
|
|
67
|
+
fontFamily: "sans-serif"
|
|
68
|
+
};
|
|
69
|
+
var msgTextStyle = {
|
|
70
|
+
lineHeight: "1.5",
|
|
71
|
+
fontSize: "1rem",
|
|
72
|
+
fontFamily: "Menlo, Consolas, monospace"
|
|
73
|
+
};
|
|
74
|
+
export { msgStyles, iframeStyle, containerStyle, headerStyle, dismissButtonStyle, msgTypeStyle, msgTextStyle };
|
package/client/overlay.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
6
|
// The error overlay is inspired (and mostly copied) from Create React App (https://github.com/facebookincubator/create-react-app)
|
|
2
7
|
// They, in turn, got inspired by webpack-hot-middleware (https://github.com/glenjamin/webpack-hot-middleware).
|
|
8
|
+
|
|
3
9
|
import ansiHTML from "ansi-html-community";
|
|
4
10
|
import { encode } from "html-entities";
|
|
11
|
+
import { listenToRuntimeError, parseErrorToStacks } from "./overlay/runtime-error.js";
|
|
12
|
+
import createOverlayMachine from "./overlay/state-machine.js";
|
|
13
|
+
import { containerStyle, dismissButtonStyle, headerStyle, iframeStyle, msgStyles, msgTextStyle, msgTypeStyle } from "./overlay/styles.js";
|
|
5
14
|
var colors = {
|
|
6
15
|
reset: ["transparent", "transparent"],
|
|
7
16
|
black: "181818",
|
|
@@ -14,201 +23,227 @@ var colors = {
|
|
|
14
23
|
lightgrey: "EBE7E3",
|
|
15
24
|
darkgrey: "6D7891"
|
|
16
25
|
};
|
|
17
|
-
/** @type {HTMLIFrameElement | null | undefined} */
|
|
18
|
-
|
|
19
|
-
var iframeContainerElement;
|
|
20
|
-
/** @type {HTMLDivElement | null | undefined} */
|
|
21
|
-
|
|
22
|
-
var containerElement;
|
|
23
|
-
/** @type {Array<(element: HTMLDivElement) => void>} */
|
|
24
|
-
|
|
25
|
-
var onLoadQueue = [];
|
|
26
|
-
/** @type {TrustedTypePolicy | undefined} */
|
|
27
|
-
|
|
28
|
-
var overlayTrustedTypesPolicy;
|
|
29
26
|
ansiHTML.setColors(colors);
|
|
30
|
-
/**
|
|
31
|
-
* @param {string | null} trustedTypesPolicyName
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
function createContainer(trustedTypesPolicyName) {
|
|
35
|
-
// Enable Trusted Types if they are available in the current browser.
|
|
36
|
-
if (window.trustedTypes) {
|
|
37
|
-
overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || "webpack-dev-server#overlay", {
|
|
38
|
-
createHTML: function createHTML(value) {
|
|
39
|
-
return value;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
iframeContainerElement = document.createElement("iframe");
|
|
45
|
-
iframeContainerElement.id = "webpack-dev-server-client-overlay";
|
|
46
|
-
iframeContainerElement.src = "about:blank";
|
|
47
|
-
iframeContainerElement.style.position = "fixed";
|
|
48
|
-
iframeContainerElement.style.left = 0;
|
|
49
|
-
iframeContainerElement.style.top = 0;
|
|
50
|
-
iframeContainerElement.style.right = 0;
|
|
51
|
-
iframeContainerElement.style.bottom = 0;
|
|
52
|
-
iframeContainerElement.style.width = "100vw";
|
|
53
|
-
iframeContainerElement.style.height = "100vh";
|
|
54
|
-
iframeContainerElement.style.border = "none";
|
|
55
|
-
iframeContainerElement.style.zIndex = 9999999999;
|
|
56
|
-
|
|
57
|
-
iframeContainerElement.onload = function () {
|
|
58
|
-
containerElement =
|
|
59
|
-
/** @type {Document} */
|
|
60
|
-
|
|
61
|
-
/** @type {HTMLIFrameElement} */
|
|
62
|
-
iframeContainerElement.contentDocument.createElement("div");
|
|
63
|
-
containerElement.id = "webpack-dev-server-client-overlay-div";
|
|
64
|
-
containerElement.style.position = "fixed";
|
|
65
|
-
containerElement.style.boxSizing = "border-box";
|
|
66
|
-
containerElement.style.left = 0;
|
|
67
|
-
containerElement.style.top = 0;
|
|
68
|
-
containerElement.style.right = 0;
|
|
69
|
-
containerElement.style.bottom = 0;
|
|
70
|
-
containerElement.style.width = "100vw";
|
|
71
|
-
containerElement.style.height = "100vh";
|
|
72
|
-
containerElement.style.backgroundColor = "rgba(0, 0, 0, 0.85)";
|
|
73
|
-
containerElement.style.color = "#E8E8E8";
|
|
74
|
-
containerElement.style.fontFamily = "Menlo, Consolas, monospace";
|
|
75
|
-
containerElement.style.fontSize = "large";
|
|
76
|
-
containerElement.style.padding = "2rem";
|
|
77
|
-
containerElement.style.lineHeight = "1.2";
|
|
78
|
-
containerElement.style.whiteSpace = "pre-wrap";
|
|
79
|
-
containerElement.style.overflow = "auto";
|
|
80
|
-
var headerElement = document.createElement("span");
|
|
81
|
-
headerElement.innerText = "Compiled with problems:";
|
|
82
|
-
var closeButtonElement = document.createElement("button");
|
|
83
|
-
closeButtonElement.innerText = "X";
|
|
84
|
-
closeButtonElement.style.background = "transparent";
|
|
85
|
-
closeButtonElement.style.border = "none";
|
|
86
|
-
closeButtonElement.style.fontSize = "20px";
|
|
87
|
-
closeButtonElement.style.fontWeight = "bold";
|
|
88
|
-
closeButtonElement.style.color = "white";
|
|
89
|
-
closeButtonElement.style.cursor = "pointer";
|
|
90
|
-
closeButtonElement.style.cssFloat = "right"; // @ts-ignore
|
|
91
|
-
|
|
92
|
-
closeButtonElement.style.styleFloat = "right";
|
|
93
|
-
closeButtonElement.addEventListener("click", function () {
|
|
94
|
-
hide();
|
|
95
|
-
});
|
|
96
|
-
containerElement.appendChild(headerElement);
|
|
97
|
-
containerElement.appendChild(closeButtonElement);
|
|
98
|
-
containerElement.appendChild(document.createElement("br"));
|
|
99
|
-
containerElement.appendChild(document.createElement("br"));
|
|
100
|
-
/** @type {Document} */
|
|
101
|
-
|
|
102
|
-
/** @type {HTMLIFrameElement} */
|
|
103
|
-
iframeContainerElement.contentDocument.body.appendChild(containerElement);
|
|
104
|
-
onLoadQueue.forEach(function (onLoad) {
|
|
105
|
-
onLoad(
|
|
106
|
-
/** @type {HTMLDivElement} */
|
|
107
|
-
containerElement);
|
|
108
|
-
});
|
|
109
|
-
onLoadQueue = [];
|
|
110
|
-
/** @type {HTMLIFrameElement} */
|
|
111
|
-
|
|
112
|
-
iframeContainerElement.onload = null;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
document.body.appendChild(iframeContainerElement);
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* @param {(element: HTMLDivElement) => void} callback
|
|
119
|
-
* @param {string | null} trustedTypesPolicyName
|
|
120
|
-
*/
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
124
|
-
if (containerElement) {
|
|
125
|
-
// Everything is ready, call the callback right away.
|
|
126
|
-
callback(containerElement);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
onLoadQueue.push(callback);
|
|
131
|
-
|
|
132
|
-
if (iframeContainerElement) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
createContainer(trustedTypesPolicyName);
|
|
137
|
-
} // Successful compilation.
|
|
138
27
|
|
|
139
|
-
|
|
140
|
-
function hide() {
|
|
141
|
-
if (!iframeContainerElement) {
|
|
142
|
-
return;
|
|
143
|
-
} // Clean up and reset internal state.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
document.body.removeChild(iframeContainerElement);
|
|
147
|
-
iframeContainerElement = null;
|
|
148
|
-
containerElement = null;
|
|
149
|
-
}
|
|
150
28
|
/**
|
|
151
29
|
* @param {string} type
|
|
152
|
-
* @param {string | { file?: string, moduleName?: string, loc?: string, message?: string }} item
|
|
30
|
+
* @param {string | { file?: string, moduleName?: string, loc?: string, message?: string; stack?: string[] }} item
|
|
153
31
|
* @returns {{ header: string, body: string }}
|
|
154
32
|
*/
|
|
155
|
-
|
|
156
|
-
|
|
157
33
|
function formatProblem(type, item) {
|
|
158
34
|
var header = type === "warning" ? "WARNING" : "ERROR";
|
|
159
35
|
var body = "";
|
|
160
|
-
|
|
161
36
|
if (typeof item === "string") {
|
|
162
37
|
body += item;
|
|
163
38
|
} else {
|
|
164
|
-
var file = item.file || "";
|
|
165
|
-
|
|
39
|
+
var file = item.file || "";
|
|
40
|
+
// eslint-disable-next-line no-nested-ternary
|
|
166
41
|
var moduleName = item.moduleName ? item.moduleName.indexOf("!") !== -1 ? "".concat(item.moduleName.replace(/^(\s|\S)*!/, ""), " (").concat(item.moduleName, ")") : "".concat(item.moduleName) : "";
|
|
167
42
|
var loc = item.loc;
|
|
168
43
|
header += "".concat(moduleName || file ? " in ".concat(moduleName ? "".concat(moduleName).concat(file ? " (".concat(file, ")") : "") : file).concat(loc ? " ".concat(loc) : "") : "");
|
|
169
44
|
body += item.message || "";
|
|
170
45
|
}
|
|
171
|
-
|
|
46
|
+
if (Array.isArray(item.stack)) {
|
|
47
|
+
item.stack.forEach(function (stack) {
|
|
48
|
+
if (typeof stack === "string") {
|
|
49
|
+
body += "\r\n".concat(stack);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
172
53
|
return {
|
|
173
54
|
header: header,
|
|
174
55
|
body: body
|
|
175
56
|
};
|
|
176
|
-
}
|
|
57
|
+
}
|
|
177
58
|
|
|
178
59
|
/**
|
|
179
|
-
* @
|
|
180
|
-
* @
|
|
181
|
-
* @
|
|
60
|
+
* @typedef {Object} CreateOverlayOptions
|
|
61
|
+
* @property {string | null} trustedTypesPolicyName
|
|
62
|
+
* @property {boolean} [catchRuntimeError]
|
|
182
63
|
*/
|
|
183
64
|
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {CreateOverlayOptions} options
|
|
68
|
+
*/
|
|
69
|
+
var createOverlay = function createOverlay(options) {
|
|
70
|
+
/** @type {HTMLIFrameElement | null | undefined} */
|
|
71
|
+
var iframeContainerElement;
|
|
72
|
+
/** @type {HTMLDivElement | null | undefined} */
|
|
73
|
+
var containerElement;
|
|
74
|
+
/** @type {Array<(element: HTMLDivElement) => void>} */
|
|
75
|
+
var onLoadQueue = [];
|
|
76
|
+
/** @type {TrustedTypePolicy | undefined} */
|
|
77
|
+
var overlayTrustedTypesPolicy;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {HTMLElement} element
|
|
82
|
+
* @param {CSSStyleDeclaration} style
|
|
83
|
+
*/
|
|
84
|
+
function applyStyle(element, style) {
|
|
85
|
+
Object.keys(style).forEach(function (prop) {
|
|
86
|
+
element.style[prop] = style[prop];
|
|
87
|
+
});
|
|
88
|
+
}
|
|
184
89
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
90
|
+
/**
|
|
91
|
+
* @param {string | null} trustedTypesPolicyName
|
|
92
|
+
*/
|
|
93
|
+
function createContainer(trustedTypesPolicyName) {
|
|
94
|
+
// Enable Trusted Types if they are available in the current browser.
|
|
95
|
+
if (window.trustedTypes) {
|
|
96
|
+
overlayTrustedTypesPolicy = window.trustedTypes.createPolicy(trustedTypesPolicyName || "webpack-dev-server#overlay", {
|
|
97
|
+
createHTML: function createHTML(value) {
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
iframeContainerElement = document.createElement("iframe");
|
|
103
|
+
iframeContainerElement.id = "webpack-dev-server-client-overlay";
|
|
104
|
+
iframeContainerElement.src = "about:blank";
|
|
105
|
+
applyStyle(iframeContainerElement, iframeStyle);
|
|
106
|
+
iframeContainerElement.onload = function () {
|
|
107
|
+
var contentElement = /** @type {Document} */
|
|
108
|
+
/** @type {HTMLIFrameElement} */
|
|
109
|
+
iframeContainerElement.contentDocument.createElement("div");
|
|
110
|
+
containerElement = /** @type {Document} */
|
|
111
|
+
/** @type {HTMLIFrameElement} */
|
|
112
|
+
iframeContainerElement.contentDocument.createElement("div");
|
|
113
|
+
contentElement.id = "webpack-dev-server-client-overlay-div";
|
|
114
|
+
applyStyle(contentElement, containerStyle);
|
|
115
|
+
var headerElement = document.createElement("div");
|
|
116
|
+
headerElement.innerText = "Compiled with problems:";
|
|
117
|
+
applyStyle(headerElement, headerStyle);
|
|
118
|
+
var closeButtonElement = document.createElement("button");
|
|
119
|
+
applyStyle(closeButtonElement, dismissButtonStyle);
|
|
120
|
+
closeButtonElement.innerText = "×";
|
|
121
|
+
closeButtonElement.ariaLabel = "Dismiss";
|
|
122
|
+
closeButtonElement.addEventListener("click", function () {
|
|
123
|
+
// eslint-disable-next-line no-use-before-define
|
|
124
|
+
overlayService.send({
|
|
125
|
+
type: "DISMISS"
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
contentElement.appendChild(headerElement);
|
|
129
|
+
contentElement.appendChild(closeButtonElement);
|
|
130
|
+
contentElement.appendChild(containerElement);
|
|
131
|
+
|
|
132
|
+
/** @type {Document} */
|
|
133
|
+
/** @type {HTMLIFrameElement} */
|
|
134
|
+
iframeContainerElement.contentDocument.body.appendChild(contentElement);
|
|
135
|
+
onLoadQueue.forEach(function (onLoad) {
|
|
136
|
+
onLoad( /** @type {HTMLDivElement} */contentElement);
|
|
137
|
+
});
|
|
138
|
+
onLoadQueue = [];
|
|
139
|
+
|
|
140
|
+
/** @type {HTMLIFrameElement} */
|
|
141
|
+
iframeContainerElement.onload = null;
|
|
142
|
+
};
|
|
143
|
+
document.body.appendChild(iframeContainerElement);
|
|
144
|
+
}
|
|
190
145
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
146
|
+
/**
|
|
147
|
+
* @param {(element: HTMLDivElement) => void} callback
|
|
148
|
+
* @param {string | null} trustedTypesPolicyName
|
|
149
|
+
*/
|
|
150
|
+
function ensureOverlayExists(callback, trustedTypesPolicyName) {
|
|
151
|
+
if (containerElement) {
|
|
152
|
+
containerElement.innerHTML = "";
|
|
153
|
+
// Everything is ready, call the callback right away.
|
|
154
|
+
callback(containerElement);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
onLoadQueue.push(callback);
|
|
158
|
+
if (iframeContainerElement) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
createContainer(trustedTypesPolicyName);
|
|
162
|
+
}
|
|
194
163
|
|
|
195
|
-
|
|
196
|
-
|
|
164
|
+
// Successful compilation.
|
|
165
|
+
function hide() {
|
|
166
|
+
if (!iframeContainerElement) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
197
169
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
entryElement.appendChild(document.createElement("br"));
|
|
204
|
-
entryElement.appendChild(messageTextNode);
|
|
205
|
-
entryElement.appendChild(document.createElement("br"));
|
|
206
|
-
entryElement.appendChild(document.createElement("br"));
|
|
207
|
-
/** @type {HTMLDivElement} */
|
|
170
|
+
// Clean up and reset internal state.
|
|
171
|
+
document.body.removeChild(iframeContainerElement);
|
|
172
|
+
iframeContainerElement = null;
|
|
173
|
+
containerElement = null;
|
|
174
|
+
}
|
|
208
175
|
|
|
209
|
-
|
|
176
|
+
// Compilation with errors (e.g. syntax error or missing modules).
|
|
177
|
+
/**
|
|
178
|
+
* @param {string} type
|
|
179
|
+
* @param {Array<string | { moduleIdentifier?: string, moduleName?: string, loc?: string, message?: string }>} messages
|
|
180
|
+
* @param {string | null} trustedTypesPolicyName
|
|
181
|
+
*/
|
|
182
|
+
function show(type, messages, trustedTypesPolicyName) {
|
|
183
|
+
ensureOverlayExists(function () {
|
|
184
|
+
messages.forEach(function (message) {
|
|
185
|
+
var entryElement = document.createElement("div");
|
|
186
|
+
var msgStyle = type === "warning" ? msgStyles.warning : msgStyles.error;
|
|
187
|
+
applyStyle(entryElement, _objectSpread(_objectSpread({}, msgStyle), {}, {
|
|
188
|
+
padding: "1rem 1rem 1.5rem 1rem"
|
|
189
|
+
}));
|
|
190
|
+
var typeElement = document.createElement("div");
|
|
191
|
+
var _formatProblem = formatProblem(type, message),
|
|
192
|
+
header = _formatProblem.header,
|
|
193
|
+
body = _formatProblem.body;
|
|
194
|
+
typeElement.innerText = header;
|
|
195
|
+
applyStyle(typeElement, msgTypeStyle);
|
|
196
|
+
if (message.moduleIdentifier) {
|
|
197
|
+
applyStyle(typeElement, {
|
|
198
|
+
cursor: "pointer"
|
|
199
|
+
});
|
|
200
|
+
// element.dataset not supported in IE
|
|
201
|
+
typeElement.setAttribute("data-can-open", true);
|
|
202
|
+
typeElement.addEventListener("click", function () {
|
|
203
|
+
fetch("/webpack-dev-server/open-editor?fileName=".concat(message.moduleIdentifier));
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Make it look similar to our terminal.
|
|
208
|
+
var text = ansiHTML(encode(body));
|
|
209
|
+
var messageTextNode = document.createElement("div");
|
|
210
|
+
applyStyle(messageTextNode, msgTextStyle);
|
|
211
|
+
messageTextNode.innerHTML = overlayTrustedTypesPolicy ? overlayTrustedTypesPolicy.createHTML(text) : text;
|
|
212
|
+
entryElement.appendChild(typeElement);
|
|
213
|
+
entryElement.appendChild(messageTextNode);
|
|
214
|
+
|
|
215
|
+
/** @type {HTMLDivElement} */
|
|
216
|
+
containerElement.appendChild(entryElement);
|
|
217
|
+
});
|
|
218
|
+
}, trustedTypesPolicyName);
|
|
219
|
+
}
|
|
220
|
+
var overlayService = createOverlayMachine({
|
|
221
|
+
showOverlay: function showOverlay(_ref) {
|
|
222
|
+
var _ref$level = _ref.level,
|
|
223
|
+
level = _ref$level === void 0 ? "error" : _ref$level,
|
|
224
|
+
messages = _ref.messages;
|
|
225
|
+
return show(level, messages, options.trustedTypesPolicyName);
|
|
226
|
+
},
|
|
227
|
+
hideOverlay: hide
|
|
228
|
+
});
|
|
229
|
+
if (options.catchRuntimeError) {
|
|
230
|
+
listenToRuntimeError(function (errorEvent) {
|
|
231
|
+
// error property may be empty in older browser like IE
|
|
232
|
+
var error = errorEvent.error,
|
|
233
|
+
message = errorEvent.message;
|
|
234
|
+
if (!error && !message) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
var errorObject = error instanceof Error ? error : new Error(error || message);
|
|
238
|
+
overlayService.send({
|
|
239
|
+
type: "RUNTIME_ERROR",
|
|
240
|
+
messages: [{
|
|
241
|
+
message: errorObject.message,
|
|
242
|
+
stack: parseErrorToStacks(errorObject)
|
|
243
|
+
}]
|
|
244
|
+
});
|
|
210
245
|
});
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
export { formatProblem,
|
|
246
|
+
}
|
|
247
|
+
return overlayService;
|
|
248
|
+
};
|
|
249
|
+
export { formatProblem, createOverlay };
|