webpack-dev-server 4.5.0 → 4.7.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,9 +1,76 @@
1
- import url from "url"; // We handle legacy API that is Node.js specific, and a newer API that implements the same WHATWG URL Standard used by web browsers
2
- // Please look at https://nodejs.org/api/url.html#url_url_strings_and_url_objects
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
+
8
+ if (protocol && protocol.substr(-1) !== ":") {
9
+ protocol += ":";
10
+ }
11
+
12
+ var auth = objURL.auth || "";
13
+
14
+ if (auth) {
15
+ auth = encodeURIComponent(auth);
16
+ auth = auth.replace(/%3A/i, ":");
17
+ auth += "@";
18
+ }
19
+
20
+ var host = "";
21
+
22
+ if (objURL.hostname) {
23
+ host = auth + (objURL.hostname.indexOf(":") === -1 ? objURL.hostname : "[".concat(objURL.hostname, "]"));
24
+
25
+ if (objURL.port) {
26
+ host += ":".concat(objURL.port);
27
+ }
28
+ }
29
+
30
+ var pathname = objURL.pathname || "";
31
+
32
+ if (objURL.slashes) {
33
+ host = "//".concat(host || "");
34
+
35
+ if (pathname && pathname.charAt(0) !== "/") {
36
+ pathname = "/".concat(pathname);
37
+ }
38
+ } else if (!host) {
39
+ host = "";
40
+ }
41
+
42
+ var search = objURL.search || "";
43
+
44
+ if (search && search.charAt(0) !== "?") {
45
+ search = "?".concat(search);
46
+ }
47
+
48
+ var hash = objURL.hash || "";
49
+
50
+ if (hash && hash.charAt(0) !== "#") {
51
+ hash = "#".concat(hash);
52
+ }
53
+
54
+ pathname = pathname.replace(/[?#]/g,
55
+ /**
56
+ * @param {string} match
57
+ * @returns {string}
58
+ */
59
+ function (match) {
60
+ return encodeURIComponent(match);
61
+ });
62
+ search = search.replace("#", "%23");
63
+ return "".concat(protocol).concat(host).concat(pathname).concat(search).concat(hash);
64
+ }
65
+ /**
66
+ * @param {URL & { fromCurrentScript?: boolean }} parsedURL
67
+ * @returns {string}
68
+ */
69
+
3
70
 
4
71
  function createSocketURL(parsedURL) {
5
72
  var hostname = parsedURL.hostname; // Node.js module parses it as `::`
6
- // `new URL(urlString, [baseURLstring])` parses it as '[::]'
73
+ // `new URL(urlString, [baseURLString])` parses it as '[::]'
7
74
 
8
75
  var isInAddrAny = hostname === "0.0.0.0" || hostname === "::" || hostname === "[::]"; // why do we need this check?
9
76
  // hostname n/a for file protocol (example, when using electron, ionic)
@@ -57,7 +124,7 @@ function createSocketURL(parsedURL) {
57
124
  socketURLPathname = parsedURL.pathname;
58
125
  }
59
126
 
60
- return url.format({
127
+ return format({
61
128
  protocol: socketURLProtocol,
62
129
  auth: socketURLAuth,
63
130
  hostname: socketURLHostname,
@@ -1,3 +1,6 @@
1
+ /**
2
+ * @returns {string}
3
+ */
1
4
  function getCurrentScriptSource() {
2
5
  // `document.currentScript` is the most accurate way to find the current script,
3
6
  // but is not supported in all browsers.
@@ -2,7 +2,12 @@ import logger from "../modules/logger/index.js";
2
2
  var name = "webpack-dev-server"; // default level is set on the client side, so it does not need
3
3
  // to be set by the CLI or API
4
4
 
5
- var defaultLevel = "info";
5
+ var defaultLevel = "info"; // options new options, merge with old options
6
+
7
+ /**
8
+ * @param {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} level
9
+ * @returns {void}
10
+ */
6
11
 
7
12
  function setLogLevel(level) {
8
13
  logger.configureDefaultLogger({
@@ -1,7 +1,11 @@
1
- import url from "url";
2
1
  import getCurrentScriptSource from "./getCurrentScriptSource.js";
2
+ /**
3
+ * @param {string} resourceQuery
4
+ * @returns {{ [key: string]: string | boolean }}
5
+ */
3
6
 
4
7
  function parseURL(resourceQuery) {
8
+ /** @type {{ [key: string]: string }} */
5
9
  var options = {};
6
10
 
7
11
  if (typeof resourceQuery === "string" && resourceQuery !== "") {
@@ -14,25 +18,19 @@ function parseURL(resourceQuery) {
14
18
  } else {
15
19
  // Else, get the url from the <script> this file was called with.
16
20
  var scriptSource = getCurrentScriptSource();
21
+ var scriptSourceURL;
22
+
23
+ try {
24
+ // The placeholder `baseURL` with `window.location.href`,
25
+ // is to allow parsing of path-relative or protocol-relative URLs,
26
+ // and will have no effect if `scriptSource` is a fully valid URL.
27
+ scriptSourceURL = new URL(scriptSource, self.location.href);
28
+ } catch (error) {// URL parsing failed, do nothing.
29
+ // We will still proceed to see if we can recover using `resourceQuery`
30
+ }
17
31
 
18
- if (scriptSource) {
19
- var scriptSourceURL;
20
-
21
- try {
22
- // The placeholder `baseURL` with `window.location.href`,
23
- // is to allow parsing of path-relative or protocol-relative URLs,
24
- // and will have no effect if `scriptSource` is a fully valid URL.
25
- scriptSourceURL = new URL(scriptSource, self.location.href);
26
- } catch (error) {// URL parsing failed, do nothing.
27
- // We will still proceed to see if we can recover using `resourceQuery`
28
- }
29
-
30
- if (scriptSourceURL) {
31
- options = scriptSourceURL;
32
- options.fromCurrentScript = true;
33
- }
34
- } else {
35
- options = url.parse(self.location.href, true, true);
32
+ if (scriptSourceURL) {
33
+ options = scriptSourceURL;
36
34
  options.fromCurrentScript = true;
37
35
  }
38
36
  }
@@ -1,6 +1,12 @@
1
- /* global __webpack_hash__ */
2
1
  import hotEmitter from "webpack/hot/emitter.js";
3
2
  import { log } from "./log.js";
3
+ /** @typedef {import("../index").Options} Options
4
+ /** @typedef {import("../index").Status} Status
5
+
6
+ /**
7
+ * @param {Options} options
8
+ * @param {Status} status
9
+ */
4
10
 
5
11
  function reloadApp(_ref, status) {
6
12
  var hot = _ref.hot,
@@ -12,11 +18,18 @@ function reloadApp(_ref, status) {
12
18
 
13
19
  var currentHash = status.currentHash,
14
20
  previousHash = status.previousHash;
15
- var isInitial = currentHash.indexOf(previousHash) >= 0;
21
+ var isInitial = currentHash.indexOf(
22
+ /** @type {string} */
23
+ previousHash) >= 0;
16
24
 
17
25
  if (isInitial) {
18
26
  return;
19
27
  }
28
+ /**
29
+ * @param {Window} rootWindow
30
+ * @param {number} intervalId
31
+ */
32
+
20
33
 
21
34
  function applyReload(rootWindow, intervalId) {
22
35
  clearInterval(intervalId);
@@ -1,5 +1,10 @@
1
1
  /* global __resourceQuery WorkerGlobalScope */
2
2
  // Send messages to the outside, so plugins can consume it.
3
+
4
+ /**
5
+ * @param {string} type
6
+ * @param {any} [data]
7
+ */
3
8
  function sendMsg(type, data) {
4
9
  if (typeof self !== "undefined" && (typeof WorkerGlobalScope === "undefined" || !(self instanceof WorkerGlobalScope))) {
5
10
  self.postMessage({