feat: init
This commit is contained in:
63
node_modules/@nuxt/vite-builder/dist/THIRD-PARTY-LICENSES.md
generated
vendored
Normal file
63
node_modules/@nuxt/vite-builder/dist/THIRD-PARTY-LICENSES.md
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
# Licenses of Bundled Dependencies
|
||||
|
||||
The published artifact additionally contains code with the following licenses:
|
||||
MIT
|
||||
|
||||
# Bundled Dependencies
|
||||
|
||||
## @nuxt/schema, nuxt
|
||||
|
||||
License: MIT
|
||||
Repositories: https://github.com/nuxt/nuxt, https://github.com/nuxt/nuxt
|
||||
|
||||
> The MIT License (MIT)
|
||||
>
|
||||
> Copyright (c) 2016-present - Nuxt Team
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in all
|
||||
> copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
> SOFTWARE.
|
||||
|
||||
---------------------------------------
|
||||
|
||||
## @vue/shared
|
||||
|
||||
License: MIT
|
||||
By: Evan You
|
||||
Repository: https://github.com/vuejs/core
|
||||
|
||||
> The MIT License (MIT)
|
||||
>
|
||||
> Copyright (c) 2018-present, Yuxi (Evan) You
|
||||
>
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in
|
||||
> all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
> THE SOFTWARE.
|
||||
50464
node_modules/@nuxt/vite-builder/dist/_chunks/index.d.mts
generated
vendored
Normal file
50464
node_modules/@nuxt/vite-builder/dist/_chunks/index.d.mts
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
119
node_modules/@nuxt/vite-builder/dist/_chunks/libs/@vue/shared.d.mts
generated
vendored
Normal file
119
node_modules/@nuxt/vite-builder/dist/_chunks/libs/@vue/shared.d.mts
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
//#region ../../node_modules/.pnpm/@vue+shared@3.5.27/node_modules/@vue/shared/dist/shared.d.ts
|
||||
/**
|
||||
* Patch flags are optimization hints generated by the compiler.
|
||||
* when a block with dynamicChildren is encountered during diff, the algorithm
|
||||
* enters "optimized mode". In this mode, we know that the vdom is produced by
|
||||
* a render function generated by the compiler, so the algorithm only needs to
|
||||
* handle updates explicitly marked by these patch flags.
|
||||
*
|
||||
* Patch flags can be combined using the | bitwise operator and can be checked
|
||||
* using the & operator, e.g.
|
||||
*
|
||||
* ```js
|
||||
* const flag = TEXT | CLASS
|
||||
* if (flag & TEXT) { ... }
|
||||
* ```
|
||||
*
|
||||
* Check the `patchElement` function in '../../runtime-core/src/renderer.ts' to see how the
|
||||
* flags are handled during diff.
|
||||
*/
|
||||
declare enum PatchFlags {
|
||||
/**
|
||||
* Indicates an element with dynamic textContent (children fast path)
|
||||
*/
|
||||
TEXT = 1,
|
||||
/**
|
||||
* Indicates an element with dynamic class binding.
|
||||
*/
|
||||
CLASS = 2,
|
||||
/**
|
||||
* Indicates an element with dynamic style
|
||||
* The compiler pre-compiles static string styles into static objects
|
||||
* + detects and hoists inline static objects
|
||||
* e.g. `style="color: red"` and `:style="{ color: 'red' }"` both get hoisted
|
||||
* as:
|
||||
* ```js
|
||||
* const style = { color: 'red' }
|
||||
* render() { return e('div', { style }) }
|
||||
* ```
|
||||
*/
|
||||
STYLE = 4,
|
||||
/**
|
||||
* Indicates an element that has non-class/style dynamic props.
|
||||
* Can also be on a component that has any dynamic props (includes
|
||||
* class/style). when this flag is present, the vnode also has a dynamicProps
|
||||
* array that contains the keys of the props that may change so the runtime
|
||||
* can diff them faster (without having to worry about removed props)
|
||||
*/
|
||||
PROPS = 8,
|
||||
/**
|
||||
* Indicates an element with props with dynamic keys. When keys change, a full
|
||||
* diff is always needed to remove the old key. This flag is mutually
|
||||
* exclusive with CLASS, STYLE and PROPS.
|
||||
*/
|
||||
FULL_PROPS = 16,
|
||||
/**
|
||||
* Indicates an element that requires props hydration
|
||||
* (but not necessarily patching)
|
||||
* e.g. event listeners & v-bind with prop modifier
|
||||
*/
|
||||
NEED_HYDRATION = 32,
|
||||
/**
|
||||
* Indicates a fragment whose children order doesn't change.
|
||||
*/
|
||||
STABLE_FRAGMENT = 64,
|
||||
/**
|
||||
* Indicates a fragment with keyed or partially keyed children
|
||||
*/
|
||||
KEYED_FRAGMENT = 128,
|
||||
/**
|
||||
* Indicates a fragment with unkeyed children.
|
||||
*/
|
||||
UNKEYED_FRAGMENT = 256,
|
||||
/**
|
||||
* Indicates an element that only needs non-props patching, e.g. ref or
|
||||
* directives (onVnodeXXX hooks). since every patched vnode checks for refs
|
||||
* and onVnodeXXX hooks, it simply marks the vnode so that a parent block
|
||||
* will track it.
|
||||
*/
|
||||
NEED_PATCH = 512,
|
||||
/**
|
||||
* Indicates a component with dynamic slots (e.g. slot that references a v-for
|
||||
* iterated value, or dynamic slot names).
|
||||
* Components with this flag are always force updated.
|
||||
*/
|
||||
DYNAMIC_SLOTS = 1024,
|
||||
/**
|
||||
* Indicates a fragment that was created only because the user has placed
|
||||
* comments at the root level of a template. This is a dev-only flag since
|
||||
* comments are stripped in production.
|
||||
*/
|
||||
DEV_ROOT_FRAGMENT = 2048,
|
||||
/**
|
||||
* SPECIAL FLAGS -------------------------------------------------------------
|
||||
* Special flags are negative integers. They are never matched against using
|
||||
* bitwise operators (bitwise matching should only happen in branches where
|
||||
* patchFlag > 0), and are mutually exclusive. When checking for a special
|
||||
* flag, simply check patchFlag === FLAG.
|
||||
*/
|
||||
/**
|
||||
* Indicates a cached static vnode. This is also a hint for hydration to skip
|
||||
* the entire sub tree since static content never needs to be updated.
|
||||
*/
|
||||
CACHED = -1,
|
||||
/**
|
||||
* A special flag that indicates that the diffing algorithm should bail out
|
||||
* of optimized mode. For example, on block fragments created by renderSlot()
|
||||
* when encountering non-compiler generated slots (i.e. manually written
|
||||
* render functions, which should always be fully diffed)
|
||||
* OR manually cloneVNodes
|
||||
*/
|
||||
BAIL = -2
|
||||
}
|
||||
declare function generateCodeFrame(source: string, start?: number, end?: number): string;
|
||||
type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
||||
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
||||
type LooseRequired<T> = { [P in keyof (T & Required<T>)]: T[P] };
|
||||
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
||||
//#endregion
|
||||
export { UnionToIntersection as a, Prettify as i, LooseRequired as n, generateCodeFrame as o, PatchFlags as r, IfAny as t };
|
||||
22
node_modules/@nuxt/vite-builder/dist/index.d.mts
generated
vendored
Normal file
22
node_modules/@nuxt/vite-builder/dist/index.d.mts
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
import { t as NuxtBuilder } from "./_chunks/index.mjs";
|
||||
import { EnvironmentOptions } from "vite";
|
||||
import { ViteConfig } from "nuxt/schema";
|
||||
|
||||
//#region src/vite.d.ts
|
||||
declare const bundle: NuxtBuilder["bundle"];
|
||||
//#endregion
|
||||
//#region src/index.d.ts
|
||||
declare module "nuxt/schema" {
|
||||
interface ViteOptions extends ViteConfig {
|
||||
$client?: EnvironmentOptions;
|
||||
$server?: EnvironmentOptions;
|
||||
viteNode?: {
|
||||
maxRetryAttempts?: number; /** in milliseconds */
|
||||
baseRetryDelay?: number; /** in milliseconds */
|
||||
maxRetryDelay?: number; /** in milliseconds */
|
||||
requestTimeout?: number;
|
||||
};
|
||||
}
|
||||
}
|
||||
//#endregion
|
||||
export { bundle };
|
||||
2023
node_modules/@nuxt/vite-builder/dist/index.mjs
generated
vendored
Normal file
2023
node_modules/@nuxt/vite-builder/dist/index.mjs
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
6
node_modules/@nuxt/vite-builder/dist/vite-node-entry.d.mts
generated
vendored
Normal file
6
node_modules/@nuxt/vite-builder/dist/vite-node-entry.d.mts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { NuxtSSRContext } from "nuxt/app";
|
||||
|
||||
//#region src/vite-node-entry.d.ts
|
||||
declare const _default: (ssrContext: NuxtSSRContext) => Promise<any>;
|
||||
//#endregion
|
||||
export { _default as default };
|
||||
81
node_modules/@nuxt/vite-builder/dist/vite-node-entry.mjs
generated
vendored
Normal file
81
node_modules/@nuxt/vite-builder/dist/vite-node-entry.mjs
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
import { performance } from "node:perf_hooks";
|
||||
import process from "node:process";
|
||||
import { ViteNodeRunner } from "vite-node/client";
|
||||
import { consola } from "consola";
|
||||
import { viteNodeFetch, viteNodeOptions } from "#vite-node";
|
||||
const runner = createRunner();
|
||||
let render;
|
||||
var vite_node_entry_default = async (ssrContext) => {
|
||||
process.server = true;
|
||||
import.meta.server = true;
|
||||
const invalidates = await viteNodeFetch.getInvalidates();
|
||||
const updates = runner.moduleCache.invalidateDepTree(invalidates);
|
||||
const start = performance.now();
|
||||
render = updates.has(viteNodeOptions.entryPath) || !render ? (await runner.executeFile(viteNodeOptions.entryPath)).default : render;
|
||||
if (updates.size) {
|
||||
const time = Math.round((performance.now() - start) * 1e3) / 1e3;
|
||||
consola.success(`Vite server hmr ${updates.size} files`, time ? `in ${time}ms` : "");
|
||||
}
|
||||
return await render(ssrContext);
|
||||
};
|
||||
function createRunner() {
|
||||
return new ViteNodeRunner({
|
||||
root: viteNodeOptions.root,
|
||||
base: viteNodeOptions.base,
|
||||
async resolveId(id, importer) {
|
||||
return await viteNodeFetch.resolveId(id, importer);
|
||||
},
|
||||
async fetchModule(id) {
|
||||
id = id.replace(/\/\//g, "/");
|
||||
return await viteNodeFetch.fetchModule(id).catch((err) => {
|
||||
const errorData = err?.data?.data;
|
||||
if (!errorData) throw err;
|
||||
let _err;
|
||||
try {
|
||||
const { message, stack } = formatViteError(errorData, id);
|
||||
_err = {
|
||||
statusText: "Vite Error",
|
||||
message,
|
||||
stack
|
||||
};
|
||||
} catch (formatError) {
|
||||
consola.warn("Internal nuxt error while formatting vite-node error. Please report this!", formatError);
|
||||
const message = `[vite-node] [TransformError] ${errorData?.message || "-"}`;
|
||||
consola.error(message, errorData);
|
||||
throw {
|
||||
statusText: "Vite Error",
|
||||
message,
|
||||
stack: `${message}\nat ${id}\n` + (errorData?.stack || "")
|
||||
};
|
||||
}
|
||||
throw _err;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function formatViteError(errorData, id) {
|
||||
const errorCode = errorData.name || errorData.reasonCode || errorData.code;
|
||||
const frame = errorData.frame || errorData.source || errorData.pluginCode;
|
||||
const getLocId = (locObj = {}) => locObj.file || locObj.id || locObj.url || id || "";
|
||||
const getLocPos = (locObj = {}) => locObj.line ? `${locObj.line}:${locObj.column || 0}` : "";
|
||||
const locId = getLocId(errorData.loc) || getLocId(errorData.location) || getLocId(errorData.input) || getLocId(errorData);
|
||||
const locPos = getLocPos(errorData.loc) || getLocPos(errorData.location) || getLocPos(errorData.input) || getLocPos(errorData);
|
||||
const loc = locId.replace(process.cwd(), ".") + (locPos ? `:${locPos}` : "");
|
||||
const message = [
|
||||
"[vite-node]",
|
||||
errorData.plugin && `[plugin:${errorData.plugin}]`,
|
||||
errorCode && `[${errorCode}]`,
|
||||
loc,
|
||||
errorData.reason && `: ${errorData.reason}`,
|
||||
frame && `<br><pre>${frame.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">")}</pre><br>`
|
||||
].filter(Boolean).join(" ");
|
||||
return {
|
||||
message,
|
||||
stack: [
|
||||
message,
|
||||
`at ${loc}`,
|
||||
errorData.stack
|
||||
].filter(Boolean).join("\n")
|
||||
};
|
||||
}
|
||||
export { vite_node_entry_default as default };
|
||||
37
node_modules/@nuxt/vite-builder/dist/vite-node.d.mts
generated
vendored
Normal file
37
node_modules/@nuxt/vite-builder/dist/vite-node.d.mts
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
import "./_chunks/index.mjs";
|
||||
import { PluginContainer } from "vite";
|
||||
import { Socket } from "node:net";
|
||||
import { Manifest } from "vue-bundle-renderer";
|
||||
import { FetchResult } from "vite-node";
|
||||
|
||||
//#region src/plugins/vite-node.d.ts
|
||||
type ResolveIdResponse = Awaited<ReturnType<PluginContainer["resolveId"]>>;
|
||||
interface ViteNodeFetch {
|
||||
/** Gets the client manifest. */
|
||||
getManifest(): Promise<Manifest>;
|
||||
/** Gets the list of invalidated files. */
|
||||
getInvalidates(): Promise<string[]>;
|
||||
/** Resolves a module ID. */
|
||||
resolveId(id: string, importer?: string): Promise<ResolveIdResponse | null>;
|
||||
/** Fetches a module. */
|
||||
fetchModule(moduleId: string): Promise<FetchResult>;
|
||||
/** Ensures the IPC socket is connected. */
|
||||
ensureConnected(): Promise<Socket>;
|
||||
}
|
||||
type ViteNodeServerOptions = {
|
||||
baseURL: string;
|
||||
socketPath: string;
|
||||
root: string;
|
||||
entryPath: string;
|
||||
base: string;
|
||||
maxRetryAttempts?: number;
|
||||
baseRetryDelay?: number;
|
||||
maxRetryDelay?: number;
|
||||
requestTimeout?: number;
|
||||
};
|
||||
//#endregion
|
||||
//#region src/vite-node.d.ts
|
||||
declare const viteNodeOptions: ViteNodeServerOptions;
|
||||
declare const viteNodeFetch: ViteNodeFetch;
|
||||
//#endregion
|
||||
export { viteNodeFetch, viteNodeOptions };
|
||||
224
node_modules/@nuxt/vite-builder/dist/vite-node.mjs
generated
vendored
Normal file
224
node_modules/@nuxt/vite-builder/dist/vite-node.mjs
generated
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
import process from "node:process";
|
||||
import net from "node:net";
|
||||
import { Buffer } from "node:buffer";
|
||||
import { isTest } from "std-env";
|
||||
function getViteNodeOptionsEnvVar() {
|
||||
const envVar = process.env.NUXT_VITE_NODE_OPTIONS;
|
||||
try {
|
||||
return JSON.parse(envVar || "{}");
|
||||
} catch (e) {
|
||||
console.error("vite-node-shared: Failed to parse NUXT_VITE_NODE_OPTIONS environment variable.", e);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
const viteNodeOptions = getViteNodeOptionsEnvVar();
|
||||
const pendingRequests = /* @__PURE__ */ new Map();
|
||||
let requestIdCounter = 0;
|
||||
let clientSocket;
|
||||
let currentConnectPromise;
|
||||
const MAX_RETRY_ATTEMPTS = viteNodeOptions.maxRetryAttempts ?? 5;
|
||||
const BASE_RETRY_DELAY_MS = viteNodeOptions.baseRetryDelay ?? 100;
|
||||
const MAX_RETRY_DELAY_MS = viteNodeOptions.maxRetryDelay ?? 2e3;
|
||||
const REQUEST_TIMEOUT_MS = viteNodeOptions.requestTimeout ?? 6e4;
|
||||
function calculateRetryDelay(attempt) {
|
||||
const exponentialDelay = BASE_RETRY_DELAY_MS * Math.pow(2, attempt);
|
||||
const jitter = Math.random() * .1 * exponentialDelay;
|
||||
return Math.min(exponentialDelay + jitter, MAX_RETRY_DELAY_MS);
|
||||
}
|
||||
function connectSocket() {
|
||||
if (clientSocket && !clientSocket.destroyed) return Promise.resolve(clientSocket);
|
||||
if (currentConnectPromise) return currentConnectPromise;
|
||||
const thisPromise = new Promise((resolve, reject) => {
|
||||
if (!viteNodeOptions.socketPath) {
|
||||
console.error("vite-node-shared: NUXT_VITE_NODE_OPTIONS.socketPath is not defined.");
|
||||
return reject(/* @__PURE__ */ new Error("Vite Node IPC socket path not configured."));
|
||||
}
|
||||
const attemptConnection = (attempt = 0) => {
|
||||
const socket = net.createConnection(viteNodeOptions.socketPath);
|
||||
const INITIAL_BUFFER_SIZE = 64 * 1024;
|
||||
const MAX_BUFFER_SIZE = 1024 * 1024 * 1024;
|
||||
let buffer = Buffer.alloc(INITIAL_BUFFER_SIZE);
|
||||
let writeOffset = 0;
|
||||
let readOffset = 0;
|
||||
socket.setNoDelay(true);
|
||||
socket.setKeepAlive(true, 3e4);
|
||||
const cleanup = () => {
|
||||
socket.off("connect", onConnect);
|
||||
socket.off("data", onData);
|
||||
socket.off("error", onError);
|
||||
socket.off("close", onClose);
|
||||
};
|
||||
const resetBuffer = () => {
|
||||
writeOffset = 0;
|
||||
readOffset = 0;
|
||||
};
|
||||
const compactBuffer = () => {
|
||||
if (readOffset > 0) {
|
||||
const remainingData = writeOffset - readOffset;
|
||||
if (remainingData > 0) buffer.copy(buffer, 0, readOffset, writeOffset);
|
||||
writeOffset = remainingData;
|
||||
readOffset = 0;
|
||||
}
|
||||
};
|
||||
const ensureBufferCapacity = (additionalBytes) => {
|
||||
const requiredSize = writeOffset + additionalBytes;
|
||||
if (requiredSize > MAX_BUFFER_SIZE) throw new Error(`Buffer size limit exceeded: ${requiredSize} > ${MAX_BUFFER_SIZE}`);
|
||||
if (requiredSize > buffer.length) {
|
||||
compactBuffer();
|
||||
if (writeOffset + additionalBytes > buffer.length) {
|
||||
const newSize = Math.min(Math.max(buffer.length * 2, requiredSize), MAX_BUFFER_SIZE);
|
||||
const newBuffer = Buffer.alloc(newSize);
|
||||
buffer.copy(newBuffer, 0, 0, writeOffset);
|
||||
buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
};
|
||||
const onConnect = () => {
|
||||
clientSocket = socket;
|
||||
resolve(socket);
|
||||
};
|
||||
const onData = (data) => {
|
||||
try {
|
||||
ensureBufferCapacity(data.length);
|
||||
data.copy(buffer, writeOffset);
|
||||
writeOffset += data.length;
|
||||
while (writeOffset - readOffset >= 4) {
|
||||
const messageLength = buffer.readUInt32BE(readOffset);
|
||||
if (writeOffset - readOffset < 4 + messageLength) return;
|
||||
const message = buffer.subarray(readOffset + 4, readOffset + 4 + messageLength).toString("utf-8");
|
||||
readOffset += 4 + messageLength;
|
||||
try {
|
||||
const response = JSON.parse(message);
|
||||
const requestHandlers = pendingRequests.get(response.id);
|
||||
if (requestHandlers) {
|
||||
const { resolve: resolveRequest, reject: rejectRequest } = requestHandlers;
|
||||
if (response.type === "error") {
|
||||
const err = new Error(response.error.message);
|
||||
err.stack = response.error.stack;
|
||||
err.data = response.error.data;
|
||||
err.statusCode = err.status = response.error.status || response.error.statusCode;
|
||||
rejectRequest(err);
|
||||
} else resolveRequest(response.data);
|
||||
pendingRequests.delete(response.id);
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.warn("vite-node-shared: Failed to parse IPC response:", parseError);
|
||||
}
|
||||
}
|
||||
if (readOffset > buffer.length / 2) compactBuffer();
|
||||
} catch (error) {
|
||||
socket.destroy(error instanceof Error ? error : /* @__PURE__ */ new Error("Buffer management error"));
|
||||
}
|
||||
};
|
||||
const onError = (err) => {
|
||||
cleanup();
|
||||
resetBuffer();
|
||||
if (attempt < MAX_RETRY_ATTEMPTS) {
|
||||
const delay = calculateRetryDelay(attempt);
|
||||
setTimeout(() => attemptConnection(attempt + 1), delay);
|
||||
} else {
|
||||
if (currentConnectPromise === thisPromise) reject(err);
|
||||
for (const { reject: rejectRequest } of pendingRequests.values()) rejectRequest(err);
|
||||
pendingRequests.clear();
|
||||
if (clientSocket === socket) clientSocket = void 0;
|
||||
if (currentConnectPromise === thisPromise) currentConnectPromise = void 0;
|
||||
}
|
||||
};
|
||||
const onClose = () => {
|
||||
cleanup();
|
||||
resetBuffer();
|
||||
for (const { reject: rejectRequest } of pendingRequests.values()) rejectRequest(/* @__PURE__ */ new Error("IPC connection closed"));
|
||||
pendingRequests.clear();
|
||||
if (clientSocket === socket) clientSocket = void 0;
|
||||
if (currentConnectPromise === thisPromise) currentConnectPromise = void 0;
|
||||
};
|
||||
socket.on("connect", onConnect);
|
||||
socket.on("data", onData);
|
||||
socket.on("error", onError);
|
||||
socket.on("close", onClose);
|
||||
};
|
||||
attemptConnection();
|
||||
});
|
||||
currentConnectPromise = thisPromise;
|
||||
return currentConnectPromise;
|
||||
}
|
||||
async function sendRequest(type, payload) {
|
||||
const requestId = requestIdCounter++;
|
||||
let lastError;
|
||||
for (let requestAttempt = 0; requestAttempt <= MAX_RETRY_ATTEMPTS; requestAttempt++) try {
|
||||
const socket = await connectSocket();
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
pendingRequests.delete(requestId);
|
||||
reject(/* @__PURE__ */ new Error(`Request timeout after ${REQUEST_TIMEOUT_MS}ms for type: ${type}`));
|
||||
}, REQUEST_TIMEOUT_MS);
|
||||
pendingRequests.set(requestId, {
|
||||
resolve: (value) => {
|
||||
clearTimeout(timeoutId);
|
||||
resolve(value);
|
||||
},
|
||||
reject: (reason) => {
|
||||
clearTimeout(timeoutId);
|
||||
reject(reason);
|
||||
}
|
||||
});
|
||||
const message = JSON.stringify({
|
||||
id: requestId,
|
||||
type,
|
||||
payload
|
||||
});
|
||||
const messageBuffer = Buffer.from(message, "utf-8");
|
||||
const messageLength = messageBuffer.length;
|
||||
const fullMessage = Buffer.alloc(4 + messageLength);
|
||||
fullMessage.writeUInt32BE(messageLength, 0);
|
||||
messageBuffer.copy(fullMessage, 4);
|
||||
try {
|
||||
socket.write(fullMessage);
|
||||
} catch (error) {
|
||||
clearTimeout(timeoutId);
|
||||
pendingRequests.delete(requestId);
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
if (requestAttempt < MAX_RETRY_ATTEMPTS) {
|
||||
const delay = calculateRetryDelay(requestAttempt);
|
||||
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||
if (clientSocket) {
|
||||
clientSocket.destroy();
|
||||
clientSocket = void 0;
|
||||
}
|
||||
currentConnectPromise = void 0;
|
||||
}
|
||||
}
|
||||
throw lastError || /* @__PURE__ */ new Error("Request failed after all retry attempts");
|
||||
}
|
||||
const viteNodeFetch = {
|
||||
getManifest() {
|
||||
return sendRequest("manifest", void 0);
|
||||
},
|
||||
getInvalidates() {
|
||||
return sendRequest("invalidates", void 0);
|
||||
},
|
||||
resolveId(id, importer) {
|
||||
return sendRequest("resolve", {
|
||||
id,
|
||||
importer
|
||||
});
|
||||
},
|
||||
fetchModule(moduleId) {
|
||||
return sendRequest("module", { moduleId });
|
||||
},
|
||||
ensureConnected() {
|
||||
return connectSocket();
|
||||
}
|
||||
};
|
||||
let preConnectAttempted = false;
|
||||
function preConnect() {
|
||||
if (preConnectAttempted || !viteNodeOptions.socketPath) return;
|
||||
preConnectAttempted = true;
|
||||
return connectSocket().catch(() => {});
|
||||
}
|
||||
if (typeof process !== "undefined" && !isTest) setTimeout(preConnect, 100);
|
||||
export { viteNodeFetch, viteNodeOptions };
|
||||
Reference in New Issue
Block a user