vite 6.0.0-beta.1 → 6.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +66 -1010
- package/README.md +4 -4
- package/bin/vite.js +5 -0
- package/client.d.ts +10 -0
- package/dist/client/client.mjs +344 -105
- package/dist/node/chunks/{dep-IQS-Za7F.js → dep-3RmXg9uo.js} +0 -8
- package/dist/node/chunks/{dep-DiM5uMHt.js → dep-Ck0pJQmh.js} +4 -175
- package/dist/node/chunks/{dep-BZ_CwQkz.js → dep-DiRA7B7B.js} +15738 -30463
- package/dist/node/chunks/{dep-D-7KCb9p.js → dep-DnSxfB-q.js} +704 -443
- package/dist/node/chunks/{dep-BZeeNeMJ.js → dep-ifLmJA8Z.js} +286 -127
- package/dist/node/cli.js +21 -37
- package/dist/node/constants.js +19 -11
- package/dist/node/index.d.ts +1649 -1602
- package/dist/node/index.js +13 -153
- package/dist/node/module-runner.d.ts +154 -141
- package/dist/node/module-runner.js +374 -221
- package/dist/node-cjs/publicUtils.cjs +363 -184
- package/index.cjs +35 -3
- package/index.d.cts +1 -1
- package/package.json +44 -33
- package/types/hmrPayload.d.ts +5 -0
- package/types/internal/cssPreprocessorOptions.d.ts +63 -0
- package/types/internal/lightningcssOptions.d.ts +18 -0
package/dist/node/index.js
CHANGED
@@ -1,25 +1,21 @@
|
|
1
1
|
export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
2
|
-
import { i as isInNodeModules, a as arraify } from './chunks/dep-
|
3
|
-
export { B as BuildEnvironment, D as DevEnvironment,
|
4
|
-
|
5
|
-
import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
|
6
|
-
export { VERSION as version } from './constants.js';
|
2
|
+
import { i as isInNodeModules, a as arraify } from './chunks/dep-DiRA7B7B.js';
|
3
|
+
export { B as BuildEnvironment, D as DevEnvironment, f as build, m as buildErrorMessage, g as createBuilder, C as createFilter, h as createIdResolver, G as createLogger, n as createRunnableDevEnvironment, c as createServer, w as createServerHotChannel, v as createServerModuleRunner, d as defineConfig, u as fetchModule, j as formatPostcssSourceMap, J as isFileLoadingAllowed, I as isFileServingAllowed, q as isRunnableDevEnvironment, l as loadConfigFromFile, K as loadEnv, A as mergeAlias, z as mergeConfig, x as moduleRunnerTransform, y as normalizePath, o as optimizeDeps, p as perEnvironmentPlugin, b as perEnvironmentState, k as preprocessCSS, e as preview, r as resolveConfig, L as resolveEnvPrefix, E as rollupVersion, H as searchForWorkspaceRoot, F as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-DiRA7B7B.js';
|
4
|
+
export { DEFAULT_CLIENT_CONDITIONS as defaultClientConditions, DEFAULT_CLIENT_MAIN_FIELDS as defaultClientMainFields, DEFAULT_SERVER_CONDITIONS as defaultServerConditions, DEFAULT_SERVER_MAIN_FIELDS as defaultServerMainFields, VERSION as version } from './constants.js';
|
7
5
|
export { version as esbuildVersion } from 'esbuild';
|
6
|
+
import 'node:fs';
|
8
7
|
import 'node:fs/promises';
|
9
8
|
import 'node:path';
|
10
9
|
import 'node:url';
|
11
10
|
import 'node:util';
|
12
11
|
import 'node:perf_hooks';
|
13
12
|
import 'node:module';
|
14
|
-
import 'tty';
|
15
13
|
import 'path';
|
16
14
|
import 'fs';
|
17
|
-
import 'node:events';
|
18
|
-
import 'node:stream';
|
19
|
-
import 'node:string_decoder';
|
20
15
|
import 'node:child_process';
|
21
16
|
import 'node:http';
|
22
17
|
import 'node:https';
|
18
|
+
import 'tty';
|
23
19
|
import 'util';
|
24
20
|
import 'net';
|
25
21
|
import 'events';
|
@@ -31,19 +27,22 @@ import 'child_process';
|
|
31
27
|
import 'node:os';
|
32
28
|
import 'node:crypto';
|
33
29
|
import 'node:dns';
|
30
|
+
import 'vite/module-runner';
|
34
31
|
import 'module';
|
32
|
+
import 'node:readline';
|
33
|
+
import 'node:process';
|
34
|
+
import 'node:buffer';
|
35
|
+
import 'node:events';
|
36
|
+
import 'crypto';
|
35
37
|
import 'node:assert';
|
36
38
|
import 'node:v8';
|
37
39
|
import 'node:worker_threads';
|
38
|
-
import 'crypto';
|
39
|
-
import 'node:buffer';
|
40
|
-
import 'node:readline';
|
41
40
|
import 'zlib';
|
42
41
|
import 'buffer';
|
43
42
|
import 'https';
|
44
43
|
import 'tls';
|
45
44
|
import 'assert';
|
46
|
-
import 'querystring';
|
45
|
+
import 'node:querystring';
|
47
46
|
import 'node:zlib';
|
48
47
|
|
49
48
|
const CSS_LANGS_RE = (
|
@@ -150,143 +149,4 @@ function splitVendorChunkPlugin() {
|
|
150
149
|
};
|
151
150
|
}
|
152
151
|
|
153
|
-
|
154
|
-
constructor(options) {
|
155
|
-
this.options = options;
|
156
|
-
}
|
157
|
-
register(environment) {
|
158
|
-
this.options.onMessage(async (data) => {
|
159
|
-
if (typeof data !== "object" || !data || !data.__v) return;
|
160
|
-
const method = data.m;
|
161
|
-
const parameters = data.a;
|
162
|
-
try {
|
163
|
-
const result = await environment[method](...parameters);
|
164
|
-
this.options.send({
|
165
|
-
__v: true,
|
166
|
-
r: result,
|
167
|
-
i: data.i
|
168
|
-
});
|
169
|
-
} catch (error) {
|
170
|
-
this.options.send({
|
171
|
-
__v: true,
|
172
|
-
e: {
|
173
|
-
name: error.name,
|
174
|
-
message: error.message,
|
175
|
-
stack: error.stack
|
176
|
-
},
|
177
|
-
i: data.i
|
178
|
-
});
|
179
|
-
}
|
180
|
-
});
|
181
|
-
}
|
182
|
-
}
|
183
|
-
|
184
|
-
class ServerHMRBroadcasterClient {
|
185
|
-
constructor(hotChannel) {
|
186
|
-
this.hotChannel = hotChannel;
|
187
|
-
}
|
188
|
-
send(...args) {
|
189
|
-
let payload;
|
190
|
-
if (typeof args[0] === "string") {
|
191
|
-
payload = {
|
192
|
-
type: "custom",
|
193
|
-
event: args[0],
|
194
|
-
data: args[1]
|
195
|
-
};
|
196
|
-
} else {
|
197
|
-
payload = args[0];
|
198
|
-
}
|
199
|
-
if (payload.type !== "custom") {
|
200
|
-
throw new Error(
|
201
|
-
"Cannot send non-custom events from the client to the server."
|
202
|
-
);
|
203
|
-
}
|
204
|
-
this.hotChannel.send(payload);
|
205
|
-
}
|
206
|
-
}
|
207
|
-
class ServerHMRConnector {
|
208
|
-
constructor(hotChannel) {
|
209
|
-
this.hotChannel = hotChannel;
|
210
|
-
this.hmrClient = new ServerHMRBroadcasterClient(hotChannel);
|
211
|
-
hotChannel.api.outsideEmitter.on("send", (payload) => {
|
212
|
-
this.handlers.forEach((listener) => listener(payload));
|
213
|
-
});
|
214
|
-
this.hotChannel = hotChannel;
|
215
|
-
}
|
216
|
-
handlers = [];
|
217
|
-
hmrClient;
|
218
|
-
connected = false;
|
219
|
-
isReady() {
|
220
|
-
return this.connected;
|
221
|
-
}
|
222
|
-
send(message) {
|
223
|
-
const payload = JSON.parse(message);
|
224
|
-
this.hotChannel.api.innerEmitter.emit(
|
225
|
-
payload.event,
|
226
|
-
payload.data,
|
227
|
-
this.hmrClient
|
228
|
-
);
|
229
|
-
}
|
230
|
-
onUpdate(handler) {
|
231
|
-
this.handlers.push(handler);
|
232
|
-
handler({ type: "connected" });
|
233
|
-
this.connected = true;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
|
237
|
-
function createHMROptions(environment, options) {
|
238
|
-
if (environment.config.server.hmr === false || options.hmr === false) {
|
239
|
-
return false;
|
240
|
-
}
|
241
|
-
if (options.hmr?.connection) {
|
242
|
-
return {
|
243
|
-
connection: options.hmr.connection,
|
244
|
-
logger: options.hmr.logger
|
245
|
-
};
|
246
|
-
}
|
247
|
-
if (!("api" in environment.hot)) return false;
|
248
|
-
const connection = new ServerHMRConnector(environment.hot);
|
249
|
-
return {
|
250
|
-
connection,
|
251
|
-
logger: options.hmr?.logger
|
252
|
-
};
|
253
|
-
}
|
254
|
-
const prepareStackTrace = {
|
255
|
-
retrieveFile(id) {
|
256
|
-
if (existsSync(id)) {
|
257
|
-
return readFileSync(id, "utf-8");
|
258
|
-
}
|
259
|
-
}
|
260
|
-
};
|
261
|
-
function resolveSourceMapOptions(options) {
|
262
|
-
if (options.sourcemapInterceptor != null) {
|
263
|
-
if (options.sourcemapInterceptor === "prepareStackTrace") {
|
264
|
-
return prepareStackTrace;
|
265
|
-
}
|
266
|
-
if (typeof options.sourcemapInterceptor === "object") {
|
267
|
-
return { ...prepareStackTrace, ...options.sourcemapInterceptor };
|
268
|
-
}
|
269
|
-
return options.sourcemapInterceptor;
|
270
|
-
}
|
271
|
-
if (typeof process !== "undefined" && "setSourceMapsEnabled" in process) {
|
272
|
-
return "node";
|
273
|
-
}
|
274
|
-
return prepareStackTrace;
|
275
|
-
}
|
276
|
-
function createServerModuleRunner(environment, options = {}) {
|
277
|
-
const hmr = createHMROptions(environment, options);
|
278
|
-
return new ModuleRunner(
|
279
|
-
{
|
280
|
-
...options,
|
281
|
-
root: environment.config.root,
|
282
|
-
transport: {
|
283
|
-
fetchModule: (id, importer, options2) => environment.fetchModule(id, importer, options2)
|
284
|
-
},
|
285
|
-
hmr,
|
286
|
-
sourcemapInterceptor: resolveSourceMapOptions(options)
|
287
|
-
},
|
288
|
-
options.evaluator || new ESModulesEvaluator()
|
289
|
-
);
|
290
|
-
}
|
291
|
-
|
292
|
-
export { RemoteEnvironmentTransport, ServerHMRConnector, createServerModuleRunner, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|
152
|
+
export { isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|
@@ -1,7 +1,90 @@
|
|
1
1
|
import { ModuleNamespace, ViteHotContext } from '../../types/hot.js';
|
2
|
-
import {
|
2
|
+
import { HotPayload, Update } from '../../types/hmrPayload.js';
|
3
3
|
import { InferCustomEventPayload } from '../../types/customEvent.js';
|
4
4
|
|
5
|
+
interface FetchFunctionOptions {
|
6
|
+
cached?: boolean;
|
7
|
+
startOffset?: number;
|
8
|
+
}
|
9
|
+
type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
|
10
|
+
interface CachedFetchResult {
|
11
|
+
/**
|
12
|
+
* If module cached in the runner, we can just confirm
|
13
|
+
* it wasn't invalidated on the server side.
|
14
|
+
*/
|
15
|
+
cache: true;
|
16
|
+
}
|
17
|
+
interface ExternalFetchResult {
|
18
|
+
/**
|
19
|
+
* The path to the externalized module starting with file://,
|
20
|
+
* by default this will be imported via a dynamic "import"
|
21
|
+
* instead of being transformed by vite and loaded with vite runner
|
22
|
+
*/
|
23
|
+
externalize: string;
|
24
|
+
/**
|
25
|
+
* Type of the module. Will be used to determine if import statement is correct.
|
26
|
+
* For example, if Vite needs to throw an error if variable is not actually exported
|
27
|
+
*/
|
28
|
+
type: 'module' | 'commonjs' | 'builtin' | 'network';
|
29
|
+
}
|
30
|
+
interface ViteFetchResult {
|
31
|
+
/**
|
32
|
+
* Code that will be evaluated by vite runner
|
33
|
+
* by default this will be wrapped in an async function
|
34
|
+
*/
|
35
|
+
code: string;
|
36
|
+
/**
|
37
|
+
* File path of the module on disk.
|
38
|
+
* This will be resolved as import.meta.url/filename
|
39
|
+
* Will be equal to `null` for virtual modules
|
40
|
+
*/
|
41
|
+
file: string | null;
|
42
|
+
/**
|
43
|
+
* Module ID in the server module graph.
|
44
|
+
*/
|
45
|
+
id: string;
|
46
|
+
/**
|
47
|
+
* Module URL used in the import.
|
48
|
+
*/
|
49
|
+
url: string;
|
50
|
+
/**
|
51
|
+
* Invalidate module on the client side.
|
52
|
+
*/
|
53
|
+
invalidate: boolean;
|
54
|
+
}
|
55
|
+
type InvokeMethods = {
|
56
|
+
fetchModule: (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
|
57
|
+
};
|
58
|
+
|
59
|
+
type ModuleRunnerTransportHandlers = {
|
60
|
+
onMessage: (data: HotPayload) => void;
|
61
|
+
onDisconnection: () => void;
|
62
|
+
};
|
63
|
+
/**
|
64
|
+
* "send and connect" or "invoke" must be implemented
|
65
|
+
*/
|
66
|
+
interface ModuleRunnerTransport {
|
67
|
+
connect?(handlers: ModuleRunnerTransportHandlers): Promise<void> | void;
|
68
|
+
disconnect?(): Promise<void> | void;
|
69
|
+
send?(data: HotPayload): Promise<void> | void;
|
70
|
+
invoke?(data: HotPayload): Promise<{
|
71
|
+
r: any;
|
72
|
+
} | {
|
73
|
+
e: any;
|
74
|
+
}>;
|
75
|
+
timeout?: number;
|
76
|
+
}
|
77
|
+
interface NormalizedModuleRunnerTransport {
|
78
|
+
connect?(onMessage?: (data: HotPayload) => void): Promise<void> | void;
|
79
|
+
disconnect?(): Promise<void> | void;
|
80
|
+
send(data: HotPayload): void;
|
81
|
+
invoke<T extends keyof InvokeMethods>(name: T, data: Parameters<InvokeMethods[T]>): Promise<ReturnType<Awaited<InvokeMethods[T]>>>;
|
82
|
+
}
|
83
|
+
declare const createWebSocketModuleRunnerTransport: (options: {
|
84
|
+
createConnection: () => WebSocket;
|
85
|
+
pingInterval?: number;
|
86
|
+
}) => Required<Pick<ModuleRunnerTransport, "connect" | "disconnect" | "send">>;
|
87
|
+
|
5
88
|
interface SourceMapLike {
|
6
89
|
version: number;
|
7
90
|
mappings?: string;
|
@@ -39,25 +122,9 @@ interface HMRLogger {
|
|
39
122
|
error(msg: string | Error): void;
|
40
123
|
debug(...msg: unknown[]): void;
|
41
124
|
}
|
42
|
-
interface HMRConnection {
|
43
|
-
/**
|
44
|
-
* Checked before sending messages to the client.
|
45
|
-
*/
|
46
|
-
isReady(): boolean;
|
47
|
-
/**
|
48
|
-
* Send message to the client.
|
49
|
-
*/
|
50
|
-
send(messages: string): void;
|
51
|
-
}
|
52
|
-
declare class HMRMessenger {
|
53
|
-
private connection;
|
54
|
-
constructor(connection: HMRConnection);
|
55
|
-
private queue;
|
56
|
-
send(message: string): void;
|
57
|
-
flush(): void;
|
58
|
-
}
|
59
125
|
declare class HMRClient {
|
60
126
|
logger: HMRLogger;
|
127
|
+
private transport;
|
61
128
|
private importUpdatedModule;
|
62
129
|
hotModulesMap: Map<string, HotModule>;
|
63
130
|
disposeMap: Map<string, (data: any) => void | Promise<void>>;
|
@@ -65,9 +132,9 @@ declare class HMRClient {
|
|
65
132
|
dataMap: Map<string, any>;
|
66
133
|
customListenersMap: CustomListenersMap;
|
67
134
|
ctxToListenersMap: Map<string, CustomListenersMap>;
|
68
|
-
|
69
|
-
constructor(logger: HMRLogger, connection: HMRConnection, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
|
135
|
+
constructor(logger: HMRLogger, transport: NormalizedModuleRunnerTransport, importUpdatedModule: (update: Update) => Promise<ModuleNamespace>);
|
70
136
|
notifyListeners<T extends string>(event: T, data: InferCustomEventPayload<T>): Promise<void>;
|
137
|
+
send(payload: HotPayload): void;
|
71
138
|
clear(): void;
|
72
139
|
prunePaths(paths: string[]): Promise<void>;
|
73
140
|
protected warnFailedUpdate(err: Error, path: string | string[]): void;
|
@@ -111,20 +178,14 @@ declare class ModuleRunner {
|
|
111
178
|
options: ModuleRunnerOptions;
|
112
179
|
evaluator: ModuleEvaluator;
|
113
180
|
private debug?;
|
114
|
-
|
115
|
-
* Holds the cache of modules
|
116
|
-
* Keys of the map are ids
|
117
|
-
*/
|
118
|
-
moduleCache: ModuleCacheMap;
|
181
|
+
evaluatedModules: EvaluatedModules;
|
119
182
|
hmrClient?: HMRClient;
|
120
|
-
private readonly urlToIdMap;
|
121
|
-
private readonly fileToIdMap;
|
122
183
|
private readonly envProxy;
|
123
184
|
private readonly transport;
|
124
185
|
private readonly resetSourceMapSupport?;
|
125
186
|
private readonly root;
|
126
|
-
private readonly
|
127
|
-
private
|
187
|
+
private readonly concurrentModuleNodePromises;
|
188
|
+
private closed;
|
128
189
|
constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
|
129
190
|
/**
|
130
191
|
* URL to execute. Accepts file path, server path or id relative to the root.
|
@@ -138,18 +199,18 @@ declare class ModuleRunner {
|
|
138
199
|
* Clears all caches, removes all HMR listeners, and resets source map support.
|
139
200
|
* This method doesn't stop the HMR connection.
|
140
201
|
*/
|
141
|
-
|
202
|
+
close(): Promise<void>;
|
142
203
|
/**
|
143
|
-
* Returns `true` if the runtime has been
|
204
|
+
* Returns `true` if the runtime has been closed by calling `close()` method.
|
144
205
|
*/
|
145
|
-
|
206
|
+
isClosed(): boolean;
|
146
207
|
private processImport;
|
147
208
|
private isCircularModule;
|
148
209
|
private isCircularImport;
|
149
210
|
private cachedRequest;
|
150
211
|
private cachedModule;
|
151
212
|
private getModuleInformation;
|
152
|
-
protected directRequest(
|
213
|
+
protected directRequest(url: string, mod: EvaluatedModuleNode, _callstack: string[]): Promise<any>;
|
153
214
|
}
|
154
215
|
|
155
216
|
interface RetrieveFileHandler {
|
@@ -166,28 +227,6 @@ interface InterceptorOptions {
|
|
166
227
|
retrieveSourceMap?: RetrieveSourceMapHandler;
|
167
228
|
}
|
168
229
|
|
169
|
-
interface RunnerTransport {
|
170
|
-
fetchModule: FetchFunction;
|
171
|
-
}
|
172
|
-
declare class RemoteRunnerTransport implements RunnerTransport {
|
173
|
-
private readonly options;
|
174
|
-
private rpcPromises;
|
175
|
-
constructor(options: {
|
176
|
-
send: (data: any) => void;
|
177
|
-
onMessage: (handler: (data: any) => void) => void;
|
178
|
-
timeout?: number;
|
179
|
-
});
|
180
|
-
private resolve;
|
181
|
-
fetchModule(id: string, importer?: string): Promise<FetchResult>;
|
182
|
-
}
|
183
|
-
|
184
|
-
interface ModuleRunnerHMRConnection extends HMRConnection {
|
185
|
-
/**
|
186
|
-
* Configure how HMR is handled when this connection triggers an update.
|
187
|
-
* This method expects that connection will start listening for HMR updates and call this callback when it's received.
|
188
|
-
*/
|
189
|
-
onUpdate(callback: (payload: HotPayload) => void): void;
|
190
|
-
}
|
191
230
|
interface ModuleRunnerImportMeta extends ImportMeta {
|
192
231
|
url: string;
|
193
232
|
env: ImportMetaEnv;
|
@@ -202,85 +241,29 @@ interface ModuleRunnerContext {
|
|
202
241
|
[ssrImportMetaKey]: ModuleRunnerImportMeta;
|
203
242
|
}
|
204
243
|
interface ModuleEvaluator {
|
244
|
+
/**
|
245
|
+
* Number of prefixed lines in the transformed code.
|
246
|
+
*/
|
247
|
+
startOffset?: number;
|
205
248
|
/**
|
206
249
|
* Run code that was transformed by Vite.
|
207
250
|
* @param context Function context
|
208
251
|
* @param code Transformed code
|
209
|
-
* @param
|
252
|
+
* @param module The module node
|
210
253
|
*/
|
211
|
-
runInlinedModule(context: ModuleRunnerContext, code: string,
|
254
|
+
runInlinedModule(context: ModuleRunnerContext, code: string, module: Readonly<EvaluatedModuleNode>): Promise<any>;
|
212
255
|
/**
|
213
256
|
* Run externalized module.
|
214
257
|
* @param file File URL to the external module
|
215
258
|
*/
|
216
259
|
runExternalModule(file: string): Promise<any>;
|
217
260
|
}
|
218
|
-
interface ModuleCache {
|
219
|
-
promise?: Promise<any>;
|
220
|
-
exports?: any;
|
221
|
-
evaluated?: boolean;
|
222
|
-
map?: DecodedMap;
|
223
|
-
meta?: ResolvedResult;
|
224
|
-
/**
|
225
|
-
* Module ids that imports this module
|
226
|
-
*/
|
227
|
-
importers?: Set<string>;
|
228
|
-
imports?: Set<string>;
|
229
|
-
}
|
230
|
-
type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
|
231
|
-
interface CachedFetchResult {
|
232
|
-
/**
|
233
|
-
* If module cached in the runner, we can just confirm
|
234
|
-
* it wasn't invalidated on the server side.
|
235
|
-
*/
|
236
|
-
cache: true;
|
237
|
-
}
|
238
|
-
interface ExternalFetchResult {
|
239
|
-
/**
|
240
|
-
* The path to the externalized module starting with file://,
|
241
|
-
* by default this will be imported via a dynamic "import"
|
242
|
-
* instead of being transformed by vite and loaded with vite runner
|
243
|
-
*/
|
244
|
-
externalize: string;
|
245
|
-
/**
|
246
|
-
* Type of the module. Will be used to determine if import statement is correct.
|
247
|
-
* For example, if Vite needs to throw an error if variable is not actually exported
|
248
|
-
*/
|
249
|
-
type?: 'module' | 'commonjs' | 'builtin' | 'network';
|
250
|
-
}
|
251
|
-
interface ViteFetchResult {
|
252
|
-
/**
|
253
|
-
* Code that will be evaluated by vite runner
|
254
|
-
* by default this will be wrapped in an async function
|
255
|
-
*/
|
256
|
-
code: string;
|
257
|
-
/**
|
258
|
-
* File path of the module on disk.
|
259
|
-
* This will be resolved as import.meta.url/filename
|
260
|
-
* Will be equal to `null` for virtual modules
|
261
|
-
*/
|
262
|
-
file: string | null;
|
263
|
-
/**
|
264
|
-
* Module ID in the server module graph.
|
265
|
-
*/
|
266
|
-
serverId: string;
|
267
|
-
/**
|
268
|
-
* Invalidate module on the client side.
|
269
|
-
*/
|
270
|
-
invalidate: boolean;
|
271
|
-
}
|
272
261
|
type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
|
273
262
|
url: string;
|
263
|
+
id: string;
|
274
264
|
};
|
275
265
|
type FetchFunction = (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
|
276
|
-
interface FetchFunctionOptions {
|
277
|
-
cached?: boolean;
|
278
|
-
}
|
279
266
|
interface ModuleRunnerHmr {
|
280
|
-
/**
|
281
|
-
* Configure how HMR communicates between the client and the server.
|
282
|
-
*/
|
283
|
-
connection: ModuleRunnerHMRConnection;
|
284
267
|
/**
|
285
268
|
* Configure HMR logger.
|
286
269
|
*/
|
@@ -294,7 +277,7 @@ interface ModuleRunnerOptions {
|
|
294
277
|
/**
|
295
278
|
* A set of methods to communicate with the server.
|
296
279
|
*/
|
297
|
-
transport:
|
280
|
+
transport: ModuleRunnerTransport;
|
298
281
|
/**
|
299
282
|
* Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
|
300
283
|
* Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
|
@@ -304,11 +287,11 @@ interface ModuleRunnerOptions {
|
|
304
287
|
/**
|
305
288
|
* Disable HMR or configure HMR options.
|
306
289
|
*/
|
307
|
-
hmr?:
|
290
|
+
hmr?: boolean | ModuleRunnerHmr;
|
308
291
|
/**
|
309
292
|
* Custom module cache. If not provided, creates a separate module cache for each ModuleRunner instance.
|
310
293
|
*/
|
311
|
-
|
294
|
+
evaluatedModules?: EvaluatedModules;
|
312
295
|
}
|
313
296
|
interface ImportMetaEnv {
|
314
297
|
[key: string]: any;
|
@@ -319,36 +302,66 @@ interface ImportMetaEnv {
|
|
319
302
|
SSR: boolean;
|
320
303
|
}
|
321
304
|
|
322
|
-
declare class
|
323
|
-
|
324
|
-
|
325
|
-
|
305
|
+
declare class EvaluatedModuleNode {
|
306
|
+
id: string;
|
307
|
+
url: string;
|
308
|
+
importers: Set<string>;
|
309
|
+
imports: Set<string>;
|
310
|
+
evaluated: boolean;
|
311
|
+
meta: ResolvedResult | undefined;
|
312
|
+
promise: Promise<any> | undefined;
|
313
|
+
exports: any | undefined;
|
314
|
+
file: string;
|
315
|
+
map: DecodedMap | undefined;
|
316
|
+
constructor(id: string, url: string);
|
317
|
+
}
|
318
|
+
declare class EvaluatedModules {
|
319
|
+
readonly idToModuleMap: Map<string, EvaluatedModuleNode>;
|
320
|
+
readonly fileToModulesMap: Map<string, Set<EvaluatedModuleNode>>;
|
321
|
+
readonly urlToIdModuleMap: Map<string, EvaluatedModuleNode>;
|
322
|
+
/**
|
323
|
+
* Returns the module node by the resolved module ID. Usually, module ID is
|
324
|
+
* the file system path with query and/or hash. It can also be a virtual module.
|
325
|
+
*
|
326
|
+
* Module runner graph will have 1 to 1 mapping with the server module graph.
|
327
|
+
* @param id Resolved module ID
|
328
|
+
*/
|
329
|
+
getModuleById(id: string): EvaluatedModuleNode | undefined;
|
326
330
|
/**
|
327
|
-
*
|
331
|
+
* Returns all modules related to the file system path. Different modules
|
332
|
+
* might have different query parameters or hash, so it's possible to have
|
333
|
+
* multiple modules for the same file.
|
334
|
+
* @param file The file system path of the module
|
328
335
|
*/
|
329
|
-
|
330
|
-
setByModuleId(modulePath: string, mod: ModuleCache): this;
|
331
|
-
set(fsPath: string, mod: ModuleCache): this;
|
332
|
-
getByModuleId(modulePath: string): ModuleCache;
|
333
|
-
get(fsPath: string): ModuleCache;
|
334
|
-
deleteByModuleId(modulePath: string): boolean;
|
335
|
-
delete(fsPath: string): boolean;
|
336
|
-
invalidateUrl(id: string): void;
|
337
|
-
invalidateModule(module: ModuleCache): void;
|
336
|
+
getModulesByFile(file: string): Set<EvaluatedModuleNode> | undefined;
|
338
337
|
/**
|
339
|
-
*
|
338
|
+
* Returns the module node by the URL that was used in the import statement.
|
339
|
+
* Unlike module graph on the server, the URL is not resolved and is used as is.
|
340
|
+
* @param url Server URL that was used in the import statement
|
340
341
|
*/
|
341
|
-
|
342
|
+
getModuleByUrl(url: string): EvaluatedModuleNode | undefined;
|
342
343
|
/**
|
343
|
-
*
|
344
|
+
* Ensure that module is in the graph. If the module is already in the graph,
|
345
|
+
* it will return the existing module node. Otherwise, it will create a new
|
346
|
+
* module node and add it to the graph.
|
347
|
+
* @param id Resolved module ID
|
348
|
+
* @param url URL that was used in the import statement
|
344
349
|
*/
|
345
|
-
|
346
|
-
|
350
|
+
ensureModule(id: string, url: string): EvaluatedModuleNode;
|
351
|
+
invalidateModule(node: EvaluatedModuleNode): void;
|
352
|
+
/**
|
353
|
+
* Extracts the inlined source map from the module code and returns the decoded
|
354
|
+
* source map. If the source map is not inlined, it will return null.
|
355
|
+
* @param id Resolved module ID
|
356
|
+
*/
|
357
|
+
getModuleSourceMapById(id: string): DecodedMap | null;
|
358
|
+
clear(): void;
|
347
359
|
}
|
348
360
|
|
349
361
|
declare class ESModulesEvaluator implements ModuleEvaluator {
|
362
|
+
startOffset: number;
|
350
363
|
runInlinedModule(context: ModuleRunnerContext, code: string): Promise<any>;
|
351
364
|
runExternalModule(filepath: string): Promise<any>;
|
352
365
|
}
|
353
366
|
|
354
|
-
export { ESModulesEvaluator, type FetchFunction, type FetchFunctionOptions, type FetchResult, type
|
367
|
+
export { ESModulesEvaluator, EvaluatedModuleNode, EvaluatedModules, type FetchFunction, type FetchFunctionOptions, type FetchResult, type HMRLogger, type ModuleEvaluator, ModuleRunner, type ModuleRunnerContext, type ModuleRunnerHmr, type ModuleRunnerImportMeta, type ModuleRunnerOptions, type ModuleRunnerTransport, type ModuleRunnerTransportHandlers, type ResolvedResult, type SSRImportMetadata, createWebSocketModuleRunnerTransport, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
|