vite 6.0.0-alpha.8 → 6.0.0-beta.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.
@@ -1,26 +1,28 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-8PNdpITG.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, e as createBuilder, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, d as defineConfig, k as fetchModule, f as formatPostcssSourceMap, y as isFileServingAllowed, l as loadConfigFromFile, z as loadEnv, q as mergeAlias, o as mergeConfig, n as normalizePath, g as preprocessCSS, p as preview, r as resolveConfig, A as resolveEnvPrefix, v as rollupVersion, x as searchForWorkspaceRoot, w as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-8PNdpITG.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-Bv1xMYNy.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, 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 createServerHotChannel, 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-Bv1xMYNy.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
- export { c as createLogger } from './chunks/dep-C7zR1Rh8.js';
7
- import 'node:fs';
8
8
  import 'node:fs/promises';
9
9
  import 'node:path';
10
10
  import 'node:url';
11
11
  import 'node:util';
12
12
  import 'node:perf_hooks';
13
13
  import 'node:module';
14
+ import 'tty';
14
15
  import 'path';
15
16
  import 'fs';
16
- import 'events';
17
- import 'assert';
17
+ import 'node:events';
18
+ import 'node:stream';
19
+ import 'node:string_decoder';
18
20
  import 'node:child_process';
19
21
  import 'node:http';
20
22
  import 'node:https';
21
- import 'tty';
22
23
  import 'util';
23
24
  import 'net';
25
+ import 'events';
24
26
  import 'url';
25
27
  import 'http';
26
28
  import 'stream';
@@ -29,175 +31,262 @@ import 'child_process';
29
31
  import 'node:os';
30
32
  import 'node:crypto';
31
33
  import 'node:dns';
32
- import 'vite/module-runner';
33
34
  import 'module';
34
35
  import 'node:assert';
35
36
  import 'node:v8';
36
37
  import 'node:worker_threads';
37
- import 'node:events';
38
38
  import 'crypto';
39
- import 'querystring';
40
39
  import 'node:buffer';
41
40
  import 'node:readline';
42
41
  import 'zlib';
43
42
  import 'buffer';
44
43
  import 'https';
45
44
  import 'tls';
45
+ import 'assert';
46
+ import 'querystring';
46
47
  import 'node:zlib';
47
48
 
48
- // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
49
- // copy from constants.ts
50
- const CSS_LANGS_RE =
51
- // eslint-disable-next-line regexp/no-unused-capturing-group
52
- /\.(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
+ );
53
53
  const isCSSRequest = (request) => CSS_LANGS_RE.test(request);
54
- // Use splitVendorChunkPlugin() to get the same manualChunks strategy as Vite 2.7
55
- // We don't recommend using this strategy as a general solution moving forward
56
- // splitVendorChunk is a simple index/vendor strategy that was used in Vite
57
- // until v2.8. It is exposed to let people continue to use it in case it was
58
- // working well for their setups.
59
- // The cache needs to be reset on buildStart for watch mode to work correctly
60
- // Don't use this manualChunks strategy for ssr, lib mode, and 'umd' or 'iife'
61
- /**
62
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
63
- */
64
54
  class SplitVendorChunkCache {
65
- cache;
66
- constructor() {
67
- this.cache = new Map();
68
- }
69
- reset() {
70
- this.cache = new Map();
71
- }
55
+ cache;
56
+ constructor() {
57
+ this.cache = /* @__PURE__ */ new Map();
58
+ }
59
+ reset() {
60
+ this.cache = /* @__PURE__ */ new Map();
61
+ }
72
62
  }
73
- /**
74
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
75
- */
76
63
  function splitVendorChunk(options = {}) {
77
- const cache = options.cache ?? new SplitVendorChunkCache();
78
- return (id, { getModuleInfo }) => {
79
- if (isInNodeModules(id) &&
80
- !isCSSRequest(id) &&
81
- staticImportedByEntry(id, getModuleInfo, cache.cache)) {
82
- return 'vendor';
83
- }
84
- };
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
+ };
85
70
  }
86
71
  function staticImportedByEntry(id, getModuleInfo, cache, importStack = []) {
87
- if (cache.has(id)) {
88
- return cache.get(id);
89
- }
90
- if (importStack.includes(id)) {
91
- // circular deps!
92
- cache.set(id, false);
93
- return false;
94
- }
95
- const mod = getModuleInfo(id);
96
- if (!mod) {
97
- cache.set(id, false);
98
- return false;
99
- }
100
- if (mod.isEntry) {
101
- cache.set(id, true);
102
- return true;
103
- }
104
- const someImporterIs = mod.importers.some((importer) => staticImportedByEntry(importer, getModuleInfo, cache, importStack.concat(id)));
105
- cache.set(id, someImporterIs);
106
- 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;
107
98
  }
108
- /**
109
- * @deprecated use build.rollupOutput.manualChunks or framework specific configuration
110
- */
111
99
  function splitVendorChunkPlugin() {
112
- const caches = [];
113
- function createSplitVendorChunk(output, config) {
114
- const cache = new SplitVendorChunkCache();
115
- caches.push(cache);
116
- const build = config.build ?? {};
117
- const format = output?.format;
118
- if (!build.ssr && !build.lib && format !== 'umd' && format !== 'iife') {
119
- return splitVendorChunk({ cache });
120
- }
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 });
121
108
  }
122
- return {
123
- name: 'vite:split-vendor-chunk',
124
- config(config) {
125
- let outputs = config?.build?.rollupOptions?.output;
126
- if (outputs) {
127
- outputs = arraify(outputs);
128
- for (const output of outputs) {
129
- const viteManualChunks = createSplitVendorChunk(output, config);
130
- if (viteManualChunks) {
131
- if (output.manualChunks) {
132
- if (typeof output.manualChunks === 'function') {
133
- const userManualChunks = output.manualChunks;
134
- output.manualChunks = (id, api) => {
135
- return userManualChunks(id, api) ?? viteManualChunks(id, api);
136
- };
137
- }
138
- else {
139
- // else, leave the object form of manualChunks untouched, as
140
- // we can't safely replicate rollup handling.
141
- // eslint-disable-next-line no-console
142
- 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.");
143
- }
144
- }
145
- else {
146
- output.manualChunks = viteManualChunks;
147
- }
148
- }
149
- }
150
- }
151
- else {
152
- return {
153
- build: {
154
- rollupOptions: {
155
- output: {
156
- manualChunks: createSplitVendorChunk({}, config),
157
- },
158
- },
159
- },
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);
160
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;
161
132
  }
162
- },
163
- buildStart() {
164
- caches.forEach((cache) => cache.reset());
165
- },
166
- };
133
+ }
134
+ }
135
+ } else {
136
+ return {
137
+ build: {
138
+ rollupOptions: {
139
+ output: {
140
+ manualChunks: createSplitVendorChunk({}, config)
141
+ }
142
+ }
143
+ }
144
+ };
145
+ }
146
+ },
147
+ buildStart() {
148
+ caches.forEach((cache) => cache.reset());
149
+ }
150
+ };
167
151
  }
168
152
 
169
153
  class RemoteEnvironmentTransport {
170
- options;
171
- constructor(options) {
172
- this.options = options;
173
- }
174
- register(environment) {
175
- this.options.onMessage(async (data) => {
176
- if (typeof data !== 'object' || !data || !data.__v)
177
- return;
178
- const method = data.m;
179
- const parameters = data.a;
180
- try {
181
- const result = await environment[method](...parameters);
182
- this.options.send({
183
- __v: true,
184
- r: result,
185
- i: data.i,
186
- });
187
- }
188
- catch (error) {
189
- this.options.send({
190
- __v: true,
191
- e: {
192
- name: error.name,
193
- message: error.message,
194
- stack: error.stack,
195
- },
196
- i: data.i,
197
- });
198
- }
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
199
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
+ );
200
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
+ );
201
290
  }
202
291
 
203
- export { RemoteEnvironmentTransport, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
292
+ export { RemoteEnvironmentTransport, ServerHMRConnector, createServerModuleRunner, 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 {
@@ -94,7 +94,7 @@ interface DefineImportMetadata {
94
94
  */
95
95
  importedNames?: string[];
96
96
  }
97
- interface SSRImportBaseMetadata extends DefineImportMetadata {
97
+ interface SSRImportMetadata extends DefineImportMetadata {
98
98
  isDynamicImport?: boolean;
99
99
  }
100
100
 
@@ -122,6 +122,8 @@ declare class ModuleRunner {
122
122
  private readonly envProxy;
123
123
  private readonly transport;
124
124
  private readonly resetSourceMapSupport?;
125
+ private readonly root;
126
+ private readonly moduleInfoCache;
125
127
  private destroyed;
126
128
  constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
127
129
  /**
@@ -141,10 +143,12 @@ declare class ModuleRunner {
141
143
  * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
142
144
  */
143
145
  isDestroyed(): boolean;
144
- private normalizeEntryUrl;
145
146
  private processImport;
147
+ private isCircularModule;
148
+ private isCircularImport;
146
149
  private cachedRequest;
147
150
  private cachedModule;
151
+ private getModuleInformation;
148
152
  protected directRequest(id: string, mod: ModuleCache, _callstack: string[]): Promise<any>;
149
153
  }
150
154
 
@@ -182,7 +186,7 @@ interface ModuleRunnerHMRConnection extends HMRConnection {
182
186
  * Configure how HMR is handled when this connection triggers an update.
183
187
  * This method expects that connection will start listening for HMR updates and call this callback when it's received.
184
188
  */
185
- onUpdate(callback: (payload: HMRPayload) => void): void;
189
+ onUpdate(callback: (payload: HotPayload) => void): void;
186
190
  }
187
191
  interface ModuleRunnerImportMeta extends ImportMeta {
188
192
  url: string;
@@ -217,14 +221,20 @@ interface ModuleCache {
217
221
  evaluated?: boolean;
218
222
  map?: DecodedMap;
219
223
  meta?: ResolvedResult;
220
- timestamp?: number;
221
224
  /**
222
225
  * Module ids that imports this module
223
226
  */
224
227
  importers?: Set<string>;
225
228
  imports?: Set<string>;
226
229
  }
227
- type FetchResult = ExternalFetchResult | ViteFetchResult;
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
+ }
228
238
  interface ExternalFetchResult {
229
239
  /**
230
240
  * The path to the externalized module starting with file://,
@@ -247,16 +257,25 @@ interface ViteFetchResult {
247
257
  /**
248
258
  * File path of the module on disk.
249
259
  * This will be resolved as import.meta.url/filename
260
+ * Will be equal to `null` for virtual modules
250
261
  */
251
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;
252
271
  }
253
272
  type ResolvedResult = (ExternalFetchResult | ViteFetchResult) & {
254
- id: string;
273
+ url: string;
255
274
  };
256
- /**
257
- * @experimental
258
- */
259
- type FetchFunction = (id: string, importer?: string) => Promise<FetchResult>;
275
+ type FetchFunction = (id: string, importer?: string, options?: FetchFunctionOptions) => Promise<FetchResult>;
276
+ interface FetchFunctionOptions {
277
+ cached?: boolean;
278
+ }
260
279
  interface ModuleRunnerHmr {
261
280
  /**
262
281
  * Configure how HMR communicates between the client and the server.
@@ -332,4 +351,4 @@ declare class ESModulesEvaluator implements ModuleEvaluator {
332
351
  runExternalModule(filepath: string): Promise<any>;
333
352
  }
334
353
 
335
- 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 };
354
+ 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 SSRImportMetadata, ssrDynamicImportKey, ssrExportAllKey, ssrImportKey, ssrImportMetaKey, ssrModuleExportsKey };