vite 6.0.0-alpha.2 → 6.0.0-alpha.21

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.
@@ -1,10 +1,9 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-E4cF1RpV.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-E4cF1RpV.js';
4
- import { existsSync, readFileSync } from 'node:fs';
5
- import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-D2vSWyBt.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, j as buildErrorMessage, e as createBuilder, x as createFilter, f as createIdResolver, A as createLogger, k as createNodeDevEnvironment, c as createServer, n as createServerModuleRunner, d as defineConfig, m as fetchModule, g as formatPostcssSourceMap, F as isFileLoadingAllowed, E as isFileServingAllowed, l as loadConfigFromFile, G as loadEnv, w as mergeAlias, v as mergeConfig, q as moduleRunnerTransform, u as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, H as resolveEnvPrefix, y as rollupVersion, C as searchForWorkspaceRoot, z as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-D2vSWyBt.js';
6
4
  export { 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';
@@ -14,13 +13,15 @@ import 'node:module';
14
13
  import 'tty';
15
14
  import 'path';
16
15
  import 'fs';
17
- import 'events';
18
- import 'assert';
16
+ import 'node:events';
17
+ import 'node:stream';
18
+ import 'node:string_decoder';
19
19
  import 'node:child_process';
20
20
  import 'node:http';
21
21
  import 'node:https';
22
22
  import 'util';
23
23
  import 'net';
24
+ import 'events';
24
25
  import 'url';
25
26
  import 'http';
26
27
  import 'stream';
@@ -29,11 +30,11 @@ import 'child_process';
29
30
  import 'node:os';
30
31
  import 'node:crypto';
31
32
  import 'node:dns';
33
+ import 'vite/module-runner';
34
+ import 'module';
32
35
  import 'node:assert';
33
36
  import 'node:v8';
34
- import 'module';
35
37
  import 'node:worker_threads';
36
- import 'node:events';
37
38
  import 'crypto';
38
39
  import 'node:buffer';
39
40
  import 'node:readline';
@@ -41,274 +42,143 @@ import 'zlib';
41
42
  import 'buffer';
42
43
  import 'https';
43
44
  import 'tls';
45
+ import 'assert';
44
46
  import 'querystring';
45
47
  import 'node:zlib';
46
48
 
47
- // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
48
- // copy from constants.ts
49
- const CSS_LANGS_RE =
50
- // eslint-disable-next-line regexp/no-unused-capturing-group
51
- /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
49
+ const CSS_LANGS_RE = (
50
+ // eslint-disable-next-line regexp/no-unused-capturing-group
51
+ /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
52
+ );
52
53
  const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
53
- // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
54
- // We don't recommend using this strategy as a general solution moving forward
55
- // splitVendorChunk is a simple index/vendor strategy that was used in Vite
56
- // until v2.8. It is exposed to let people continue to use it in case it was
57
- // working well for their setups.
58
- // The cache needs to be reset on buildStart for watch mode to work correctly
59
- // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
60
- /**
61
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
62
- */
63
54
  class SplitVendorChunkCache {
64
- cache;
65
- constructor() {
66
- this.cache = new Map();
67
- }
68
- reset() {
69
- this.cache = new Map();
70
- }
55
+ cache;
56
+ constructor() {
57
+ this.cache = /* @__PURE__ */ new Map();
58
+ }
59
+ reset() {
60
+ this.cache = /* @__PURE__ */ new Map();
61
+ }
71
62
  }
72
- /**
73
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
74
- */
75
63
  function splitVendorChunk(options = {}) {
76
- const cache = options.cache ?? new SplitVendorChunkCache();
77
- return (id, { getModuleInfo }) => {
78
- if (isInNodeModules(id) &&
79
- !isCSSRequest(id) &&
80
- staticImportedByEntry(id, getModuleInfo, cache.cache)) {
81
- return 'vendor';
82
- }
83
- };
64
+ const cache = options.cache ?? new SplitVendorChunkCache();
65
+ return (id, { getModuleInfo }) => {
66
+ if (isInNodeModules(id) && !isCSSRequest(id) && staticImportedByEntry(id, getModuleInfo, cache.cache)) {
67
+ return "vendor";
68
+ }
69
+ };
84
70
  }
85
71
  function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
86
- if (cache.has(id)) {
87
- return cache.get(id);
88
- }
89
- if (importStack.includes(id)) {
90
- // circular deps!
91
- cache.set(id, false);
92
- return false;
93
- }
94
- const mod = getModuleInfo(id);
95
- if (!mod) {
96
- cache.set(id, false);
97
- return false;
98
- }
99
- if (mod.isEntry) {
100
- cache.set(id, true);
101
- return true;
102
- }
103
- const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
104
- cache.set(id, someImporterIs);
105
- return someImporterIs;
72
+ if (cache.has(id)) {
73
+ return cache.get(id);
74
+ }
75
+ if (importStack.includes(id)) {
76
+ cache.set(id, false);
77
+ return false;
78
+ }
79
+ const mod = getModuleInfo(id);
80
+ if (!mod) {
81
+ cache.set(id, false);
82
+ return false;
83
+ }
84
+ if (mod.isEntry) {
85
+ cache.set(id, true);
86
+ return true;
87
+ }
88
+ const someImporterIs = mod.importers.some(
89
+ (importer) => staticImportedByEntry(
90
+ importer,
91
+ getModuleInfo,
92
+ cache,
93
+ importStack.concat(id)
94
+ )
95
+ );
96
+ cache.set(id, someImporterIs);
97
+ return someImporterIs;
106
98
  }
107
- /**
108
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
109
- */
110
99
  function splitVendorChunkPlugin() {
111
- const caches = [];
112
- function createSplitVendorChunk(output, config) {
113
- const cache = new SplitVendorChunkCache();
114
- caches.push(cache);
115
- const build = config.build ?? {};
116
- const format = output?.format;
117
- if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
118
- return splitVendorChunk({ cache });
119
- }
120
- }
121
- return {
122
- name: 'vite:split-vendor-chunk',
123
- config(config) {
124
- let outputs = config?.build?.rollupOptions?.output;
125
- if (outputs) {
126
- outputs = arraify(outputs);
127
- for (const output of outputs) {
128
- const viteManualChunks = createSplitVendorChunk(output, config);
129
- if (viteManualChunks) {
130
- if (output.manualChunks) {
131
- if (typeof output.manualChunks === 'function') {
132
- const userManualChunks = output.manualChunks;
133
- output.manualChunks = (id, api) => {
134
- return userManualChunks(id, api) ?? viteManualChunks(id, api);
135
- };
136
- }
137
- else {
138
- // else, leave the object form of manualChunks untouched, as
139
- // we can't safely replicate rollup handling.
140
- // eslint-disable-next-line no-console
141
- console.warn("(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead.");
142
- }
143
- }
144
- else {
145
- output.manualChunks = viteManualChunks;
146
- }
147
- }
148
- }
149
- }
150
- else {
151
- return {
152
- build: {
153
- rollupOptions: {
154
- output: {
155
- manualChunks: createSplitVendorChunk({}, config),
156
- },
157
- },
158
- },
100
+ const caches = [];
101
+ function createSplitVendorChunk(output, config) {
102
+ const cache = new SplitVendorChunkCache();
103
+ caches.push(cache);
104
+ const build = config.build ?? {};
105
+ const format = output?.format;
106
+ if (!build.ssr && !build.lib && format !== "umd" && format !== "iife") {
107
+ return splitVendorChunk({ cache });
108
+ }
109
+ }
110
+ return {
111
+ name: "vite:split-vendor-chunk",
112
+ config(config) {
113
+ let outputs = config?.build?.rollupOptions?.output;
114
+ if (outputs) {
115
+ outputs = arraify(outputs);
116
+ for (const output of outputs) {
117
+ const viteManualChunks = createSplitVendorChunk(output, config);
118
+ if (viteManualChunks) {
119
+ if (output.manualChunks) {
120
+ if (typeof output.manualChunks === "function") {
121
+ const userManualChunks = output.manualChunks;
122
+ output.manualChunks = (id, api) => {
123
+ return userManualChunks(id, api) ?? viteManualChunks(id, api);
159
124
  };
125
+ } else {
126
+ console.warn(
127
+ "(!) the `splitVendorChunk` plugin doesn't have any effect when using the object form of `build.rollupOptions.output.manualChunks`. Consider using the function form instead."
128
+ );
129
+ }
130
+ } else {
131
+ output.manualChunks = viteManualChunks;
160
132
  }
161
- },
162
- buildStart() {
163
- caches.forEach((cache) => cache.reset());
164
- },
165
- };
166
- }
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
-
202
- class ServerHMRBroadcasterClient {
203
- hmrChannel;
204
- constructor(hmrChannel) {
205
- this.hmrChannel = hmrChannel;
206
- }
207
- send(...args) {
208
- let payload;
209
- if (typeof args[0] === 'string') {
210
- payload = {
211
- type: 'custom',
212
- event: args[0],
213
- data: args[1],
214
- };
215
- }
216
- else {
217
- payload = args[0];
218
- }
219
- if (payload.type !== 'custom') {
220
- throw new Error('Cannot send non-custom events from the client to the server.');
221
- }
222
- this.hmrChannel.send(payload);
223
- }
224
- }
225
- /**
226
- * The connector class to establish HMR communication between the server and the Vite runtime.
227
- * @experimental
228
- */
229
- class ServerHMRConnector {
230
- handlers = [];
231
- hmrChannel;
232
- hmrClient;
233
- connected = false;
234
- constructor(server) {
235
- const hmrChannel = server.hot?.channels.find((c) => c.name === 'ssr');
236
- if (!hmrChannel) {
237
- throw new Error("Your version of Vite doesn't support HMR during SSR. Please, use Vite 5.1 or higher.");
133
+ }
238
134
  }
239
- this.hmrClient = new ServerHMRBroadcasterClient(hmrChannel);
240
- hmrChannel.api.outsideEmitter.on('send', (payload) => {
241
- this.handlers.forEach((listener) => listener(payload));
242
- });
243
- this.hmrChannel = hmrChannel;
244
- }
245
- isReady() {
246
- return this.connected;
247
- }
248
- send(message) {
249
- const payload = JSON.parse(message);
250
- this.hmrChannel.api.innerEmitter.emit(payload.event, payload.data, this.hmrClient);
251
- }
252
- onUpdate(handler) {
253
- this.handlers.push(handler);
254
- handler({ type: 'connected' });
255
- this.connected = true;
256
- }
257
- }
258
-
259
- function createHMROptions(server, options) {
260
- if (server.config.server.hmr === false || options.hmr === false) {
261
- return false;
262
- }
263
- if (options.hmr?.connection) {
135
+ } else {
264
136
  return {
265
- connection: options.hmr.connection,
266
- logger: options.hmr.logger,
137
+ build: {
138
+ rollupOptions: {
139
+ output: {
140
+ manualChunks: createSplitVendorChunk({}, config)
141
+ }
142
+ }
143
+ }
267
144
  };
268
- }
269
- const connection = new ServerHMRConnector(server);
270
- return {
271
- connection,
272
- logger: options.hmr?.logger,
273
- };
274
- }
275
- const prepareStackTrace = {
276
- retrieveFile(id) {
277
- if (existsSync(id)) {
278
- return readFileSync(id, 'utf-8');
279
- }
145
+ }
280
146
  },
281
- };
282
- function resolveSourceMapOptions(options) {
283
- if (options.sourcemapInterceptor != null) {
284
- if (options.sourcemapInterceptor === 'prepareStackTrace') {
285
- return prepareStackTrace;
286
- }
287
- if (typeof options.sourcemapInterceptor === 'object') {
288
- return { ...prepareStackTrace, ...options.sourcemapInterceptor };
289
- }
290
- return options.sourcemapInterceptor;
291
- }
292
- if (typeof process !== 'undefined' && 'setSourceMapsEnabled' in process) {
293
- return 'node';
147
+ buildStart() {
148
+ caches.forEach((cache) => cache.reset());
294
149
  }
295
- return prepareStackTrace;
150
+ };
296
151
  }
297
- /**
298
- * Create an instance of the Vite SSR runtime that support HMR.
299
- * @experimental
300
- */
301
- function createServerModuleRunner(environment, options = {}) {
302
- const hmr = createHMROptions(environment.server, options);
303
- return new ModuleRunner({
304
- ...options,
305
- root: environment.config.root,
306
- transport: {
307
- fetchModule: (id, importer) => environment.fetchModule(id, importer),
308
- },
309
- hmr,
310
- sourcemapInterceptor: resolveSourceMapOptions(options),
311
- }, options.runner || new ESModulesEvaluator());
152
+
153
+ class RemoteEnvironmentTransport {
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
+ }
312
182
  }
313
183
 
314
- export { RemoteEnvironmentTransport, ServerHMRConnector, createServerModuleRunner, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
184
+ export { RemoteEnvironmentTransport, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
@@ -1,5 +1,5 @@
1
1
  import { ModuleNamespace, ViteHotContext } from '../../types/hot.js';
2
- import { Update, HMRPayload } from '../../types/hmrPayload.js';
2
+ import { Update, HotPayload } from '../../types/hmrPayload.js';
3
3
  import { InferCustomEventPayload } from '../../types/customEvent.js';
4
4
 
5
5
  interface SourceMapLike {
@@ -117,12 +117,13 @@ declare class ModuleRunner {
117
117
  */
118
118
  moduleCache: ModuleCacheMap;
119
119
  hmrClient?: HMRClient;
120
- private idToUrlMap;
121
- private fileToIdMap;
122
- private envProxy;
123
- private transport;
124
- private _destroyed;
125
- private _resetSourceMapSupport?;
120
+ private readonly urlToIdMap;
121
+ private readonly fileToIdMap;
122
+ private readonly envProxy;
123
+ private readonly transport;
124
+ private readonly resetSourceMapSupport?;
125
+ private readonly root;
126
+ private destroyed;
126
127
  constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
127
128
  /**
128
129
  * URL to execute. Accepts file path, server path or id relative to the root.
@@ -141,12 +142,13 @@ declare class ModuleRunner {
141
142
  * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
142
143
  */
143
144
  isDestroyed(): boolean;
144
- private invalidateFiles;
145
145
  private normalizeEntryUrl;
146
146
  private processImport;
147
+ private isCircularModule;
148
+ private isCircularImport;
147
149
  private cachedRequest;
148
150
  private cachedModule;
149
- protected directRequest(id: string, fetchResult: ResolvedResult, _callstack: string[]): Promise<any>;
151
+ protected directRequest(id: string, mod: ModuleCache, _callstack: string[]): Promise<any>;
150
152
  }
151
153
 
152
154
  interface RetrieveFileHandler {
@@ -183,7 +185,7 @@ interface ModuleRunnerHMRConnection extends HMRConnection {
183
185
  * Configure how HMR is handled when this connection triggers an update.
184
186
  * This method expects that connection will start listening for HMR updates and call this callback when it's received.
185
187
  */
186
- onUpdate(callback: (payload: HMRPayload) => void): void;
188
+ onUpdate(callback: (payload: HotPayload) => void): void;
187
189
  }
188
190
  interface ModuleRunnerImportMeta extends ImportMeta {
189
191
  url: string;
@@ -217,14 +219,21 @@ interface ModuleCache {
217
219
  exports?: any;
218
220
  evaluated?: boolean;
219
221
  map?: DecodedMap;
220
- meta?: FetchResult;
222
+ meta?: ResolvedResult;
221
223
  /**
222
224
  * Module ids that imports this module
223
225
  */
224
226
  importers?: Set<string>;
225
227
  imports?: Set<string>;
226
228
  }
227
- type FetchResult = ExternalFetchResult | ViteFetchResult;
229
+ type FetchResult = CachedFetchResult | ExternalFetchResult | ViteFetchResult;
230
+ interface CachedFetchResult {
231
+ /**
232
+ * If module cached in the runner, we can just confirm
233
+ * it wasn't invalidated on the server side.
234
+ */
235
+ cache: true;
236
+ }
228
237
  interface ExternalFetchResult {
229
238
  /**
230
239
  * The path to the externalized module starting with file://,
@@ -247,16 +256,21 @@ interface ViteFetchResult {
247
256
  /**
248
257
  * File path of the module on disk.
249
258
  * This will be resolved as import.meta.url/filename
259
+ * Will be equal to `null` for virtual modules
250
260
  */
251
261
  file: string | null;
262
+ /**
263
+ * Invalidate module on the client side.
264
+ */
265
+ invalidate: boolean;
252
266
  }
253
267
  type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
254
268
  id: string;
255
269
  };
256
- /**
257
- * @experimental
258
- */
259
- type FetchFunction = (id: string, importer?: string) => Promise<FetchResult>;
270
+ type FetchFunction = (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
271
+ interface FetchFunctionOptions {
272
+ cached?: boolean;
273
+ }
260
274
  interface ModuleRunnerHmr {
261
275
  /**
262
276
  * Configure how HMR communicates between the client and the server.
@@ -314,7 +328,8 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
314
328
  get(fsPath: string): ModuleCache;
315
329
  deleteByModuleId(modulePath: string): boolean;
316
330
  delete(fsPath: string): boolean;
317
- invalidate(id: string): void;
331
+ invalidateUrl(id: string): void;
332
+ invalidateModule(module: ModuleCache): void;
318
333
  /**
319
334
  * Invalidate modules that dependent on the given modules, up to the main entry
320
335
  */
@@ -331,4 +346,4 @@ declare class ESModulesEvaluator implements ModuleEvaluator {
331
346
  runExternalModule(filepath: string): Promise<any>;
332
347
  }
333
348
 
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 };
349
+ export { ESModulesEvaluator, type FetchFunction, type FetchFunctionOptions, 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 };