|
|
import { HotPayload } from "#types/hmrPayload"; |
|
|
|
|
|
|
|
|
interface FetchFunctionOptions { |
|
|
cached?: boolean; |
|
|
startOffset?: number; |
|
|
} |
|
|
type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult; |
|
|
interface CachedFetchResult { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cache: true; |
|
|
} |
|
|
interface ExternalFetchResult { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
externalize: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type: "module" | "commonjs" | "builtin" | "network"; |
|
|
} |
|
|
interface ViteFetchResult { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
code: string; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
file: string | null; |
|
|
|
|
|
|
|
|
|
|
|
id: string; |
|
|
|
|
|
|
|
|
|
|
|
url: string; |
|
|
|
|
|
|
|
|
|
|
|
invalidate: boolean; |
|
|
} |
|
|
type InvokeMethods = { |
|
|
fetchModule: (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>; |
|
|
getBuiltins: () => Promise<Array<{ |
|
|
type: "string"; |
|
|
value: string; |
|
|
} | { |
|
|
type: "RegExp"; |
|
|
source: string; |
|
|
flags: string; |
|
|
}>>; |
|
|
}; |
|
|
|
|
|
|
|
|
type ModuleRunnerTransportHandlers = { |
|
|
onMessage: (data: HotPayload) => void; |
|
|
onDisconnection: () => void; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
interface ModuleRunnerTransport { |
|
|
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void; |
|
|
disconnect?(): Promise<void> | void; |
|
|
send?(data: HotPayload): Promise<void> | void; |
|
|
invoke?(data: HotPayload): Promise<{ |
|
|
result: any; |
|
|
} | { |
|
|
error: any; |
|
|
}>; |
|
|
timeout?: number; |
|
|
} |
|
|
interface NormalizedModuleRunnerTransport { |
|
|
connect?(onMessage?: (data: HotPayload) => void): Promise<void> | void; |
|
|
disconnect?(): Promise<void> | void; |
|
|
send(data: HotPayload): Promise<void>; |
|
|
invoke<T extends keyof InvokeMethods>(name: T, data: Parameters<InvokeMethods[T]>): Promise<ReturnType<Awaited<InvokeMethods[T]>>>; |
|
|
} |
|
|
declare const createWebSocketModuleRunnerTransport: (options: { |
|
|
createConnection: () => WebSocket; |
|
|
pingInterval?: number; |
|
|
}) => Required<Pick<ModuleRunnerTransport, "connect" | "disconnect" | "send">>; |
|
|
|
|
|
export { ExternalFetchResult as a, ViteFetchResult as c, createWebSocketModuleRunnerTransport as i, ModuleRunnerTransportHandlers as n, FetchFunctionOptions as o, NormalizedModuleRunnerTransport as r, FetchResult as s, ModuleRunnerTransport as t }; |