[57e58a3] | 1 | import { ModuleNamespace, ViteHotContext } from '../../types/hot.js';
|
---|
| 2 | import { Update, HotPayload } from '../../types/hmrPayload.js';
|
---|
| 3 | import { InferCustomEventPayload } from '../../types/customEvent.js';
|
---|
| 4 | import { N as NormalizedModuleRunnerTransport, E as ExternalFetchResult, V as ViteFetchResult, F as FetchFunctionOptions, a as FetchResult, M as ModuleRunnerTransport } from './moduleRunnerTransport.d-CXw_Ws6P.js';
|
---|
| 5 | export { b as ModuleRunnerTransportHandlers, c as createWebSocketModuleRunnerTransport } from './moduleRunnerTransport.d-CXw_Ws6P.js';
|
---|
| 6 |
|
---|
| 7 | interface SourceMapLike {
|
---|
| 8 | version: number;
|
---|
| 9 | mappings?: string;
|
---|
| 10 | names?: string[];
|
---|
| 11 | sources?: string[];
|
---|
| 12 | sourcesContent?: string[];
|
---|
| 13 | }
|
---|
| 14 | declare class DecodedMap {
|
---|
| 15 | map: SourceMapLike;
|
---|
| 16 | _encoded: string;
|
---|
| 17 | _decoded: undefined | number[][][];
|
---|
| 18 | _decodedMemo: Stats;
|
---|
| 19 | url: string;
|
---|
| 20 | version: number;
|
---|
| 21 | names: string[];
|
---|
| 22 | resolvedSources: string[];
|
---|
| 23 | constructor(map: SourceMapLike, from: string);
|
---|
| 24 | }
|
---|
| 25 | interface Stats {
|
---|
| 26 | lastKey: number;
|
---|
| 27 | lastNeedle: number;
|
---|
| 28 | lastIndex: number;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | type CustomListenersMap = Map<string, ((data: any) => void)[]>;
|
---|
| 32 | interface HotModule {
|
---|
| 33 | id: string;
|
---|
| 34 | callbacks: HotCallback[];
|
---|
| 35 | }
|
---|
| 36 | interface HotCallback {
|
---|
| 37 | deps: string[];
|
---|
| 38 | fn: (modules: Array<ModuleNamespace | undefined>) => void;
|
---|
| 39 | }
|
---|
| 40 | interface HMRLogger {
|
---|
| 41 | error(msg: string | Error): void;
|
---|
| 42 | debug(...msg: unknown[]): void;
|
---|
| 43 | }
|
---|
| 44 | declare class HMRClient {
|
---|
| 45 | logger: HMRLogger;
|
---|
| 46 | private transport;
|
---|
| 47 | private importUpdatedModule;
|
---|
| 48 | hotModulesMap: Map<string, HotModule>;
|
---|
| 49 | disposeMap: Map<string, (data: any) => void | Promise<void>>;
|
---|
| 50 | pruneMap: Map<string, (data: any) => void | Promise<void>>;
|
---|
| 51 | dataMap: Map<string, any>;
|
---|
| 52 | customListenersMap: CustomListenersMap;
|
---|
| 53 | ctxToListenersMap: Map<string, CustomListenersMap>;
|
---|
| 54 | constructor(logger: HMRLogger, transport: NormalizedModuleRunnerTransport, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
|
---|
| 55 | notifyListeners<T extends string>(event: T, data: InferCustomEventPayload<T>): Promise<void>;
|
---|
| 56 | send(payload: HotPayload): void;
|
---|
| 57 | clear(): void;
|
---|
| 58 | prunePaths(paths: string[]): Promise<void>;
|
---|
| 59 | protected warnFailedUpdate(err: Error, path: string | string[]): void;
|
---|
| 60 | private updateQueue;
|
---|
| 61 | private pendingUpdateQueue;
|
---|
| 62 | /**
|
---|
| 63 | * buffer multiple hot updates triggered by the same src change
|
---|
| 64 | * so that they are invoked in the same order they were sent.
|
---|
| 65 | * (otherwise the order may be inconsistent because of the http request round trip)
|
---|
| 66 | */
|
---|
| 67 | queueUpdate(payload: Update): Promise<void>;
|
---|
| 68 | private fetchUpdate;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | interface DefineImportMetadata {
|
---|
| 72 | /**
|
---|
| 73 | * Imported names before being transformed to `ssrImportKey`
|
---|
| 74 | *
|
---|
| 75 | * import foo, { bar as baz, qux } from 'hello'
|
---|
| 76 | * => ['default', 'bar', 'qux']
|
---|
| 77 | *
|
---|
| 78 | * import * as namespace from 'world
|
---|
| 79 | * => undefined
|
---|
| 80 | */
|
---|
| 81 | importedNames?: string[];
|
---|
| 82 | }
|
---|
| 83 | interface SSRImportMetadata extends DefineImportMetadata {
|
---|
| 84 | isDynamicImport?: boolean;
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | declare const ssrModuleExportsKey = "__vite_ssr_exports__";
|
---|
| 88 | declare const ssrImportKey = "__vite_ssr_import__";
|
---|
| 89 | declare const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
|
---|
| 90 | declare const ssrExportAllKey = "__vite_ssr_exportAll__";
|
---|
| 91 | declare const ssrImportMetaKey = "__vite_ssr_import_meta__";
|
---|
| 92 |
|
---|
| 93 | interface ModuleRunnerDebugger {
|
---|
| 94 | (formatter: unknown, ...args: unknown[]): void;
|
---|
| 95 | }
|
---|
| 96 | declare class ModuleRunner {
|
---|
| 97 | options: ModuleRunnerOptions;
|
---|
| 98 | evaluator: ModuleEvaluator;
|
---|
| 99 | private debug?;
|
---|
| 100 | evaluatedModules: EvaluatedModules;
|
---|
| 101 | hmrClient?: HMRClient;
|
---|
| 102 | private readonly envProxy;
|
---|
| 103 | private readonly transport;
|
---|
| 104 | private readonly resetSourceMapSupport?;
|
---|
| 105 | private readonly concurrentModuleNodePromises;
|
---|
| 106 | private closed;
|
---|
| 107 | constructor(options: ModuleRunnerOptions, evaluator?: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
|
---|
| 108 | /**
|
---|
| 109 | * URL to execute. Accepts file path, server path or id relative to the root.
|
---|
| 110 | */
|
---|
| 111 | import<T = any>(url: string): Promise<T>;
|
---|
| 112 | /**
|
---|
| 113 | * Clear all caches including HMR listeners.
|
---|
| 114 | */
|
---|
| 115 | clearCache(): void;
|
---|
| 116 | /**
|
---|
| 117 | * Clears all caches, removes all HMR listeners, and resets source map support.
|
---|
| 118 | * This method doesn't stop the HMR connection.
|
---|
| 119 | */
|
---|
| 120 | close(): Promise<void>;
|
---|
| 121 | /**
|
---|
| 122 | * Returns `true` if the runtime has been closed by calling `close()` method.
|
---|
| 123 | */
|
---|
| 124 | isClosed(): boolean;
|
---|
| 125 | private processImport;
|
---|
| 126 | private isCircularModule;
|
---|
| 127 | private isCircularImport;
|
---|
| 128 | private cachedRequest;
|
---|
| 129 | private cachedModule;
|
---|
| 130 | private getModuleInformation;
|
---|
| 131 | protected directRequest(url: string, mod: EvaluatedModuleNode, _callstack: string[]): Promise<any>;
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | interface RetrieveFileHandler {
|
---|
| 135 | (path: string): string | null | undefined | false;
|
---|
| 136 | }
|
---|
| 137 | interface RetrieveSourceMapHandler {
|
---|
| 138 | (path: string): null | {
|
---|
| 139 | url: string;
|
---|
| 140 | map: any;
|
---|
| 141 | };
|
---|
| 142 | }
|
---|
| 143 | interface InterceptorOptions {
|
---|
| 144 | retrieveFile?: RetrieveFileHandler;
|
---|
| 145 | retrieveSourceMap?: RetrieveSourceMapHandler;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | interface ModuleRunnerImportMeta extends ImportMeta {
|
---|
| 149 | url: string;
|
---|
| 150 | env: ImportMetaEnv;
|
---|
| 151 | hot?: ViteHotContext;
|
---|
| 152 | [key: string]: any;
|
---|
| 153 | }
|
---|
| 154 | interface ModuleRunnerContext {
|
---|
| 155 | [ssrModuleExportsKey]: Record<string, any>;
|
---|
| 156 | [ssrImportKey]: (id: string, metadata?: DefineImportMetadata) => Promise<any>;
|
---|
| 157 | [ssrDynamicImportKey]: (id: string, options?: ImportCallOptions) => Promise<any>;
|
---|
| 158 | [ssrExportAllKey]: (obj: any) => void;
|
---|
| 159 | [ssrImportMetaKey]: ModuleRunnerImportMeta;
|
---|
| 160 | }
|
---|
| 161 | interface ModuleEvaluator {
|
---|
| 162 | /**
|
---|
| 163 | * Number of prefixed lines in the transformed code.
|
---|
| 164 | */
|
---|
| 165 | startOffset?: number;
|
---|
| 166 | /**
|
---|
| 167 | * Run code that was transformed by Vite.
|
---|
| 168 | * @param context Function context
|
---|
| 169 | * @param code Transformed code
|
---|
| 170 | * @param module The module node
|
---|
| 171 | */
|
---|
| 172 | runInlinedModule(context: ModuleRunnerContext, code: string, module: Readonly<EvaluatedModuleNode>): Promise<any>;
|
---|
| 173 | /**
|
---|
| 174 | * Run externalized module.
|
---|
| 175 | * @param file File URL to the external module
|
---|
| 176 | */
|
---|
| 177 | runExternalModule(file: string): Promise<any>;
|
---|
| 178 | }
|
---|
| 179 | type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
|
---|
| 180 | url: string;
|
---|
| 181 | id: string;
|
---|
| 182 | };
|
---|
| 183 | type FetchFunction = (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
|
---|
| 184 | interface ModuleRunnerHmr {
|
---|
| 185 | /**
|
---|
| 186 | * Configure HMR logger.
|
---|
| 187 | */
|
---|
| 188 | logger?: false | HMRLogger;
|
---|
| 189 | }
|
---|
| 190 | interface ModuleRunnerOptions {
|
---|
| 191 | /**
|
---|
| 192 | * Root of the project
|
---|
| 193 | * @deprecated not used and to be removed
|
---|
| 194 | */
|
---|
| 195 | root?: string;
|
---|
| 196 | /**
|
---|
| 197 | * A set of methods to communicate with the server.
|
---|
| 198 | */
|
---|
| 199 | transport: ModuleRunnerTransport;
|
---|
| 200 | /**
|
---|
| 201 | * Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
|
---|
| 202 | * Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
|
---|
| 203 | * You can provide an object to configure how file contents and source maps are resolved for files that were not processed by Vite.
|
---|
| 204 | */
|
---|
| 205 | sourcemapInterceptor?: false | 'node' | 'prepareStackTrace' | InterceptorOptions;
|
---|
| 206 | /**
|
---|
| 207 | * Disable HMR or configure HMR options.
|
---|
| 208 | *
|
---|
| 209 | * @default true
|
---|
| 210 | */
|
---|
| 211 | hmr?: boolean | ModuleRunnerHmr;
|
---|
| 212 | /**
|
---|
| 213 | * Custom module cache. If not provided, creates a separate module cache for each ModuleRunner instance.
|
---|
| 214 | */
|
---|
| 215 | evaluatedModules?: EvaluatedModules;
|
---|
| 216 | }
|
---|
| 217 | interface ImportMetaEnv {
|
---|
| 218 | [key: string]: any;
|
---|
| 219 | BASE_URL: string;
|
---|
| 220 | MODE: string;
|
---|
| 221 | DEV: boolean;
|
---|
| 222 | PROD: boolean;
|
---|
| 223 | SSR: boolean;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
| 226 | declare class EvaluatedModuleNode {
|
---|
| 227 | id: string;
|
---|
| 228 | url: string;
|
---|
| 229 | importers: Set<string>;
|
---|
| 230 | imports: Set<string>;
|
---|
| 231 | evaluated: boolean;
|
---|
| 232 | meta: ResolvedResult | undefined;
|
---|
| 233 | promise: Promise<any> | undefined;
|
---|
| 234 | exports: any | undefined;
|
---|
| 235 | file: string;
|
---|
| 236 | map: DecodedMap | undefined;
|
---|
| 237 | constructor(id: string, url: string);
|
---|
| 238 | }
|
---|
| 239 | declare class EvaluatedModules {
|
---|
| 240 | readonly idToModuleMap: Map<string, EvaluatedModuleNode>;
|
---|
| 241 | readonly fileToModulesMap: Map<string, Set<EvaluatedModuleNode>>;
|
---|
| 242 | readonly urlToIdModuleMap: Map<string, EvaluatedModuleNode>;
|
---|
| 243 | /**
|
---|
| 244 | * Returns the module node by the resolved module ID. Usually, module ID is
|
---|
| 245 | * the file system path with query and/or hash. It can also be a virtual module.
|
---|
| 246 | *
|
---|
| 247 | * Module runner graph will have 1 to 1 mapping with the server module graph.
|
---|
| 248 | * @param id Resolved module ID
|
---|
| 249 | */
|
---|
| 250 | getModuleById(id: string): EvaluatedModuleNode | undefined;
|
---|
| 251 | /**
|
---|
| 252 | * Returns all modules related to the file system path. Different modules
|
---|
| 253 | * might have different query parameters or hash, so it's possible to have
|
---|
| 254 | * multiple modules for the same file.
|
---|
| 255 | * @param file The file system path of the module
|
---|
| 256 | */
|
---|
| 257 | getModulesByFile(file: string): Set<EvaluatedModuleNode> | undefined;
|
---|
| 258 | /**
|
---|
| 259 | * Returns the module node by the URL that was used in the import statement.
|
---|
| 260 | * Unlike module graph on the server, the URL is not resolved and is used as is.
|
---|
| 261 | * @param url Server URL that was used in the import statement
|
---|
| 262 | */
|
---|
| 263 | getModuleByUrl(url: string): EvaluatedModuleNode | undefined;
|
---|
| 264 | /**
|
---|
| 265 | * Ensure that module is in the graph. If the module is already in the graph,
|
---|
| 266 | * it will return the existing module node. Otherwise, it will create a new
|
---|
| 267 | * module node and add it to the graph.
|
---|
| 268 | * @param id Resolved module ID
|
---|
| 269 | * @param url URL that was used in the import statement
|
---|
| 270 | */
|
---|
| 271 | ensureModule(id: string, url: string): EvaluatedModuleNode;
|
---|
| 272 | invalidateModule(node: EvaluatedModuleNode): void;
|
---|
| 273 | /**
|
---|
| 274 | * Extracts the inlined source map from the module code and returns the decoded
|
---|
| 275 | * source map. If the source map is not inlined, it will return null.
|
---|
| 276 | * @param id Resolved module ID
|
---|
| 277 | */
|
---|
| 278 | getModuleSourceMapById(id: string): DecodedMap | null;
|
---|
| 279 | clear(): void;
|
---|
| 280 | }
|
---|
| 281 |
|
---|
| 282 | declare class ESModulesEvaluator implements ModuleEvaluator {
|
---|
| 283 | readonly startOffset: number;
|
---|
| 284 | runInlinedModule(context: ModuleRunnerContext, code: string): Promise<any>;
|
---|
| 285 | runExternalModule(filepath: string): Promise<any>;
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | export { ESModulesEvaluator, EvaluatedModuleNode, EvaluatedModules, type FetchFunction, FetchFunctionOptions, FetchResult, type HMRLogger, type InterceptorOptions, type ModuleEvaluator, ModuleRunner, type ModuleRunnerContext, type ModuleRunnerHmr, type ModuleRunnerImportMeta, type ModuleRunnerOptions, ModuleRunnerTransport, type ResolvedResult, type SSRImportMetadata, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
|
---|