webpack-dev-server 5.0.2 → 5.2.2

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.
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export = WebsocketServer;
3
2
  declare class WebsocketServer extends BaseServer {
4
3
  static heartbeatInterval: number;
@@ -1,64 +0,0 @@
1
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
2
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
5
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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;
@@ -1,47 +0,0 @@
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
-
32
- /**
33
- * @callback UnhandledRejectionCallback
34
- * @param {PromiseRejectionEvent} rejectionEvent
35
- * @returns {void}
36
- */
37
-
38
- /**
39
- * @param {UnhandledRejectionCallback} callback
40
- */
41
- function listenToUnhandledRejection(callback) {
42
- window.addEventListener("unhandledrejection", callback);
43
- return function cleanup() {
44
- window.removeEventListener("unhandledrejection", callback);
45
- };
46
- }
47
- export { listenToRuntimeError, listenToUnhandledRejection, parseErrorToStacks };
@@ -1,100 +0,0 @@
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
- * @property {'build' | 'runtime'} messageSource
8
- */
9
-
10
- /**
11
- * @typedef {Object} CreateOverlayMachineOptions
12
- * @property {(data: ShowOverlayData) => void} showOverlay
13
- * @property {() => void} hideOverlay
14
- */
15
-
16
- /**
17
- * @param {CreateOverlayMachineOptions} options
18
- */
19
- var createOverlayMachine = function createOverlayMachine(options) {
20
- var hideOverlay = options.hideOverlay,
21
- showOverlay = options.showOverlay;
22
- var overlayMachine = createMachine({
23
- initial: "hidden",
24
- context: {
25
- level: "error",
26
- messages: [],
27
- messageSource: "build"
28
- },
29
- states: {
30
- hidden: {
31
- on: {
32
- BUILD_ERROR: {
33
- target: "displayBuildError",
34
- actions: ["setMessages", "showOverlay"]
35
- },
36
- RUNTIME_ERROR: {
37
- target: "displayRuntimeError",
38
- actions: ["setMessages", "showOverlay"]
39
- }
40
- }
41
- },
42
- displayBuildError: {
43
- on: {
44
- DISMISS: {
45
- target: "hidden",
46
- actions: ["dismissMessages", "hideOverlay"]
47
- },
48
- BUILD_ERROR: {
49
- target: "displayBuildError",
50
- actions: ["appendMessages", "showOverlay"]
51
- }
52
- }
53
- },
54
- displayRuntimeError: {
55
- on: {
56
- DISMISS: {
57
- target: "hidden",
58
- actions: ["dismissMessages", "hideOverlay"]
59
- },
60
- RUNTIME_ERROR: {
61
- target: "displayRuntimeError",
62
- actions: ["appendMessages", "showOverlay"]
63
- },
64
- BUILD_ERROR: {
65
- target: "displayBuildError",
66
- actions: ["setMessages", "showOverlay"]
67
- }
68
- }
69
- }
70
- }
71
- }, {
72
- actions: {
73
- dismissMessages: function dismissMessages() {
74
- return {
75
- messages: [],
76
- level: "error",
77
- messageSource: "build"
78
- };
79
- },
80
- appendMessages: function appendMessages(context, event) {
81
- return {
82
- messages: context.messages.concat(event.messages),
83
- level: event.level || context.level,
84
- messageSource: event.type === "RUNTIME_ERROR" ? "runtime" : "build"
85
- };
86
- },
87
- setMessages: function setMessages(context, event) {
88
- return {
89
- messages: event.messages,
90
- level: event.level || context.level,
91
- messageSource: event.type === "RUNTIME_ERROR" ? "runtime" : "build"
92
- };
93
- },
94
- hideOverlay: hideOverlay,
95
- showOverlay: showOverlay
96
- }
97
- });
98
- return overlayMachine;
99
- };
100
- export default createOverlayMachine;
@@ -1,74 +0,0 @@
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 };
@@ -1,121 +0,0 @@
1
- /**
2
- * @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL
3
- * @returns {string}
4
- */
5
- function format(objURL) {
6
- var protocol = objURL.protocol || "";
7
- if (protocol && protocol.substr(-1) !== ":") {
8
- protocol += ":";
9
- }
10
- var auth = objURL.auth || "";
11
- if (auth) {
12
- auth = encodeURIComponent(auth);
13
- auth = auth.replace(/%3A/i, ":");
14
- auth += "@";
15
- }
16
- var host = "";
17
- if (objURL.hostname) {
18
- host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
19
- if (objURL.port) {
20
- host += ":".concat(objURL.port);
21
- }
22
- }
23
- var pathname = objURL.pathname || "";
24
- if (objURL.slashes) {
25
- host = "//".concat(host || "");
26
- if (pathname && pathname.charAt(0) !== "/") {
27
- pathname = "/".concat(pathname);
28
- }
29
- } else if (!host) {
30
- host = "";
31
- }
32
- var search = objURL.search || "";
33
- if (search && search.charAt(0) !== "?") {
34
- search = "?".concat(search);
35
- }
36
- var hash = objURL.hash || "";
37
- if (hash && hash.charAt(0) !== "#") {
38
- hash = "#".concat(hash);
39
- }
40
- pathname = pathname.replace(/[?#]/g,
41
- /**
42
- * @param {string} match
43
- * @returns {string}
44
- */
45
- function (match) {
46
- return encodeURIComponent(match);
47
- });
48
- search = search.replace("#", "%23");
49
- return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
50
- }
51
-
52
- /**
53
- * @param {URL & { fromCurrentScript?: boolean }} parsedURL
54
- * @returns {string}
55
- */
56
- function createSocketURL(parsedURL) {
57
- var hostname = parsedURL.hostname;
58
-
59
- // Node.js module parses it as `::`
60
- // `new URL(urlString, [baseURLString])` parses it as '[::]'
61
- var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]";
62
-
63
- // why do we need this check?
64
- // hostname n/a for file protocol (example, when using electron, ionic)
65
- // see: https://github.com/webpack/webpack-dev-server/pull/384
66
- if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf("http") === 0) {
67
- hostname = self.location.hostname;
68
- }
69
- var socketURLProtocol = parsedURL.protocol || self.location.protocol;
70
-
71
- // When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
72
- if (socketURLProtocol === "auto:" || hostname && isInAddrAny && self.location.protocol === "https:") {
73
- socketURLProtocol = self.location.protocol;
74
- }
75
- socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
76
- var socketURLAuth = "";
77
-
78
- // `new URL(urlString, [baseURLstring])` doesn't have `auth` property
79
- // Parse authentication credentials in case we need them
80
- if (parsedURL.username) {
81
- socketURLAuth = parsedURL.username;
82
-
83
- // Since HTTP basic authentication does not allow empty username,
84
- // we only include password if the username is not empty.
85
- if (parsedURL.password) {
86
- // Result: <username>:<password>
87
- socketURLAuth = socketURLAuth.concat(":", parsedURL.password);
88
- }
89
- }
90
-
91
- // In case the host is a raw IPv6 address, it can be enclosed in
92
- // the brackets as the brackets are needed in the final URL string.
93
- // Need to remove those as url.format blindly adds its own set of brackets
94
- // if the host string contains colons. That would lead to non-working
95
- // double brackets (e.g. [[::]]) host
96
- //
97
- // All of these web socket url params are optionally passed in through resourceQuery,
98
- // so we need to fall back to the default if they are not provided
99
- var socketURLHostname = (hostname || self.location.hostname || "localhost").replace(/^\[(.*)\]$/, "$1");
100
- var socketURLPort = parsedURL.port;
101
- if (!socketURLPort || socketURLPort === "0") {
102
- socketURLPort = self.location.port;
103
- }
104
-
105
- // If path is provided it'll be passed in via the resourceQuery as a
106
- // query param so it has to be parsed out of the querystring in order for the
107
- // client to open the socket to the correct location.
108
- var socketURLPathname = "/ws";
109
- if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
110
- socketURLPathname = parsedURL.pathname;
111
- }
112
- return format({
113
- protocol: socketURLProtocol,
114
- auth: socketURLAuth,
115
- hostname: socketURLHostname,
116
- port: socketURLPort,
117
- pathname: socketURLPathname,
118
- slashes: true
119
- });
120
- }
121
- export default createSocketURL;
@@ -1,24 +0,0 @@
1
- /**
2
- * @returns {string}
3
- */
4
- function getCurrentScriptSource() {
5
- // `document.currentScript` is the most accurate way to find the current script,
6
- // but is not supported in all browsers.
7
- if (document.currentScript) {
8
- return document.currentScript.getAttribute("src");
9
- }
10
-
11
- // Fallback to getting all scripts running in the document.
12
- var scriptElements = document.scripts || [];
13
- var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) {
14
- return element.getAttribute("src");
15
- });
16
- if (scriptElementsWithSrc.length > 0) {
17
- var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
18
- return currentScript.getAttribute("src");
19
- }
20
-
21
- // Fail as there was no script to use.
22
- throw new Error("[webpack-dev-server] Failed to get current script source.");
23
- }
24
- export default getCurrentScriptSource;
@@ -1,36 +0,0 @@
1
- import getCurrentScriptSource from "./getCurrentScriptSource.js";
2
-
3
- /**
4
- * @param {string} resourceQuery
5
- * @returns {{ [key: string]: string | boolean }}
6
- */
7
- function parseURL(resourceQuery) {
8
- /** @type {{ [key: string]: string }} */
9
- var options = {};
10
- if (typeof resourceQuery === "string" && resourceQuery !== "") {
11
- var searchParams = resourceQuery.slice(1).split("&");
12
- for (var i = 0; i < searchParams.length; i++) {
13
- var pair = searchParams[i].split("=");
14
- options[pair[0]] = decodeURIComponent(pair[1]);
15
- }
16
- } else {
17
- // Else, get the url from the <script> this file was called with.
18
- var scriptSource = getCurrentScriptSource();
19
- var scriptSourceURL;
20
- try {
21
- // The placeholder `baseURL` with `window.location.href`,
22
- // is to allow parsing of path-relative or protocol-relative URLs,
23
- // and will have no effect if `scriptSource` is a fully valid URL.
24
- scriptSourceURL = new URL(scriptSource, self.location.href);
25
- } catch (error) {
26
- // URL parsing failed, do nothing.
27
- // We will still proceed to see if we can recover using `resourceQuery`
28
- }
29
- if (scriptSourceURL) {
30
- options = scriptSourceURL;
31
- options.fromCurrentScript = true;
32
- }
33
- }
34
- return options;
35
- }
36
- export default parseURL;
@@ -1,63 +0,0 @@
1
- import hotEmitter from "webpack/hot/emitter.js";
2
- import { log } from "./log.js";
3
-
4
- /** @typedef {import("../index").Options} Options
5
- /** @typedef {import("../index").Status} Status
6
-
7
- /**
8
- * @param {Options} options
9
- * @param {Status} status
10
- */
11
- function reloadApp(_ref, status) {
12
- var hot = _ref.hot,
13
- liveReload = _ref.liveReload;
14
- if (status.isUnloading) {
15
- return;
16
- }
17
- var currentHash = status.currentHash,
18
- previousHash = status.previousHash;
19
- var isInitial = currentHash.indexOf( /** @type {string} */previousHash) >= 0;
20
- if (isInitial) {
21
- return;
22
- }
23
-
24
- /**
25
- * @param {Window} rootWindow
26
- * @param {number} intervalId
27
- */
28
- function applyReload(rootWindow, intervalId) {
29
- clearInterval(intervalId);
30
- log.info("App updated. Reloading...");
31
- rootWindow.location.reload();
32
- }
33
- var search = self.location.search.toLowerCase();
34
- var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
35
- var allowToLiveReload = search.indexOf("webpack-dev-server-live-reload=false") === -1;
36
- if (hot && allowToHot) {
37
- log.info("App hot update...");
38
- hotEmitter.emit("webpackHotUpdate", status.currentHash);
39
- if (typeof self !== "undefined" && self.window) {
40
- // broadcast update to window
41
- self.postMessage("webpackHotUpdate".concat(status.currentHash), "*");
42
- }
43
- }
44
- // allow refreshing the page only if liveReload isn't disabled
45
- else if (liveReload && allowToLiveReload) {
46
- var rootWindow = self;
47
-
48
- // use parent window for reload (in case we're in an iframe with no valid src)
49
- var intervalId = self.setInterval(function () {
50
- if (rootWindow.location.protocol !== "about:") {
51
- // reload immediately if protocol is valid
52
- applyReload(rootWindow, intervalId);
53
- } else {
54
- rootWindow = rootWindow.parent;
55
- if (rootWindow.parent === rootWindow) {
56
- // if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
57
- applyReload(rootWindow, intervalId);
58
- }
59
- }
60
- });
61
- }
62
- }
63
- export default reloadApp;
@@ -1,18 +0,0 @@
1
- var ansiRegex = new RegExp(["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|"), "g");
2
-
3
- /**
4
- *
5
- * Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
6
- * Adapted from code originally released by Sindre Sorhus
7
- * Licensed the MIT License
8
- *
9
- * @param {string} string
10
- * @return {string}
11
- */
12
- function stripAnsi(string) {
13
- if (typeof string !== "string") {
14
- throw new TypeError("Expected a `string`, got `".concat(typeof string, "`"));
15
- }
16
- return string.replace(ansiRegex, "");
17
- }
18
- export default stripAnsi;