1 | import { HotPayload } from '../../types/hmrPayload.js';
|
---|
2 |
|
---|
3 | interface FetchFunctionOptions {
|
---|
4 | cached?: boolean;
|
---|
5 | startOffset?: number;
|
---|
6 | }
|
---|
7 | type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
|
---|
8 | interface CachedFetchResult {
|
---|
9 | /**
|
---|
10 | * If module cached in the runner, we can just confirm
|
---|
11 | * it wasn't invalidated on the server side.
|
---|
12 | */
|
---|
13 | cache: true;
|
---|
14 | }
|
---|
15 | interface ExternalFetchResult {
|
---|
16 | /**
|
---|
17 | * The path to the externalized module starting with file://,
|
---|
18 | * by default this will be imported via a dynamic "import"
|
---|
19 | * instead of being transformed by vite and loaded with vite runner
|
---|
20 | */
|
---|
21 | externalize: string;
|
---|
22 | /**
|
---|
23 | * Type of the module. Will be used to determine if import statement is correct.
|
---|
24 | * For example, if Vite needs to throw an error if variable is not actually exported
|
---|
25 | */
|
---|
26 | type: 'module' | 'commonjs' | 'builtin' | 'network';
|
---|
27 | }
|
---|
28 | interface ViteFetchResult {
|
---|
29 | /**
|
---|
30 | * Code that will be evaluated by vite runner
|
---|
31 | * by default this will be wrapped in an async function
|
---|
32 | */
|
---|
33 | code: string;
|
---|
34 | /**
|
---|
35 | * File path of the module on disk.
|
---|
36 | * This will be resolved as import.meta.url/filename
|
---|
37 | * Will be equal to `null` for virtual modules
|
---|
38 | */
|
---|
39 | file: string | null;
|
---|
40 | /**
|
---|
41 | * Module ID in the server module graph.
|
---|
42 | */
|
---|
43 | id: string;
|
---|
44 | /**
|
---|
45 | * Module URL used in the import.
|
---|
46 | */
|
---|
47 | url: string;
|
---|
48 | /**
|
---|
49 | * Invalidate module on the client side.
|
---|
50 | */
|
---|
51 | invalidate: boolean;
|
---|
52 | }
|
---|
53 | type InvokeMethods = {
|
---|
54 | fetchModule: (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
|
---|
55 | };
|
---|
56 |
|
---|
57 | type ModuleRunnerTransportHandlers = {
|
---|
58 | onMessage: (data: HotPayload) => void;
|
---|
59 | onDisconnection: () => void;
|
---|
60 | };
|
---|
61 | /**
|
---|
62 | * "send and connect" or "invoke" must be implemented
|
---|
63 | */
|
---|
64 | interface ModuleRunnerTransport {
|
---|
65 | connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void;
|
---|
66 | disconnect?(): Promise<void> | void;
|
---|
67 | send?(data: HotPayload): Promise<void> | void;
|
---|
68 | invoke?(data: HotPayload): Promise<{
|
---|
69 | result: any;
|
---|
70 | } | {
|
---|
71 | error: any;
|
---|
72 | }>;
|
---|
73 | timeout?: number;
|
---|
74 | }
|
---|
75 | interface NormalizedModuleRunnerTransport {
|
---|
76 | connect?(onMessage?: (data: HotPayload) => void): Promise<void> | void;
|
---|
77 | disconnect?(): Promise<void> | void;
|
---|
78 | send(data: HotPayload): Promise<void>;
|
---|
79 | invoke<T extends keyof InvokeMethods>(name: T, data: Parameters<InvokeMethods[T]>): Promise<ReturnType<Awaited<InvokeMethods[T]>>>;
|
---|
80 | }
|
---|
81 | declare const createWebSocketModuleRunnerTransport: (options: {
|
---|
82 | createConnection: () => WebSocket;
|
---|
83 | pingInterval?: number;
|
---|
84 | }) => Required<Pick<ModuleRunnerTransport, "connect" | "disconnect" | "send">>;
|
---|
85 |
|
---|
86 | export { type ExternalFetchResult as E, type FetchFunctionOptions as F, type ModuleRunnerTransport as M, type NormalizedModuleRunnerTransport as N, type ViteFetchResult as V, type FetchResult as a, type ModuleRunnerTransportHandlers as b, createWebSocketModuleRunnerTransport as c };
|
---|