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.
- package/README.md +1 -1
- package/client/clients/SockJSClient.js +7 -7
- package/client/clients/WebSocketClient.js +7 -7
- package/client/index.js +303 -23
- package/client/modules/logger/index.js +240 -133
- package/client/modules/sockjs-client/index.js +18 -12
- package/client/overlay.js +365 -18
- package/client/progress.js +125 -0
- package/client/socket.js +5 -1
- package/client/utils/log.js +1 -17
- package/lib/Server.js +831 -479
- package/lib/options.json +23 -5
- package/package.json +37 -36
- package/types/bin/cli-flags.d.ts +15 -0
- package/types/lib/Server.d.ts +216 -339
- package/types/lib/servers/WebsocketServer.d.ts +0 -1
- package/client/overlay/fsm.js +0 -64
- package/client/overlay/runtime-error.js +0 -47
- package/client/overlay/state-machine.js +0 -100
- package/client/overlay/styles.js +0 -74
- package/client/utils/createSocketURL.js +0 -121
- package/client/utils/getCurrentScriptSource.js +0 -24
- package/client/utils/parseURL.js +0 -36
- package/client/utils/reloadApp.js +0 -63
- package/client/utils/stripAnsi.js +0 -18
package/README.md
CHANGED
|
@@ -190,7 +190,7 @@ CLI documentation: https://webpack.js.org/api/cli/.
|
|
|
190
190
|
Made with ♥ by the webpack team.
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
>
|
|
193
|
+
> [!NOTE]
|
|
194
194
|
>
|
|
195
195
|
> _Detailed documentation for above options is available on this [link](https://webpack.js.org/configuration/dev-server/)._
|
|
196
196
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
function
|
|
3
|
-
function
|
|
4
|
-
function
|
|
5
|
-
function
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
3
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
4
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
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
|
import SockJS from "../modules/sockjs-client/index.js";
|
|
7
8
|
import { log } from "../utils/log.js";
|
|
8
9
|
var SockJSClient = /*#__PURE__*/function () {
|
|
@@ -25,7 +26,7 @@ var SockJSClient = /*#__PURE__*/function () {
|
|
|
25
26
|
/**
|
|
26
27
|
* @param {(...args: any[]) => void} f
|
|
27
28
|
*/
|
|
28
|
-
_createClass(SockJSClient, [{
|
|
29
|
+
return _createClass(SockJSClient, [{
|
|
29
30
|
key: "onOpen",
|
|
30
31
|
value: function onOpen(f) {
|
|
31
32
|
this.sock.onopen = f;
|
|
@@ -56,6 +57,5 @@ var SockJSClient = /*#__PURE__*/function () {
|
|
|
56
57
|
};
|
|
57
58
|
}
|
|
58
59
|
}]);
|
|
59
|
-
return SockJSClient;
|
|
60
60
|
}();
|
|
61
61
|
export { SockJSClient as default };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
function
|
|
3
|
-
function
|
|
4
|
-
function
|
|
5
|
-
function
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
|
|
3
|
+
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
|
|
4
|
+
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
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
|
import { log } from "../utils/log.js";
|
|
7
8
|
var WebSocketClient = /*#__PURE__*/function () {
|
|
8
9
|
/**
|
|
@@ -19,7 +20,7 @@ var WebSocketClient = /*#__PURE__*/function () {
|
|
|
19
20
|
/**
|
|
20
21
|
* @param {(...args: any[]) => void} f
|
|
21
22
|
*/
|
|
22
|
-
_createClass(WebSocketClient, [{
|
|
23
|
+
return _createClass(WebSocketClient, [{
|
|
23
24
|
key: "onOpen",
|
|
24
25
|
value: function onOpen(f) {
|
|
25
26
|
this.client.onopen = f;
|
|
@@ -46,6 +47,5 @@ var WebSocketClient = /*#__PURE__*/function () {
|
|
|
46
47
|
};
|
|
47
48
|
}
|
|
48
49
|
}]);
|
|
49
|
-
return WebSocketClient;
|
|
50
50
|
}();
|
|
51
51
|
export { WebSocketClient as default };
|
package/client/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
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
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(
|
|
4
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" ==
|
|
5
|
-
function _toPrimitive(t, r) { if ("object" !=
|
|
3
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
7
|
/* global __resourceQuery, __webpack_hash__ */
|
|
7
8
|
/// <reference types="webpack/module" />
|
|
8
9
|
import webpackHotLog from "webpack/hot/log.js";
|
|
9
|
-
import
|
|
10
|
-
import parseURL from "./utils/parseURL.js";
|
|
10
|
+
import hotEmitter from "webpack/hot/emitter.js";
|
|
11
11
|
import socket from "./socket.js";
|
|
12
12
|
import { formatProblem, createOverlay } from "./overlay.js";
|
|
13
|
-
import { log,
|
|
13
|
+
import { log, setLogLevel } from "./utils/log.js";
|
|
14
14
|
import sendMessage from "./utils/sendMessage.js";
|
|
15
|
-
import
|
|
16
|
-
import createSocketURL from "./utils/createSocketURL.js";
|
|
15
|
+
import { isProgressSupported, defineProgressElement } from "./progress.js";
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* @typedef {Object} OverlayOptions
|
|
@@ -44,14 +43,13 @@ import createSocketURL from "./utils/createSocketURL.js";
|
|
|
44
43
|
* @param {boolean | { warnings?: boolean | string; errors?: boolean | string; runtimeErrors?: boolean | string; }} overlayOptions
|
|
45
44
|
*/
|
|
46
45
|
var decodeOverlayOptions = function decodeOverlayOptions(overlayOptions) {
|
|
47
|
-
if (
|
|
46
|
+
if (_typeof(overlayOptions) === "object") {
|
|
48
47
|
["warnings", "errors", "runtimeErrors"].forEach(function (property) {
|
|
49
48
|
if (typeof overlayOptions[property] === "string") {
|
|
50
49
|
var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]);
|
|
51
50
|
|
|
52
51
|
// eslint-disable-next-line no-new-func
|
|
53
|
-
|
|
54
|
-
overlayOptions[property] = overlayFilterFunction;
|
|
52
|
+
overlayOptions[property] = new Function("message", "var callback = ".concat(overlayFilterFunctionString, "\n return callback(message)"));
|
|
55
53
|
}
|
|
56
54
|
});
|
|
57
55
|
}
|
|
@@ -66,12 +64,62 @@ var status = {
|
|
|
66
64
|
currentHash: __webpack_hash__
|
|
67
65
|
};
|
|
68
66
|
|
|
69
|
-
/**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
/**
|
|
68
|
+
* @returns {string}
|
|
69
|
+
*/
|
|
70
|
+
var getCurrentScriptSource = function getCurrentScriptSource() {
|
|
71
|
+
// `document.currentScript` is the most accurate way to find the current script,
|
|
72
|
+
// but is not supported in all browsers.
|
|
73
|
+
if (document.currentScript) {
|
|
74
|
+
return document.currentScript.getAttribute("src");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Fallback to getting all scripts running in the document.
|
|
78
|
+
var scriptElements = document.scripts || [];
|
|
79
|
+
var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) {
|
|
80
|
+
return element.getAttribute("src");
|
|
81
|
+
});
|
|
82
|
+
if (scriptElementsWithSrc.length > 0) {
|
|
83
|
+
var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1];
|
|
84
|
+
return currentScript.getAttribute("src");
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Fail as there was no script to use.
|
|
88
|
+
throw new Error("[webpack-dev-server] Failed to get current script source.");
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* @param {string} resourceQuery
|
|
93
|
+
* @returns {{ [key: string]: string | boolean }}
|
|
94
|
+
*/
|
|
95
|
+
var parseURL = function parseURL(resourceQuery) {
|
|
96
|
+
/** @type {{ [key: string]: string }} */
|
|
97
|
+
var result = {};
|
|
98
|
+
if (typeof resourceQuery === "string" && resourceQuery !== "") {
|
|
99
|
+
var searchParams = resourceQuery.slice(1).split("&");
|
|
100
|
+
for (var i = 0; i < searchParams.length; i++) {
|
|
101
|
+
var pair = searchParams[i].split("=");
|
|
102
|
+
result[pair[0]] = decodeURIComponent(pair[1]);
|
|
103
|
+
}
|
|
104
|
+
} else {
|
|
105
|
+
// Else, get the url from the <script> this file was called with.
|
|
106
|
+
var scriptSource = getCurrentScriptSource();
|
|
107
|
+
var scriptSourceURL;
|
|
108
|
+
try {
|
|
109
|
+
// The placeholder `baseURL` with `window.location.href`,
|
|
110
|
+
// is to allow parsing of path-relative or protocol-relative URLs,
|
|
111
|
+
// and will have no effect if `scriptSource` is a fully valid URL.
|
|
112
|
+
scriptSourceURL = new URL(scriptSource, self.location.href);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// URL parsing failed, do nothing.
|
|
115
|
+
// We will still proceed to see if we can recover using `resourceQuery`
|
|
116
|
+
}
|
|
117
|
+
if (scriptSourceURL) {
|
|
118
|
+
result = scriptSourceURL;
|
|
119
|
+
result.fromCurrentScript = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
75
123
|
};
|
|
76
124
|
var parsedResourceQuery = parseURL(__resourceQuery);
|
|
77
125
|
var enabledFeatures = {
|
|
@@ -80,6 +128,14 @@ var enabledFeatures = {
|
|
|
80
128
|
Progress: false,
|
|
81
129
|
Overlay: false
|
|
82
130
|
};
|
|
131
|
+
|
|
132
|
+
/** @type {Options} */
|
|
133
|
+
var options = {
|
|
134
|
+
hot: false,
|
|
135
|
+
liveReload: false,
|
|
136
|
+
progress: false,
|
|
137
|
+
overlay: false
|
|
138
|
+
};
|
|
83
139
|
if (parsedResourceQuery.hot === "true") {
|
|
84
140
|
options.hot = true;
|
|
85
141
|
enabledFeatures["Hot Module Replacement"] = true;
|
|
@@ -100,7 +156,7 @@ if (parsedResourceQuery.overlay) {
|
|
|
100
156
|
}
|
|
101
157
|
|
|
102
158
|
// Fill in default "true" params for partially-specified objects.
|
|
103
|
-
if (
|
|
159
|
+
if (_typeof(options.overlay) === "object") {
|
|
104
160
|
options.overlay = _objectSpread({
|
|
105
161
|
errors: true,
|
|
106
162
|
warnings: true,
|
|
@@ -108,7 +164,7 @@ if (parsedResourceQuery.overlay) {
|
|
|
108
164
|
}, options.overlay);
|
|
109
165
|
decodeOverlayOptions(options.overlay);
|
|
110
166
|
}
|
|
111
|
-
enabledFeatures.Overlay =
|
|
167
|
+
enabledFeatures.Overlay = options.overlay !== false;
|
|
112
168
|
}
|
|
113
169
|
if (parsedResourceQuery.logging) {
|
|
114
170
|
options.logging = parsedResourceQuery.logging;
|
|
@@ -120,19 +176,35 @@ if (typeof parsedResourceQuery.reconnect !== "undefined") {
|
|
|
120
176
|
/**
|
|
121
177
|
* @param {string} level
|
|
122
178
|
*/
|
|
123
|
-
function setAllLogLevel(level) {
|
|
179
|
+
var setAllLogLevel = function setAllLogLevel(level) {
|
|
124
180
|
// This is needed because the HMR logger operate separately from dev server logger
|
|
125
181
|
webpackHotLog.setLogLevel(level === "verbose" || level === "log" ? "info" : level);
|
|
126
182
|
setLogLevel(level);
|
|
127
|
-
}
|
|
183
|
+
};
|
|
128
184
|
if (options.logging) {
|
|
129
185
|
setAllLogLevel(options.logging);
|
|
130
186
|
}
|
|
187
|
+
var logEnabledFeatures = function logEnabledFeatures(features) {
|
|
188
|
+
var listEnabledFeatures = Object.keys(features);
|
|
189
|
+
if (!features || listEnabledFeatures.length === 0) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
var logString = "Server started:";
|
|
193
|
+
|
|
194
|
+
// Server started: Hot Module Replacement enabled, Live Reloading enabled, Overlay disabled.
|
|
195
|
+
for (var i = 0; i < listEnabledFeatures.length; i++) {
|
|
196
|
+
var key = listEnabledFeatures[i];
|
|
197
|
+
logString += " ".concat(key, " ").concat(features[key] ? "enabled" : "disabled", ",");
|
|
198
|
+
}
|
|
199
|
+
// replace last comma with a period
|
|
200
|
+
logString = logString.slice(0, -1).concat(".");
|
|
201
|
+
log.info(logString);
|
|
202
|
+
};
|
|
131
203
|
logEnabledFeatures(enabledFeatures);
|
|
132
204
|
self.addEventListener("beforeunload", function () {
|
|
133
205
|
status.isUnloading = true;
|
|
134
206
|
});
|
|
135
|
-
var overlay = typeof window !== "undefined" ? createOverlay(
|
|
207
|
+
var overlay = typeof window !== "undefined" ? createOverlay(_typeof(options.overlay) === "object" ? {
|
|
136
208
|
trustedTypesPolicyName: options.overlay.trustedTypesPolicyName,
|
|
137
209
|
catchRuntimeError: options.overlay.runtimeErrors
|
|
138
210
|
} : {
|
|
@@ -141,6 +213,80 @@ var overlay = typeof window !== "undefined" ? createOverlay(typeof options.overl
|
|
|
141
213
|
}) : {
|
|
142
214
|
send: function send() {}
|
|
143
215
|
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @param {Options} options
|
|
219
|
+
* @param {Status} currentStatus
|
|
220
|
+
*/
|
|
221
|
+
var reloadApp = function reloadApp(_ref, currentStatus) {
|
|
222
|
+
var hot = _ref.hot,
|
|
223
|
+
liveReload = _ref.liveReload;
|
|
224
|
+
if (currentStatus.isUnloading) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
var currentHash = currentStatus.currentHash,
|
|
228
|
+
previousHash = currentStatus.previousHash;
|
|
229
|
+
var isInitial = currentHash.indexOf(/** @type {string} */previousHash) >= 0;
|
|
230
|
+
if (isInitial) {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* @param {Window} rootWindow
|
|
236
|
+
* @param {number} intervalId
|
|
237
|
+
*/
|
|
238
|
+
function applyReload(rootWindow, intervalId) {
|
|
239
|
+
clearInterval(intervalId);
|
|
240
|
+
log.info("App updated. Reloading...");
|
|
241
|
+
rootWindow.location.reload();
|
|
242
|
+
}
|
|
243
|
+
var search = self.location.search.toLowerCase();
|
|
244
|
+
var allowToHot = search.indexOf("webpack-dev-server-hot=false") === -1;
|
|
245
|
+
var allowToLiveReload = search.indexOf("webpack-dev-server-live-reload=false") === -1;
|
|
246
|
+
if (hot && allowToHot) {
|
|
247
|
+
log.info("App hot update...");
|
|
248
|
+
hotEmitter.emit("webpackHotUpdate", currentStatus.currentHash);
|
|
249
|
+
if (typeof self !== "undefined" && self.window) {
|
|
250
|
+
// broadcast update to window
|
|
251
|
+
self.postMessage("webpackHotUpdate".concat(currentStatus.currentHash), "*");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// allow refreshing the page only if liveReload isn't disabled
|
|
255
|
+
else if (liveReload && allowToLiveReload) {
|
|
256
|
+
var rootWindow = self;
|
|
257
|
+
|
|
258
|
+
// use parent window for reload (in case we're in an iframe with no valid src)
|
|
259
|
+
var intervalId = self.setInterval(function () {
|
|
260
|
+
if (rootWindow.location.protocol !== "about:") {
|
|
261
|
+
// reload immediately if protocol is valid
|
|
262
|
+
applyReload(rootWindow, intervalId);
|
|
263
|
+
} else {
|
|
264
|
+
rootWindow = rootWindow.parent;
|
|
265
|
+
if (rootWindow.parent === rootWindow) {
|
|
266
|
+
// if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
|
|
267
|
+
applyReload(rootWindow, intervalId);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
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");
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* Strip [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) from a string.
|
|
278
|
+
* Adapted from code originally released by Sindre Sorhus
|
|
279
|
+
* Licensed the MIT License
|
|
280
|
+
*
|
|
281
|
+
* @param {string} string
|
|
282
|
+
* @return {string}
|
|
283
|
+
*/
|
|
284
|
+
var stripAnsi = function stripAnsi(string) {
|
|
285
|
+
if (typeof string !== "string") {
|
|
286
|
+
throw new TypeError("Expected a `string`, got `".concat(_typeof(string), "`"));
|
|
287
|
+
}
|
|
288
|
+
return string.replace(ansiRegex, "");
|
|
289
|
+
};
|
|
144
290
|
var onSocketMessage = {
|
|
145
291
|
hot: function hot() {
|
|
146
292
|
if (parsedResourceQuery.hot === "false") {
|
|
@@ -205,6 +351,18 @@ var onSocketMessage = {
|
|
|
205
351
|
if (options.progress) {
|
|
206
352
|
log.info("".concat(data.pluginName ? "[".concat(data.pluginName, "] ") : "").concat(data.percent, "% - ").concat(data.msg, "."));
|
|
207
353
|
}
|
|
354
|
+
if (isProgressSupported()) {
|
|
355
|
+
if (typeof options.progress === "string") {
|
|
356
|
+
var progress = document.querySelector("wds-progress");
|
|
357
|
+
if (!progress) {
|
|
358
|
+
defineProgressElement();
|
|
359
|
+
progress = document.createElement("wds-progress");
|
|
360
|
+
document.body.appendChild(progress);
|
|
361
|
+
}
|
|
362
|
+
progress.setAttribute("progress", data.percent);
|
|
363
|
+
progress.setAttribute("type", options.progress);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
208
366
|
sendMessage("Progress", data);
|
|
209
367
|
},
|
|
210
368
|
"still-ok": function stillOk() {
|
|
@@ -307,5 +465,127 @@ var onSocketMessage = {
|
|
|
307
465
|
sendMessage("Close");
|
|
308
466
|
}
|
|
309
467
|
};
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* @param {{ protocol?: string, auth?: string, hostname?: string, port?: string, pathname?: string, search?: string, hash?: string, slashes?: boolean }} objURL
|
|
471
|
+
* @returns {string}
|
|
472
|
+
*/
|
|
473
|
+
var formatURL = function formatURL(objURL) {
|
|
474
|
+
var protocol = objURL.protocol || "";
|
|
475
|
+
if (protocol && protocol.substr(-1) !== ":") {
|
|
476
|
+
protocol += ":";
|
|
477
|
+
}
|
|
478
|
+
var auth = objURL.auth || "";
|
|
479
|
+
if (auth) {
|
|
480
|
+
auth = encodeURIComponent(auth);
|
|
481
|
+
auth = auth.replace(/%3A/i, ":");
|
|
482
|
+
auth += "@";
|
|
483
|
+
}
|
|
484
|
+
var host = "";
|
|
485
|
+
if (objURL.hostname) {
|
|
486
|
+
host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
|
|
487
|
+
if (objURL.port) {
|
|
488
|
+
host += ":".concat(objURL.port);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
var pathname = objURL.pathname || "";
|
|
492
|
+
if (objURL.slashes) {
|
|
493
|
+
host = "//".concat(host || "");
|
|
494
|
+
if (pathname && pathname.charAt(0) !== "/") {
|
|
495
|
+
pathname = "/".concat(pathname);
|
|
496
|
+
}
|
|
497
|
+
} else if (!host) {
|
|
498
|
+
host = "";
|
|
499
|
+
}
|
|
500
|
+
var search = objURL.search || "";
|
|
501
|
+
if (search && search.charAt(0) !== "?") {
|
|
502
|
+
search = "?".concat(search);
|
|
503
|
+
}
|
|
504
|
+
var hash = objURL.hash || "";
|
|
505
|
+
if (hash && hash.charAt(0) !== "#") {
|
|
506
|
+
hash = "#".concat(hash);
|
|
507
|
+
}
|
|
508
|
+
pathname = pathname.replace(/[?#]/g,
|
|
509
|
+
/**
|
|
510
|
+
* @param {string} match
|
|
511
|
+
* @returns {string}
|
|
512
|
+
*/
|
|
513
|
+
function (match) {
|
|
514
|
+
return encodeURIComponent(match);
|
|
515
|
+
});
|
|
516
|
+
search = search.replace("#", "%23");
|
|
517
|
+
return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
|
|
518
|
+
};
|
|
519
|
+
|
|
520
|
+
/**
|
|
521
|
+
* @param {URL & { fromCurrentScript?: boolean }} parsedURL
|
|
522
|
+
* @returns {string}
|
|
523
|
+
*/
|
|
524
|
+
var createSocketURL = function createSocketURL(parsedURL) {
|
|
525
|
+
var hostname = parsedURL.hostname;
|
|
526
|
+
|
|
527
|
+
// Node.js module parses it as `::`
|
|
528
|
+
// `new URL(urlString, [baseURLString])` parses it as '[::]'
|
|
529
|
+
var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]";
|
|
530
|
+
|
|
531
|
+
// why do we need this check?
|
|
532
|
+
// hostname n/a for file protocol (example, when using electron, ionic)
|
|
533
|
+
// see: https://github.com/webpack/webpack-dev-server/pull/384
|
|
534
|
+
if (isInAddrAny && self.location.hostname && self.location.protocol.indexOf("http") === 0) {
|
|
535
|
+
hostname = self.location.hostname;
|
|
536
|
+
}
|
|
537
|
+
var socketURLProtocol = parsedURL.protocol || self.location.protocol;
|
|
538
|
+
|
|
539
|
+
// When https is used in the app, secure web sockets are always necessary because the browser doesn't accept non-secure web sockets.
|
|
540
|
+
if (socketURLProtocol === "auto:" || hostname && isInAddrAny && self.location.protocol === "https:") {
|
|
541
|
+
socketURLProtocol = self.location.protocol;
|
|
542
|
+
}
|
|
543
|
+
socketURLProtocol = socketURLProtocol.replace(/^(?:http|.+-extension|file)/i, "ws");
|
|
544
|
+
var socketURLAuth = "";
|
|
545
|
+
|
|
546
|
+
// `new URL(urlString, [baseURLstring])` doesn't have `auth` property
|
|
547
|
+
// Parse authentication credentials in case we need them
|
|
548
|
+
if (parsedURL.username) {
|
|
549
|
+
socketURLAuth = parsedURL.username;
|
|
550
|
+
|
|
551
|
+
// Since HTTP basic authentication does not allow empty username,
|
|
552
|
+
// we only include password if the username is not empty.
|
|
553
|
+
if (parsedURL.password) {
|
|
554
|
+
// Result: <username>:<password>
|
|
555
|
+
socketURLAuth = socketURLAuth.concat(":", parsedURL.password);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// In case the host is a raw IPv6 address, it can be enclosed in
|
|
560
|
+
// the brackets as the brackets are needed in the final URL string.
|
|
561
|
+
// Need to remove those as url.format blindly adds its own set of brackets
|
|
562
|
+
// if the host string contains colons. That would lead to non-working
|
|
563
|
+
// double brackets (e.g. [[::]]) host
|
|
564
|
+
//
|
|
565
|
+
// All of these web socket url params are optionally passed in through resourceQuery,
|
|
566
|
+
// so we need to fall back to the default if they are not provided
|
|
567
|
+
var socketURLHostname = (hostname || self.location.hostname || "localhost").replace(/^\[(.*)\]$/, "$1");
|
|
568
|
+
var socketURLPort = parsedURL.port;
|
|
569
|
+
if (!socketURLPort || socketURLPort === "0") {
|
|
570
|
+
socketURLPort = self.location.port;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// If path is provided it'll be passed in via the resourceQuery as a
|
|
574
|
+
// query param so it has to be parsed out of the querystring in order for the
|
|
575
|
+
// client to open the socket to the correct location.
|
|
576
|
+
var socketURLPathname = "/ws";
|
|
577
|
+
if (parsedURL.pathname && !parsedURL.fromCurrentScript) {
|
|
578
|
+
socketURLPathname = parsedURL.pathname;
|
|
579
|
+
}
|
|
580
|
+
return formatURL({
|
|
581
|
+
protocol: socketURLProtocol,
|
|
582
|
+
auth: socketURLAuth,
|
|
583
|
+
hostname: socketURLHostname,
|
|
584
|
+
port: socketURLPort,
|
|
585
|
+
pathname: socketURLPathname,
|
|
586
|
+
slashes: true
|
|
587
|
+
});
|
|
588
|
+
};
|
|
310
589
|
var socketURL = createSocketURL(parsedResourceQuery);
|
|
311
|
-
socket(socketURL, onSocketMessage, options.reconnect);
|
|
590
|
+
socket(socketURL, onSocketMessage, options.reconnect);
|
|
591
|
+
export { getCurrentScriptSource, parseURL, createSocketURL };
|