From aa424feeadfec93df9e6513ac823be5c4318c242 Mon Sep 17 00:00:00 2001 From: Create or Update Pull Request Action Date: Wed, 14 Jan 2026 22:43:49 +0000 Subject: [PATCH] docs: update external docs --- .../client.test.js.snap.webpack5 | 28 +- tmp-client/clients/WebSocketClient.js | 57 ++ tmp-client/index.js | 630 +++++++++++++ tmp-client/modules/logger/index.js | 831 ++++++++++++++++++ tmp-client/overlay.js | 665 ++++++++++++++ tmp-client/progress.js | 152 ++++ tmp-client/socket.js | 74 ++ tmp-client/utils/log.js | 19 + tmp-client/utils/sendMessage.js | 18 + 9 files changed, 2468 insertions(+), 6 deletions(-) create mode 100644 tmp-client/clients/WebSocketClient.js create mode 100644 tmp-client/index.js create mode 100644 tmp-client/modules/logger/index.js create mode 100644 tmp-client/overlay.js create mode 100644 tmp-client/progress.js create mode 100644 tmp-client/socket.js create mode 100644 tmp-client/utils/log.js create mode 100644 tmp-client/utils/sendMessage.js diff --git a/test/e2e/__snapshots__/client.test.js.snap.webpack5 b/test/e2e/__snapshots__/client.test.js.snap.webpack5 index 142b64205d..9a9eaed7be 100644 --- a/test/e2e/__snapshots__/client.test.js.snap.webpack5 +++ b/test/e2e/__snapshots__/client.test.js.snap.webpack5 @@ -1,21 +1,37 @@ // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing -exports[`client option configure client entry should disable client entry: console messages 1`] = `[]`; +exports[`client option configure client entry should disable client entry: console messages 1`] = ` +[ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; exports[`client option configure client entry should disable client entry: page errors 1`] = `[]`; exports[`client option configure client entry should disable client entry: response status 1`] = `200`; -exports[`client option default behaviour responds with a 200 status code for /ws path: console messages 1`] = `[]`; +exports[`client option configure client entry should disable client entry: webSockets 1`] = `[]`; -exports[`client option default behaviour responds with a 200 status code for /ws path: page errors 1`] = `[]`; +exports[`client option default behaviour responds with a 200 status code for / path: console messages 1`] = ` +[ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; -exports[`client option default behaviour responds with a 200 status code for /ws path: response status 1`] = `200`; +exports[`client option default behaviour responds with a 200 status code for / path: page errors 1`] = `[]`; + +exports[`client option default behaviour responds with a 200 status code for / path: response status 1`] = `404`; + +exports[`client option default behaviour responds with a 200 status code for / path: webSockets 1`] = `[]`; exports[`client option override client entry should disable client entry: response status 1`] = `200`; -exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: console messages 1`] = `[]`; +exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: console messages 1`] = ` +[ + "Failed to load resource: the server responded with a status of 404 (Not Found)", +] +`; exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: page errors 1`] = `[]`; -exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: response status 1`] = `200`; +exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: webSockets 1`] = `[]`; diff --git a/tmp-client/clients/WebSocketClient.js b/tmp-client/clients/WebSocketClient.js new file mode 100644 index 0000000000..6f33f11ed6 --- /dev/null +++ b/tmp-client/clients/WebSocketClient.js @@ -0,0 +1,57 @@ +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); } +function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } +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); } } +function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +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); } +import { log } from "../utils/log.js"; + +/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */ + +/** + * @implements {CommunicationClient} + */ +var WebSocketClient = /*#__PURE__*/function () { + /** + * @param {string} url url to connect + */ + function WebSocketClient(url) { + _classCallCheck(this, WebSocketClient); + this.client = new WebSocket(url); + this.client.onerror = function (error) { + log.error(error); + }; + } + + /** + * @param {(...args: EXPECTED_ANY[]) => void} fn function + */ + return _createClass(WebSocketClient, [{ + key: "onOpen", + value: function onOpen(fn) { + this.client.onopen = fn; + } + + /** + * @param {(...args: EXPECTED_ANY[]) => void} fn function + */ + }, { + key: "onClose", + value: function onClose(fn) { + this.client.onclose = fn; + } + + // call f with the message string as the first argument + /** + * @param {(...args: EXPECTED_ANY[]) => void} fn function + */ + }, { + key: "onMessage", + value: function onMessage(fn) { + this.client.onmessage = function (err) { + fn(err.data); + }; + } + }]); +}(); +export { WebSocketClient as default }; \ No newline at end of file diff --git a/tmp-client/index.js b/tmp-client/index.js new file mode 100644 index 0000000000..e71c5b6449 --- /dev/null +++ b/tmp-client/index.js @@ -0,0 +1,630 @@ +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; } +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; } +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; } +function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } +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); } +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); } +/* global __resourceQuery, __webpack_hash__ */ +// @ts-expect-error +import hotEmitter from "webpack/hot/emitter.js"; +// @ts-expect-error +import webpackHotLog from "webpack/hot/log.js"; +import { createOverlay, formatProblem } from "./overlay.js"; +import { defineProgressElement, isProgressSupported } from "./progress.js"; +import socket from "./socket.js"; +import { log, setLogLevel } from "./utils/log.js"; +import sendMessage from "./utils/sendMessage.js"; + +// eslint-disable-next-line jsdoc/no-restricted-syntax +/** @typedef {any} EXPECTED_ANY */ + +/** + * @typedef {object} RawOverlayOptions + * @property {string=} warnings warnings + * @property {string=} errors errors + * @property {string=} runtimeErrors runtime errors + * @property {string=} trustedTypesPolicyName trusted types policy name + */ + +/** + * @typedef {object} OverlayOptions + * @property {(boolean | ((error: Error) => boolean))=} warnings warnings + * @property {(boolean | ((error: Error) => boolean))=} errors errors + * @property {(boolean | ((error: Error) => boolean))=} runtimeErrors runtime errors + * @property {string=} trustedTypesPolicyName trusted types policy name + */ + +/** @typedef {false | true | "none" | "error" | "warn" | "info" | "log" | "verbose"} LogLevel */ + +/** + * @typedef {object} Options + * @property {boolean} hot true when hot enabled, otherwise false + * @property {boolean} liveReload true when live reload enabled, otherwise false + * @property {boolean} progress true when need to show progress, otherwise false + * @property {boolean | OverlayOptions} overlay overlay options + * @property {LogLevel=} logging logging level + * @property {number=} reconnect count of allowed reconnection + */ + +/** + * @typedef {object} Status + * @property {boolean} isUnloading true when unloaded, otherwise false + * @property {string} currentHash current hash + * @property {string=} previousHash previous hash + */ + +/** + * @param {boolean | RawOverlayOptions | OverlayOptions} overlayOptions overlay options + */ +var decodeOverlayOptions = function decodeOverlayOptions(overlayOptions) { + if (_typeof(overlayOptions) === "object") { + var requiredOptions = ["warnings", "errors", "runtimeErrors"]; + for (var i = 0; i < requiredOptions.length; i++) { + var property = /** @type {keyof Omit} */ + requiredOptions[i]; + if (typeof overlayOptions[property] === "string") { + var overlayFilterFunctionString = decodeURIComponent(overlayOptions[property]); + + /** @type {OverlayOptions} */ + overlayOptions[property] = /** @type {(error: Error) => boolean} */ + // eslint-disable-next-line no-new-func + new Function("message", "var callback = ".concat(overlayFilterFunctionString, "\n return callback(message)")); + } + } + } +}; + +/** + * @type {Status} + */ +var status = { + isUnloading: false, + currentHash: __webpack_hash__ +}; + +/** + * @returns {string} current script source + */ +var getCurrentScriptSource = function getCurrentScriptSource() { + // `document.currentScript` is the most accurate way to find the current script, + // but is not supported in all browsers. + if (document.currentScript) { + return /** @type {string} */document.currentScript.getAttribute("src"); + } + + // Fallback to getting all scripts running in the document. + var scriptElements = document.scripts || []; + var scriptElementsWithSrc = Array.prototype.filter.call(scriptElements, function (element) { + return element.getAttribute("src"); + }); + if (scriptElementsWithSrc.length > 0) { + var currentScript = scriptElementsWithSrc[scriptElementsWithSrc.length - 1]; + return currentScript.getAttribute("src"); + } + + // Fail as there was no script to use. + throw new Error("[webpack-dev-server] Failed to get current script source."); +}; + +/** @typedef {{ hot?: string, ["live-reload"]?: string, progress?: string, reconnect?: string, logging?: LogLevel, overlay?: string, fromCurrentScript?: boolean }} AdditionalParsedURL */ +/** @typedef {Partial & AdditionalParsedURL} ParsedURL */ + +/** + * @param {string} resourceQuery resource query + * @returns {ParsedURL} parsed URL + */ +var parseURL = function parseURL(resourceQuery) { + /** @type {ParsedURL} */ + var result = {}; + if (typeof resourceQuery === "string" && resourceQuery !== "") { + var searchParams = resourceQuery.slice(1).split("&"); + for (var i = 0; i < searchParams.length; i++) { + var pair = searchParams[i].split("="); + + /** @type {EXPECTED_ANY} */ + result[pair[0]] = decodeURIComponent(pair[1]); + } + } else { + // Else, get the url from the