source: node_modules/vite/dist/node/moduleRunnerTransport.d-CXw_Ws6P.d.ts@ 9868304

Last change on this file since 9868304 was 57e58a3, checked in by ste08 <sjovanoska@…>, 4 months ago

Initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1import { HotPayload } from '../../types/hmrPayload.js';
2
3interface FetchFunctionOptions {
4 cached?: boolean;
5 startOffset?: number;
6}
7type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
8interface 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}
15interface 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}
28interface 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}
53type InvokeMethods = {
54 fetchModule: (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
55};
56
57type ModuleRunnerTransportHandlers = {
58 onMessage: (data: HotPayload) => void;
59 onDisconnection: () => void;
60};
61/**
62 * "send and connect" or "invoke" must be implemented
63 */
64interface 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}
75interface 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}
81declare const createWebSocketModuleRunnerTransport: (options: {
82 createConnection: () => WebSocket;
83 pingInterval?: number;
84}) => Required<Pick<ModuleRunnerTransport, "connect" | "disconnect" | "send">>;
85
86export { 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 };
Note: See TracBrowser for help on using the repository browser.