Update package dependencies and remove unused files from node_modules
This commit is contained in:
591
node_modules/vite/dist/client/client.mjs
generated
vendored
591
node_modules/vite/dist/client/client.mjs
generated
vendored
@@ -56,19 +56,13 @@ class HMRContext {
|
||||
decline() {
|
||||
}
|
||||
invalidate(message) {
|
||||
const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
|
||||
this.hmrClient.notifyListeners("vite:invalidate", {
|
||||
path: this.ownerPath,
|
||||
message,
|
||||
firstInvalidatedBy
|
||||
});
|
||||
this.send("vite:invalidate", {
|
||||
path: this.ownerPath,
|
||||
message,
|
||||
firstInvalidatedBy
|
||||
message
|
||||
});
|
||||
this.send("vite:invalidate", { path: this.ownerPath, message });
|
||||
this.hmrClient.logger.debug(
|
||||
`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
||||
`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
||||
);
|
||||
}
|
||||
on(event, cb) {
|
||||
@@ -97,7 +91,9 @@ class HMRContext {
|
||||
removeFromMap(this.newListeners);
|
||||
}
|
||||
send(event, data) {
|
||||
this.hmrClient.send({ type: "custom", event, data });
|
||||
this.hmrClient.messenger.send(
|
||||
JSON.stringify({ type: "custom", event, data })
|
||||
);
|
||||
}
|
||||
acceptDeps(deps, callback = () => {
|
||||
}) {
|
||||
@@ -112,10 +108,25 @@ class HMRContext {
|
||||
this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
||||
}
|
||||
}
|
||||
class HMRMessenger {
|
||||
constructor(connection) {
|
||||
this.connection = connection;
|
||||
this.queue = [];
|
||||
}
|
||||
send(message) {
|
||||
this.queue.push(message);
|
||||
this.flush();
|
||||
}
|
||||
flush() {
|
||||
if (this.connection.isReady()) {
|
||||
this.queue.forEach((msg) => this.connection.send(msg));
|
||||
this.queue = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
class HMRClient {
|
||||
constructor(logger, transport, importUpdatedModule) {
|
||||
constructor(logger, connection, importUpdatedModule) {
|
||||
this.logger = logger;
|
||||
this.transport = transport;
|
||||
this.importUpdatedModule = importUpdatedModule;
|
||||
this.hotModulesMap = /* @__PURE__ */ new Map();
|
||||
this.disposeMap = /* @__PURE__ */ new Map();
|
||||
@@ -125,6 +136,7 @@ class HMRClient {
|
||||
this.ctxToListenersMap = /* @__PURE__ */ new Map();
|
||||
this.updateQueue = [];
|
||||
this.pendingUpdateQueue = false;
|
||||
this.messenger = new HMRMessenger(connection);
|
||||
}
|
||||
async notifyListeners(event, data) {
|
||||
const cbs = this.customListenersMap.get(event);
|
||||
@@ -132,11 +144,6 @@ class HMRClient {
|
||||
await Promise.allSettled(cbs.map((cb) => cb(data)));
|
||||
}
|
||||
}
|
||||
send(payload) {
|
||||
this.transport.send(payload).catch((err) => {
|
||||
this.logger.error(err);
|
||||
});
|
||||
}
|
||||
clear() {
|
||||
this.hotModulesMap.clear();
|
||||
this.disposeMap.clear();
|
||||
@@ -147,7 +154,7 @@ class HMRClient {
|
||||
}
|
||||
// After an HMR update, some modules are no longer imported on the page
|
||||
// but they may have left behind side effects that need to be cleaned up
|
||||
// (e.g. style injections)
|
||||
// (.e.g style injections)
|
||||
async prunePaths(paths) {
|
||||
await Promise.all(
|
||||
paths.map((path) => {
|
||||
@@ -163,11 +170,11 @@ class HMRClient {
|
||||
});
|
||||
}
|
||||
warnFailedUpdate(err, path) {
|
||||
if (!(err instanceof Error) || !err.message.includes("fetch")) {
|
||||
if (!err.message.includes("fetch")) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
this.logger.error(
|
||||
`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
||||
`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
||||
);
|
||||
}
|
||||
/**
|
||||
@@ -187,7 +194,7 @@ class HMRClient {
|
||||
}
|
||||
}
|
||||
async fetchUpdate(update) {
|
||||
const { path, acceptedPath, firstInvalidatedBy } = update;
|
||||
const { path, acceptedPath } = update;
|
||||
const mod = this.hotModulesMap.get(path);
|
||||
if (!mod) {
|
||||
return;
|
||||
@@ -207,317 +214,14 @@ class HMRClient {
|
||||
}
|
||||
}
|
||||
return () => {
|
||||
try {
|
||||
this.currentFirstInvalidatedBy = firstInvalidatedBy;
|
||||
for (const { deps, fn } of qualifiedCallbacks) {
|
||||
fn(
|
||||
deps.map(
|
||||
(dep) => dep === acceptedPath ? fetchedModule : void 0
|
||||
)
|
||||
);
|
||||
}
|
||||
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
||||
this.logger.debug(`hot updated: ${loggedPath}`);
|
||||
} finally {
|
||||
this.currentFirstInvalidatedBy = void 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* @ts-self-types="./index.d.ts" */
|
||||
let urlAlphabet =
|
||||
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
||||
let nanoid = (size = 21) => {
|
||||
let id = '';
|
||||
let i = size | 0;
|
||||
while (i--) {
|
||||
id += urlAlphabet[(Math.random() * 64) | 0];
|
||||
}
|
||||
return id
|
||||
};
|
||||
|
||||
typeof process !== "undefined" && process.platform === "win32";
|
||||
function promiseWithResolvers() {
|
||||
let resolve;
|
||||
let reject;
|
||||
const promise = new Promise((_resolve, _reject) => {
|
||||
resolve = _resolve;
|
||||
reject = _reject;
|
||||
});
|
||||
return { promise, resolve, reject };
|
||||
}
|
||||
|
||||
function reviveInvokeError(e) {
|
||||
const error = new Error(e.message || "Unknown invoke error");
|
||||
Object.assign(error, e, {
|
||||
// pass the whole error instead of just the stacktrace
|
||||
// so that it gets formatted nicely with console.log
|
||||
runnerError: new Error("RunnerError")
|
||||
});
|
||||
return error;
|
||||
}
|
||||
const createInvokeableTransport = (transport) => {
|
||||
if (transport.invoke) {
|
||||
return {
|
||||
...transport,
|
||||
async invoke(name, data) {
|
||||
const result = await transport.invoke({
|
||||
type: "custom",
|
||||
event: "vite:invoke",
|
||||
data: {
|
||||
id: "send",
|
||||
name,
|
||||
data
|
||||
}
|
||||
});
|
||||
if ("error" in result) {
|
||||
throw reviveInvokeError(result.error);
|
||||
}
|
||||
return result.result;
|
||||
}
|
||||
};
|
||||
}
|
||||
if (!transport.send || !transport.connect) {
|
||||
throw new Error(
|
||||
"transport must implement send and connect when invoke is not implemented"
|
||||
);
|
||||
}
|
||||
const rpcPromises = /* @__PURE__ */ new Map();
|
||||
return {
|
||||
...transport,
|
||||
connect({ onMessage, onDisconnection }) {
|
||||
return transport.connect({
|
||||
onMessage(payload) {
|
||||
if (payload.type === "custom" && payload.event === "vite:invoke") {
|
||||
const data = payload.data;
|
||||
if (data.id.startsWith("response:")) {
|
||||
const invokeId = data.id.slice("response:".length);
|
||||
const promise = rpcPromises.get(invokeId);
|
||||
if (!promise) return;
|
||||
if (promise.timeoutId) clearTimeout(promise.timeoutId);
|
||||
rpcPromises.delete(invokeId);
|
||||
const { error, result } = data.data;
|
||||
if (error) {
|
||||
promise.reject(error);
|
||||
} else {
|
||||
promise.resolve(result);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
onMessage(payload);
|
||||
},
|
||||
onDisconnection
|
||||
});
|
||||
},
|
||||
disconnect() {
|
||||
rpcPromises.forEach((promise) => {
|
||||
promise.reject(
|
||||
new Error(
|
||||
`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`
|
||||
)
|
||||
for (const { deps, fn } of qualifiedCallbacks) {
|
||||
fn(
|
||||
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
||||
);
|
||||
});
|
||||
rpcPromises.clear();
|
||||
return transport.disconnect?.();
|
||||
},
|
||||
send(data) {
|
||||
return transport.send(data);
|
||||
},
|
||||
async invoke(name, data) {
|
||||
const promiseId = nanoid();
|
||||
const wrappedData = {
|
||||
type: "custom",
|
||||
event: "vite:invoke",
|
||||
data: {
|
||||
name,
|
||||
id: `send:${promiseId}`,
|
||||
data
|
||||
}
|
||||
};
|
||||
const sendPromise = transport.send(wrappedData);
|
||||
const { promise, resolve, reject } = promiseWithResolvers();
|
||||
const timeout = transport.timeout ?? 6e4;
|
||||
let timeoutId;
|
||||
if (timeout > 0) {
|
||||
timeoutId = setTimeout(() => {
|
||||
rpcPromises.delete(promiseId);
|
||||
reject(
|
||||
new Error(
|
||||
`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`
|
||||
)
|
||||
);
|
||||
}, timeout);
|
||||
timeoutId?.unref?.();
|
||||
}
|
||||
rpcPromises.set(promiseId, { resolve, reject, name, timeoutId });
|
||||
if (sendPromise) {
|
||||
sendPromise.catch((err) => {
|
||||
clearTimeout(timeoutId);
|
||||
rpcPromises.delete(promiseId);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
try {
|
||||
return await promise;
|
||||
} catch (err) {
|
||||
throw reviveInvokeError(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
const normalizeModuleRunnerTransport = (transport) => {
|
||||
const invokeableTransport = createInvokeableTransport(transport);
|
||||
let isConnected = !invokeableTransport.connect;
|
||||
let connectingPromise;
|
||||
return {
|
||||
...transport,
|
||||
...invokeableTransport.connect ? {
|
||||
async connect(onMessage) {
|
||||
if (isConnected) return;
|
||||
if (connectingPromise) {
|
||||
await connectingPromise;
|
||||
return;
|
||||
}
|
||||
const maybePromise = invokeableTransport.connect({
|
||||
onMessage: onMessage ?? (() => {
|
||||
}),
|
||||
onDisconnection() {
|
||||
isConnected = false;
|
||||
}
|
||||
});
|
||||
if (maybePromise) {
|
||||
connectingPromise = maybePromise;
|
||||
await connectingPromise;
|
||||
connectingPromise = void 0;
|
||||
}
|
||||
isConnected = true;
|
||||
}
|
||||
} : {},
|
||||
...invokeableTransport.disconnect ? {
|
||||
async disconnect() {
|
||||
if (!isConnected) return;
|
||||
if (connectingPromise) {
|
||||
await connectingPromise;
|
||||
}
|
||||
isConnected = false;
|
||||
await invokeableTransport.disconnect();
|
||||
}
|
||||
} : {},
|
||||
async send(data) {
|
||||
if (!invokeableTransport.send) return;
|
||||
if (!isConnected) {
|
||||
if (connectingPromise) {
|
||||
await connectingPromise;
|
||||
} else {
|
||||
throw new Error("send was called before connect");
|
||||
}
|
||||
}
|
||||
await invokeableTransport.send(data);
|
||||
},
|
||||
async invoke(name, data) {
|
||||
if (!isConnected) {
|
||||
if (connectingPromise) {
|
||||
await connectingPromise;
|
||||
} else {
|
||||
throw new Error("invoke was called before connect");
|
||||
}
|
||||
}
|
||||
return invokeableTransport.invoke(name, data);
|
||||
}
|
||||
};
|
||||
};
|
||||
const createWebSocketModuleRunnerTransport = (options) => {
|
||||
const pingInterval = options.pingInterval ?? 3e4;
|
||||
let ws;
|
||||
let pingIntervalId;
|
||||
return {
|
||||
async connect({ onMessage, onDisconnection }) {
|
||||
const socket = options.createConnection();
|
||||
socket.addEventListener("message", async ({ data }) => {
|
||||
onMessage(JSON.parse(data));
|
||||
});
|
||||
let isOpened = socket.readyState === socket.OPEN;
|
||||
if (!isOpened) {
|
||||
await new Promise((resolve, reject) => {
|
||||
socket.addEventListener(
|
||||
"open",
|
||||
() => {
|
||||
isOpened = true;
|
||||
resolve();
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
socket.addEventListener("close", async () => {
|
||||
if (!isOpened) {
|
||||
reject(new Error("WebSocket closed without opened."));
|
||||
return;
|
||||
}
|
||||
onMessage({
|
||||
type: "custom",
|
||||
event: "vite:ws:disconnect",
|
||||
data: { webSocket: socket }
|
||||
});
|
||||
onDisconnection();
|
||||
});
|
||||
});
|
||||
}
|
||||
onMessage({
|
||||
type: "custom",
|
||||
event: "vite:ws:connect",
|
||||
data: { webSocket: socket }
|
||||
});
|
||||
ws = socket;
|
||||
pingIntervalId = setInterval(() => {
|
||||
if (socket.readyState === socket.OPEN) {
|
||||
socket.send(JSON.stringify({ type: "ping" }));
|
||||
}
|
||||
}, pingInterval);
|
||||
},
|
||||
disconnect() {
|
||||
clearInterval(pingIntervalId);
|
||||
ws?.close();
|
||||
},
|
||||
send(data) {
|
||||
ws.send(JSON.stringify(data));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
function createHMRHandler(handler) {
|
||||
const queue = new Queue();
|
||||
return (payload) => queue.enqueue(() => handler(payload));
|
||||
}
|
||||
class Queue {
|
||||
constructor() {
|
||||
this.queue = [];
|
||||
this.pending = false;
|
||||
}
|
||||
enqueue(promise) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.queue.push({
|
||||
promise,
|
||||
resolve,
|
||||
reject
|
||||
});
|
||||
this.dequeue();
|
||||
});
|
||||
}
|
||||
dequeue() {
|
||||
if (this.pending) {
|
||||
return false;
|
||||
}
|
||||
const item = this.queue.shift();
|
||||
if (!item) {
|
||||
return false;
|
||||
}
|
||||
this.pending = true;
|
||||
item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
||||
this.pending = false;
|
||||
this.dequeue();
|
||||
});
|
||||
return true;
|
||||
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
||||
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -757,21 +461,23 @@ class ErrorOverlay extends HTMLElement {
|
||||
fileRE.lastIndex = 0;
|
||||
while (match = fileRE.exec(text)) {
|
||||
const { 0: file, index } = match;
|
||||
const frag = text.slice(curIndex, index);
|
||||
el.appendChild(document.createTextNode(frag));
|
||||
const link = document.createElement("a");
|
||||
link.textContent = file;
|
||||
link.className = "file-link";
|
||||
link.onclick = () => {
|
||||
fetch(
|
||||
new URL(
|
||||
`${base$1}__open-in-editor?file=${encodeURIComponent(file)}`,
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
};
|
||||
el.appendChild(link);
|
||||
curIndex += frag.length + file.length;
|
||||
if (index != null) {
|
||||
const frag = text.slice(curIndex, index);
|
||||
el.appendChild(document.createTextNode(frag));
|
||||
const link = document.createElement("a");
|
||||
link.textContent = file;
|
||||
link.className = "file-link";
|
||||
link.onclick = () => {
|
||||
fetch(
|
||||
new URL(
|
||||
`${base$1}__open-in-editor?file=${encodeURIComponent(file)}`,
|
||||
import.meta.url
|
||||
)
|
||||
);
|
||||
};
|
||||
el.appendChild(link);
|
||||
curIndex += frag.length + file.length;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -794,68 +500,69 @@ const hmrPort = __HMR_PORT__;
|
||||
const socketHost = `${__HMR_HOSTNAME__ || importMetaUrl.hostname}:${hmrPort || importMetaUrl.port}${__HMR_BASE__}`;
|
||||
const directSocketHost = __HMR_DIRECT_TARGET__;
|
||||
const base = __BASE__ || "/";
|
||||
const hmrTimeout = __HMR_TIMEOUT__;
|
||||
const wsToken = __WS_TOKEN__;
|
||||
const transport = normalizeModuleRunnerTransport(
|
||||
(() => {
|
||||
let wsTransport = createWebSocketModuleRunnerTransport({
|
||||
createConnection: () => new WebSocket(
|
||||
`${socketProtocol}://${socketHost}?token=${wsToken}`,
|
||||
"vite-hmr"
|
||||
),
|
||||
pingInterval: hmrTimeout
|
||||
});
|
||||
return {
|
||||
async connect(handlers) {
|
||||
try {
|
||||
await wsTransport.connect(handlers);
|
||||
} catch (e) {
|
||||
if (!hmrPort) {
|
||||
wsTransport = createWebSocketModuleRunnerTransport({
|
||||
createConnection: () => new WebSocket(
|
||||
`${socketProtocol}://${directSocketHost}?token=${wsToken}`,
|
||||
"vite-hmr"
|
||||
),
|
||||
pingInterval: hmrTimeout
|
||||
});
|
||||
try {
|
||||
await wsTransport.connect(handlers);
|
||||
console.info(
|
||||
"[vite] Direct websocket connection fallback. Check out https://vite.dev/config/server-options.html#server-hmr to remove the previous connection error."
|
||||
);
|
||||
} catch (e2) {
|
||||
if (e2 instanceof Error && e2.message.includes("WebSocket closed without opened.")) {
|
||||
const currentScriptHostURL = new URL(import.meta.url);
|
||||
const currentScriptHost = currentScriptHostURL.host + currentScriptHostURL.pathname.replace(/@vite\/client$/, "");
|
||||
console.error(
|
||||
`[vite] failed to connect to websocket.
|
||||
let socket;
|
||||
try {
|
||||
let fallback;
|
||||
if (!hmrPort) {
|
||||
fallback = () => {
|
||||
socket = setupWebSocket(socketProtocol, directSocketHost, () => {
|
||||
const currentScriptHostURL = new URL(import.meta.url);
|
||||
const currentScriptHost = currentScriptHostURL.host + currentScriptHostURL.pathname.replace(/@vite\/client$/, "");
|
||||
console.error(
|
||||
`[vite] failed to connect to websocket.
|
||||
your current setup:
|
||||
(browser) ${currentScriptHost} <--[HTTP]--> ${serverHost} (server)
|
||||
(browser) ${socketHost} <--[WebSocket (failing)]--> ${directSocketHost} (server)
|
||||
Check out your Vite / network configuration and https://vite.dev/config/server-options.html#server-hmr .`
|
||||
);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
console.error(`[vite] failed to connect to websocket (${e}). `);
|
||||
throw e;
|
||||
}
|
||||
},
|
||||
async disconnect() {
|
||||
await wsTransport.disconnect();
|
||||
},
|
||||
send(data) {
|
||||
wsTransport.send(data);
|
||||
}
|
||||
);
|
||||
});
|
||||
socket.addEventListener(
|
||||
"open",
|
||||
() => {
|
||||
console.info(
|
||||
"[vite] Direct websocket connection fallback. Check out https://vite.dev/config/server-options.html#server-hmr to remove the previous connection error."
|
||||
);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
};
|
||||
})()
|
||||
);
|
||||
let willUnload = false;
|
||||
if (typeof window !== "undefined") {
|
||||
window.addEventListener("beforeunload", () => {
|
||||
willUnload = true;
|
||||
}
|
||||
socket = setupWebSocket(socketProtocol, socketHost, fallback);
|
||||
} catch (error) {
|
||||
console.error(`[vite] failed to connect to websocket (${error}). `);
|
||||
}
|
||||
function setupWebSocket(protocol, hostAndPath, onCloseWithoutOpen) {
|
||||
const socket2 = new WebSocket(
|
||||
`${protocol}://${hostAndPath}?token=${wsToken}`,
|
||||
"vite-hmr"
|
||||
);
|
||||
let isOpened = false;
|
||||
socket2.addEventListener(
|
||||
"open",
|
||||
() => {
|
||||
isOpened = true;
|
||||
notifyListeners("vite:ws:connect", { webSocket: socket2 });
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
socket2.addEventListener("message", async ({ data }) => {
|
||||
handleMessage(JSON.parse(data));
|
||||
});
|
||||
socket2.addEventListener("close", async ({ wasClean }) => {
|
||||
if (wasClean) return;
|
||||
if (!isOpened && onCloseWithoutOpen) {
|
||||
onCloseWithoutOpen();
|
||||
return;
|
||||
}
|
||||
notifyListeners("vite:ws:disconnect", { webSocket: socket2 });
|
||||
if (hasDocument) {
|
||||
console.log(`[vite] server connection lost. Polling for restart...`);
|
||||
await waitForSuccessfulPing(protocol, hostAndPath);
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
return socket2;
|
||||
}
|
||||
function cleanUrl(pathname) {
|
||||
const url = new URL(pathname, "http://vite.dev");
|
||||
@@ -878,11 +585,11 @@ const debounceReload = (time) => {
|
||||
};
|
||||
const pageReload = debounceReload(50);
|
||||
const hmrClient = new HMRClient(
|
||||
console,
|
||||
{
|
||||
error: (err) => console.error("[vite]", err),
|
||||
debug: (...msg) => console.debug("[vite]", ...msg)
|
||||
isReady: () => socket && socket.readyState === 1,
|
||||
send: (message) => socket.send(message)
|
||||
},
|
||||
transport,
|
||||
async function importUpdatedModule({
|
||||
acceptedPath,
|
||||
timestamp,
|
||||
@@ -905,14 +612,19 @@ const hmrClient = new HMRClient(
|
||||
return await importPromise;
|
||||
}
|
||||
);
|
||||
transport.connect(createHMRHandler(handleMessage));
|
||||
async function handleMessage(payload) {
|
||||
switch (payload.type) {
|
||||
case "connected":
|
||||
console.debug(`[vite] connected.`);
|
||||
hmrClient.messenger.flush();
|
||||
setInterval(() => {
|
||||
if (socket.readyState === socket.OPEN) {
|
||||
socket.send('{"type":"ping"}');
|
||||
}
|
||||
}, __HMR_TIMEOUT__);
|
||||
break;
|
||||
case "update":
|
||||
await hmrClient.notifyListeners("vite:beforeUpdate", payload);
|
||||
notifyListeners("vite:beforeUpdate", payload);
|
||||
if (hasDocument) {
|
||||
if (isFirstUpdate && hasErrorOverlay()) {
|
||||
location.reload();
|
||||
@@ -955,24 +667,14 @@ async function handleMessage(payload) {
|
||||
});
|
||||
})
|
||||
);
|
||||
await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
||||
notifyListeners("vite:afterUpdate", payload);
|
||||
break;
|
||||
case "custom": {
|
||||
await hmrClient.notifyListeners(payload.event, payload.data);
|
||||
if (payload.event === "vite:ws:disconnect") {
|
||||
if (hasDocument && !willUnload) {
|
||||
console.log(`[vite] server connection lost. Polling for restart...`);
|
||||
const socket = payload.data.webSocket;
|
||||
const url = new URL(socket.url);
|
||||
url.search = "";
|
||||
await waitForSuccessfulPing(url.href);
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
notifyListeners(payload.event, payload.data);
|
||||
break;
|
||||
}
|
||||
case "full-reload":
|
||||
await hmrClient.notifyListeners("vite:beforeFullReload", payload);
|
||||
notifyListeners("vite:beforeFullReload", payload);
|
||||
if (hasDocument) {
|
||||
if (payload.path && payload.path.endsWith(".html")) {
|
||||
const pagePath = decodeURI(location.pathname);
|
||||
@@ -987,11 +689,11 @@ async function handleMessage(payload) {
|
||||
}
|
||||
break;
|
||||
case "prune":
|
||||
await hmrClient.notifyListeners("vite:beforePrune", payload);
|
||||
notifyListeners("vite:beforePrune", payload);
|
||||
await hmrClient.prunePaths(payload.paths);
|
||||
break;
|
||||
case "error": {
|
||||
await hmrClient.notifyListeners("vite:error", payload);
|
||||
notifyListeners("vite:error", payload);
|
||||
if (hasDocument) {
|
||||
const err = payload.err;
|
||||
if (enableOverlay) {
|
||||
@@ -1006,23 +708,20 @@ ${err.stack}`
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "ping":
|
||||
break;
|
||||
default: {
|
||||
const check = payload;
|
||||
return check;
|
||||
}
|
||||
}
|
||||
}
|
||||
function notifyListeners(event, data) {
|
||||
hmrClient.notifyListeners(event, data);
|
||||
}
|
||||
const enableOverlay = __HMR_ENABLE_OVERLAY__;
|
||||
const hasDocument = "document" in globalThis;
|
||||
function createErrorOverlay(err) {
|
||||
clearErrorOverlay();
|
||||
const { customElements } = globalThis;
|
||||
if (customElements) {
|
||||
const ErrorOverlayConstructor = customElements.get(overlayId);
|
||||
document.body.appendChild(new ErrorOverlayConstructor(err));
|
||||
}
|
||||
document.body.appendChild(new ErrorOverlay(err));
|
||||
}
|
||||
function clearErrorOverlay() {
|
||||
document.querySelectorAll(overlayId).forEach((n) => n.close());
|
||||
@@ -1030,27 +729,23 @@ function clearErrorOverlay() {
|
||||
function hasErrorOverlay() {
|
||||
return document.querySelectorAll(overlayId).length;
|
||||
}
|
||||
async function waitForSuccessfulPing(socketUrl, ms = 1e3) {
|
||||
async function ping() {
|
||||
const socket = new WebSocket(socketUrl, "vite-ping");
|
||||
return new Promise((resolve) => {
|
||||
function onOpen() {
|
||||
resolve(true);
|
||||
close();
|
||||
}
|
||||
function onError() {
|
||||
resolve(false);
|
||||
close();
|
||||
}
|
||||
function close() {
|
||||
socket.removeEventListener("open", onOpen);
|
||||
socket.removeEventListener("error", onError);
|
||||
socket.close();
|
||||
}
|
||||
socket.addEventListener("open", onOpen);
|
||||
socket.addEventListener("error", onError);
|
||||
});
|
||||
}
|
||||
async function waitForSuccessfulPing(socketProtocol2, hostAndPath, ms = 1e3) {
|
||||
const pingHostProtocol = socketProtocol2 === "wss" ? "https" : "http";
|
||||
const ping = async () => {
|
||||
try {
|
||||
await fetch(`${pingHostProtocol}://${hostAndPath}`, {
|
||||
mode: "no-cors",
|
||||
headers: {
|
||||
// Custom headers won't be included in a request with no-cors so (ab)use one of the
|
||||
// safelisted headers to identify the ping request
|
||||
Accept: "text/x-vite-ping"
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} catch {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
if (await ping()) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user