vite 5.2.7 → 6.0.0-alpha.0
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/dist/client/client.mjs +4 -1
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-C1QONNHf.js → dep-DUc_OVe8.js} +1 -1
- package/dist/node/chunks/{dep-ThQVBShq.js → dep-b2YSXG5U.js} +1 -1
- package/dist/node/chunks/{dep-C-KAszbv.js → dep-hQh5_mg-.js} +35156 -34048
- package/dist/node/cli.js +52 -23
- package/dist/node/index.d.ts +746 -388
- package/dist/node/index.js +57 -15
- package/dist/node/{types.d-aGj9QkWt.d.ts → module-runner.d.ts} +135 -82
- package/dist/node/{runtime.js → module-runner.js} +115 -83
- package/dist/node-cjs/publicUtils.cjs +2 -2
- package/package.json +6 -6
- package/types/hmrPayload.d.ts +1 -1
- package/dist/node/runtime.d.ts +0 -63
package/dist/node/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
export { parseAst, parseAstAsync } from 'rollup/parseAst';
|
2
|
-
import { i as isInNodeModules, a as arraify } from './chunks/dep-
|
3
|
-
export { b as build,
|
2
|
+
import { i as isInNodeModules, a as arraify } from './chunks/dep-hQh5_mg-.js';
|
3
|
+
export { B as BuildEnvironment, D as DevEnvironment, b as build, h as buildErrorMessage, u as createFilter, x as createLogger, j as createNodeDevEnvironment, c as createServer, e as createViteBuilder, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, z as isFileServingAllowed, l as loadConfigFromFile, A as loadEnv, q as mergeAlias, m as mergeConfig, n as normalizePath, o as optimizeDeps, g as preprocessCSS, p as preview, r as resolveConfig, C as resolveEnvPrefix, v as rollupVersion, y as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-hQh5_mg-.js';
|
4
|
+
import { existsSync, readFileSync } from 'node:fs';
|
5
|
+
import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
|
4
6
|
export { VERSION as version } from './constants.js';
|
5
7
|
export { version as esbuildVersion } from 'esbuild';
|
6
|
-
import { existsSync, readFileSync } from 'node:fs';
|
7
|
-
import { ViteRuntime, ESModulesRunner } from 'vite/runtime';
|
8
8
|
import 'node:fs/promises';
|
9
9
|
import 'node:path';
|
10
10
|
import 'node:url';
|
@@ -29,19 +29,19 @@ import 'child_process';
|
|
29
29
|
import 'node:os';
|
30
30
|
import 'node:crypto';
|
31
31
|
import 'node:dns';
|
32
|
-
import 'crypto';
|
33
|
-
import 'module';
|
34
32
|
import 'node:assert';
|
35
33
|
import 'node:v8';
|
34
|
+
import 'module';
|
36
35
|
import 'node:worker_threads';
|
37
|
-
import 'node:buffer';
|
38
36
|
import 'node:events';
|
39
|
-
import '
|
37
|
+
import 'crypto';
|
38
|
+
import 'node:buffer';
|
40
39
|
import 'node:readline';
|
41
40
|
import 'zlib';
|
42
41
|
import 'buffer';
|
43
42
|
import 'https';
|
44
43
|
import 'tls';
|
44
|
+
import 'querystring';
|
45
45
|
import 'node:zlib';
|
46
46
|
|
47
47
|
// This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
|
@@ -165,6 +165,40 @@ function splitVendorChunkPlugin() {
|
|
165
165
|
};
|
166
166
|
}
|
167
167
|
|
168
|
+
class RemoteEnvironmentTransport {
|
169
|
+
options;
|
170
|
+
constructor(options) {
|
171
|
+
this.options = options;
|
172
|
+
}
|
173
|
+
register(environment) {
|
174
|
+
this.options.onMessage(async (data) => {
|
175
|
+
if (typeof data !== 'object' || !data || !data.__v)
|
176
|
+
return;
|
177
|
+
const method = data.m;
|
178
|
+
const parameters = data.a;
|
179
|
+
try {
|
180
|
+
const result = await environment[method](...parameters);
|
181
|
+
this.options.send({
|
182
|
+
__v: true,
|
183
|
+
r: result,
|
184
|
+
i: data.i,
|
185
|
+
});
|
186
|
+
}
|
187
|
+
catch (error) {
|
188
|
+
this.options.send({
|
189
|
+
__v: true,
|
190
|
+
e: {
|
191
|
+
name: error.name,
|
192
|
+
message: error.message,
|
193
|
+
stack: error.stack,
|
194
|
+
},
|
195
|
+
i: data.i,
|
196
|
+
});
|
197
|
+
}
|
198
|
+
});
|
199
|
+
}
|
200
|
+
}
|
201
|
+
|
168
202
|
class ServerHMRBroadcasterClient {
|
169
203
|
hmrChannel;
|
170
204
|
constructor(hmrChannel) {
|
@@ -226,6 +260,12 @@ function createHMROptions(server, options) {
|
|
226
260
|
if (server.config.server.hmr === false || options.hmr === false) {
|
227
261
|
return false;
|
228
262
|
}
|
263
|
+
if (options.hmr?.connection) {
|
264
|
+
return {
|
265
|
+
connection: options.hmr.connection,
|
266
|
+
logger: options.hmr.logger,
|
267
|
+
};
|
268
|
+
}
|
229
269
|
const connection = new ServerHMRConnector(server);
|
230
270
|
return {
|
231
271
|
connection,
|
@@ -258,15 +298,17 @@ function resolveSourceMapOptions(options) {
|
|
258
298
|
* Create an instance of the Vite SSR runtime that support HMR.
|
259
299
|
* @experimental
|
260
300
|
*/
|
261
|
-
|
262
|
-
const hmr = createHMROptions(server, options);
|
263
|
-
return new
|
301
|
+
function createServerModuleRunner(environment, options = {}) {
|
302
|
+
const hmr = createHMROptions(environment.server, options);
|
303
|
+
return new ModuleRunner({
|
264
304
|
...options,
|
265
|
-
root:
|
266
|
-
|
305
|
+
root: environment.config.root,
|
306
|
+
transport: {
|
307
|
+
fetchModule: (id, importer) => environment.fetchModule(id, importer),
|
308
|
+
},
|
267
309
|
hmr,
|
268
310
|
sourcemapInterceptor: resolveSourceMapOptions(options),
|
269
|
-
}, options.runner || new
|
311
|
+
}, options.runner || new ESModulesEvaluator());
|
270
312
|
}
|
271
313
|
|
272
|
-
export { ServerHMRConnector,
|
314
|
+
export { RemoteEnvironmentTransport, ServerHMRConnector, createServerModuleRunner, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
|
@@ -2,6 +2,30 @@ import { ModuleNamespace, ViteHotContext } from '../../types/hot.js';
|
|
2
2
|
import { Update, HMRPayload } from '../../types/hmrPayload.js';
|
3
3
|
import { InferCustomEventPayload } from '../../types/customEvent.js';
|
4
4
|
|
5
|
+
interface SourceMapLike {
|
6
|
+
version: number;
|
7
|
+
mappings?: string;
|
8
|
+
names?: string[];
|
9
|
+
sources?: string[];
|
10
|
+
sourcesContent?: string[];
|
11
|
+
}
|
12
|
+
declare class DecodedMap {
|
13
|
+
map: SourceMapLike;
|
14
|
+
_encoded: string;
|
15
|
+
_decoded: undefined | number[][][];
|
16
|
+
_decodedMemo: Stats;
|
17
|
+
url: string;
|
18
|
+
version: number;
|
19
|
+
names: string[];
|
20
|
+
resolvedSources: string[];
|
21
|
+
constructor(map: SourceMapLike, from: string);
|
22
|
+
}
|
23
|
+
interface Stats {
|
24
|
+
lastKey: number;
|
25
|
+
lastNeedle: number;
|
26
|
+
lastIndex: number;
|
27
|
+
}
|
28
|
+
|
5
29
|
type CustomListenersMap = Map<string, ((data: any) => void)[]>;
|
6
30
|
interface HotModule {
|
7
31
|
id: string;
|
@@ -74,66 +98,57 @@ interface SSRImportBaseMetadata extends DefineImportMetadata {
|
|
74
98
|
isDynamicImport?: boolean;
|
75
99
|
}
|
76
100
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
sourcesContent?: string[];
|
83
|
-
}
|
84
|
-
declare class DecodedMap {
|
85
|
-
map: SourceMapLike;
|
86
|
-
_encoded: string;
|
87
|
-
_decoded: undefined | number[][][];
|
88
|
-
_decodedMemo: Stats;
|
89
|
-
url: string;
|
90
|
-
version: number;
|
91
|
-
names: string[];
|
92
|
-
resolvedSources: string[];
|
93
|
-
constructor(map: SourceMapLike, from: string);
|
94
|
-
}
|
95
|
-
interface Stats {
|
96
|
-
lastKey: number;
|
97
|
-
lastNeedle: number;
|
98
|
-
lastIndex: number;
|
99
|
-
}
|
101
|
+
declare const ssrModuleExportsKey = "__vite_ssr_exports__";
|
102
|
+
declare const ssrImportKey = "__vite_ssr_import__";
|
103
|
+
declare const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
|
104
|
+
declare const ssrExportAllKey = "__vite_ssr_exportAll__";
|
105
|
+
declare const ssrImportMetaKey = "__vite_ssr_import_meta__";
|
100
106
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
107
|
+
interface ModuleRunnerDebugger {
|
108
|
+
(formatter: unknown, ...args: unknown[]): void;
|
109
|
+
}
|
110
|
+
declare class ModuleRunner {
|
111
|
+
options: ModuleRunnerOptions;
|
112
|
+
evaluator: ModuleEvaluator;
|
113
|
+
private debug?;
|
105
114
|
/**
|
106
|
-
*
|
115
|
+
* Holds the cache of modules
|
116
|
+
* Keys of the map are ids
|
107
117
|
*/
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
importedId: string;
|
118
|
-
importedBy: string;
|
119
|
-
}, seen?: Set<string>): boolean;
|
118
|
+
moduleCache: ModuleCacheMap;
|
119
|
+
hmrClient?: HMRClient;
|
120
|
+
private idToUrlMap;
|
121
|
+
private fileToIdMap;
|
122
|
+
private envProxy;
|
123
|
+
private transport;
|
124
|
+
private _destroyed;
|
125
|
+
private _resetSourceMapSupport?;
|
126
|
+
constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
|
120
127
|
/**
|
121
|
-
*
|
128
|
+
* URL to execute. Accepts file path, server path or id relative to the root.
|
122
129
|
*/
|
123
|
-
|
130
|
+
import<T = any>(url: string): Promise<T>;
|
124
131
|
/**
|
125
|
-
*
|
132
|
+
* Clear all caches including HMR listeners.
|
126
133
|
*/
|
127
|
-
|
128
|
-
|
134
|
+
clearCache(): void;
|
135
|
+
/**
|
136
|
+
* Clears all caches, removes all HMR listeners, and resets source map support.
|
137
|
+
* This method doesn't stop the HMR connection.
|
138
|
+
*/
|
139
|
+
destroy(): Promise<void>;
|
140
|
+
/**
|
141
|
+
* Returns `true` if the runtime has been destroyed by calling `destroy()` method.
|
142
|
+
*/
|
143
|
+
isDestroyed(): boolean;
|
144
|
+
private invalidateFiles;
|
145
|
+
private normalizeEntryUrl;
|
146
|
+
private processImport;
|
147
|
+
private cachedRequest;
|
148
|
+
private cachedModule;
|
149
|
+
protected directRequest(id: string, fetchResult: ResolvedResult, _callstack: string[]): Promise<any>;
|
129
150
|
}
|
130
151
|
|
131
|
-
declare const ssrModuleExportsKey = "__vite_ssr_exports__";
|
132
|
-
declare const ssrImportKey = "__vite_ssr_import__";
|
133
|
-
declare const ssrDynamicImportKey = "__vite_ssr_dynamic_import__";
|
134
|
-
declare const ssrExportAllKey = "__vite_ssr_exportAll__";
|
135
|
-
declare const ssrImportMetaKey = "__vite_ssr_import_meta__";
|
136
|
-
|
137
152
|
interface RetrieveFileHandler {
|
138
153
|
(path: string): string | null | undefined | false;
|
139
154
|
}
|
@@ -148,37 +163,49 @@ interface InterceptorOptions {
|
|
148
163
|
retrieveSourceMap?: RetrieveSourceMapHandler;
|
149
164
|
}
|
150
165
|
|
151
|
-
interface
|
152
|
-
|
166
|
+
interface RunnerTransport {
|
167
|
+
fetchModule: FetchFunction;
|
153
168
|
}
|
154
|
-
|
169
|
+
declare class RemoteRunnerTransport implements RunnerTransport {
|
170
|
+
private readonly options;
|
171
|
+
private rpcPromises;
|
172
|
+
constructor(options: {
|
173
|
+
send: (data: any) => void;
|
174
|
+
onMessage: (handler: (data: any) => void) => void;
|
175
|
+
timeout?: number;
|
176
|
+
});
|
177
|
+
private resolve;
|
178
|
+
fetchModule(id: string, importer?: string): Promise<FetchResult>;
|
179
|
+
}
|
180
|
+
|
181
|
+
interface ModuleRunnerHMRConnection extends HMRConnection {
|
155
182
|
/**
|
156
183
|
* Configure how HMR is handled when this connection triggers an update.
|
157
184
|
* This method expects that connection will start listening for HMR updates and call this callback when it's received.
|
158
185
|
*/
|
159
186
|
onUpdate(callback: (payload: HMRPayload) => void): void;
|
160
187
|
}
|
161
|
-
interface
|
188
|
+
interface ModuleRunnerImportMeta extends ImportMeta {
|
162
189
|
url: string;
|
163
190
|
env: ImportMetaEnv;
|
164
191
|
hot?: ViteHotContext;
|
165
192
|
[key: string]: any;
|
166
193
|
}
|
167
|
-
interface
|
194
|
+
interface ModuleRunnerContext {
|
168
195
|
[ssrModuleExportsKey]: Record<string, any>;
|
169
196
|
[ssrImportKey]: (id: string, metadata?: DefineImportMetadata) => Promise<any>;
|
170
197
|
[ssrDynamicImportKey]: (id: string, options?: ImportCallOptions) => Promise<any>;
|
171
198
|
[ssrExportAllKey]: (obj: any) => void;
|
172
|
-
[ssrImportMetaKey]:
|
199
|
+
[ssrImportMetaKey]: ModuleRunnerImportMeta;
|
173
200
|
}
|
174
|
-
interface
|
201
|
+
interface ModuleEvaluator {
|
175
202
|
/**
|
176
203
|
* Run code that was transformed by Vite.
|
177
204
|
* @param context Function context
|
178
205
|
* @param code Transformed code
|
179
206
|
* @param id ID that was used to fetch the module
|
180
207
|
*/
|
181
|
-
|
208
|
+
runInlinedModule(context: ModuleRunnerContext, code: string, id: string): Promise<any>;
|
182
209
|
/**
|
183
210
|
* Run externalized module.
|
184
211
|
* @param file File URL to the external module
|
@@ -202,7 +229,7 @@ interface ExternalFetchResult {
|
|
202
229
|
/**
|
203
230
|
* The path to the externalized module starting with file://,
|
204
231
|
* by default this will be imported via a dynamic "import"
|
205
|
-
* instead of being transformed by vite and loaded with vite
|
232
|
+
* instead of being transformed by vite and loaded with vite runner
|
206
233
|
*/
|
207
234
|
externalize: string;
|
208
235
|
/**
|
@@ -213,7 +240,7 @@ interface ExternalFetchResult {
|
|
213
240
|
}
|
214
241
|
interface ViteFetchResult {
|
215
242
|
/**
|
216
|
-
* Code that will be evaluated by vite
|
243
|
+
* Code that will be evaluated by vite runner
|
217
244
|
* by default this will be wrapped in an async function
|
218
245
|
*/
|
219
246
|
code: string;
|
@@ -230,21 +257,25 @@ type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
|
|
230
257
|
* @experimental
|
231
258
|
*/
|
232
259
|
type FetchFunction = (id: string, importer?: string) => Promise<FetchResult>;
|
233
|
-
interface
|
260
|
+
interface ModuleRunnerHmr {
|
234
261
|
/**
|
235
|
-
*
|
262
|
+
* Configure how HMR communicates between the client and the server.
|
236
263
|
*/
|
237
|
-
|
264
|
+
connection: ModuleRunnerHMRConnection;
|
238
265
|
/**
|
239
|
-
*
|
240
|
-
* For SSR, Vite exposes `server.ssrFetchModule` function that you can use here.
|
241
|
-
* For other runtime use cases, Vite also exposes `fetchModule` from its main entry point.
|
266
|
+
* Configure HMR logger.
|
242
267
|
*/
|
243
|
-
|
268
|
+
logger?: false | HMRLogger;
|
269
|
+
}
|
270
|
+
interface ModuleRunnerOptions {
|
271
|
+
/**
|
272
|
+
* Root of the project
|
273
|
+
*/
|
274
|
+
root: string;
|
244
275
|
/**
|
245
|
-
*
|
276
|
+
* A set of methods to communicate with the server.
|
246
277
|
*/
|
247
|
-
|
278
|
+
transport: RunnerTransport;
|
248
279
|
/**
|
249
280
|
* Configure how source maps are resolved. Prefers `node` if `process.setSourceMapsEnabled` is available.
|
250
281
|
* Otherwise it will use `prepareStackTrace` by default which overrides `Error.prepareStackTrace` method.
|
@@ -254,18 +285,9 @@ interface ViteRuntimeOptions {
|
|
254
285
|
/**
|
255
286
|
* Disable HMR or configure HMR options.
|
256
287
|
*/
|
257
|
-
hmr?: false |
|
258
|
-
/**
|
259
|
-
* Configure how HMR communicates between the client and the server.
|
260
|
-
*/
|
261
|
-
connection: HMRRuntimeConnection;
|
262
|
-
/**
|
263
|
-
* Configure HMR logger.
|
264
|
-
*/
|
265
|
-
logger?: false | HMRLogger;
|
266
|
-
};
|
288
|
+
hmr?: false | ModuleRunnerHmr;
|
267
289
|
/**
|
268
|
-
* Custom module cache. If not provided, creates a separate module cache for each
|
290
|
+
* Custom module cache. If not provided, creates a separate module cache for each ModuleRunner instance.
|
269
291
|
*/
|
270
292
|
moduleCache?: ModuleCacheMap;
|
271
293
|
}
|
@@ -278,4 +300,35 @@ interface ImportMetaEnv {
|
|
278
300
|
SSR: boolean;
|
279
301
|
}
|
280
302
|
|
281
|
-
|
303
|
+
declare class ModuleCacheMap extends Map<string, ModuleCache> {
|
304
|
+
private root;
|
305
|
+
constructor(root: string, entries?: [string, ModuleCache][]);
|
306
|
+
normalize(fsPath: string): string;
|
307
|
+
/**
|
308
|
+
* Assign partial data to the map
|
309
|
+
*/
|
310
|
+
update(fsPath: string, mod: ModuleCache): this;
|
311
|
+
setByModuleId(modulePath: string, mod: ModuleCache): this;
|
312
|
+
set(fsPath: string, mod: ModuleCache): this;
|
313
|
+
getByModuleId(modulePath: string): ModuleCache;
|
314
|
+
get(fsPath: string): ModuleCache;
|
315
|
+
deleteByModuleId(modulePath: string): boolean;
|
316
|
+
delete(fsPath: string): boolean;
|
317
|
+
invalidate(id: string): void;
|
318
|
+
/**
|
319
|
+
* Invalidate modules that dependent on the given modules, up to the main entry
|
320
|
+
*/
|
321
|
+
invalidateDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
|
322
|
+
/**
|
323
|
+
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
|
324
|
+
*/
|
325
|
+
invalidateSubDepTree(ids: string[] | Set<string>, invalidated?: Set<string>): Set<string>;
|
326
|
+
getSourceMap(moduleId: string): null | DecodedMap;
|
327
|
+
}
|
328
|
+
|
329
|
+
declare class ESModulesEvaluator implements ModuleEvaluator {
|
330
|
+
runInlinedModule(context: ModuleRunnerContext, code: string): Promise<any>;
|
331
|
+
runExternalModule(filepath: string): Promise<any>;
|
332
|
+
}
|
333
|
+
|
334
|
+
export { ESModulesEvaluator, type FetchFunction, type FetchResult, type HMRConnection, type HMRLogger, type ModuleCache, ModuleCacheMap, type ModuleEvaluator, ModuleRunner, type ModuleRunnerContext, type ModuleRunnerHMRConnection, type ModuleRunnerHmr, type ModuleRunnerImportMeta, type ModuleRunnerOptions, RemoteRunnerTransport, type ResolvedResult, type RunnerTransport, type SSRImportBaseMetadata as SSRImportMetadata, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };
|