vite 6.0.0-beta.9 → 6.0.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.

Potentially problematic release.


This version of vite might be problematic. Click here for more details.

@@ -1,7 +1,7 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-CG5ueZZV.js';
3
- export { B as BuildEnvironment, D as DevEnvironment, b as build, j as buildErrorMessage, e as createBuilder, z as createFilter, f as createIdResolver, E as createLogger, k as createRunnableDevEnvironment, c as createServer, u as createServerHotChannel, q as createServerModuleRunner, d as defineConfig, n as fetchModule, g as formatPostcssSourceMap, H as isFileLoadingAllowed, G as isFileServingAllowed, m as isRunnableDevEnvironment, l as loadConfigFromFile, I as loadEnv, y as mergeAlias, x as mergeConfig, v as moduleRunnerTransform, w as normalizePath, o as optimizeDeps, h as preprocessCSS, p as preview, r as resolveConfig, J as resolveEnvPrefix, A as rollupVersion, F as searchForWorkspaceRoot, C as send, s as sortUserPlugins, t as transformWithEsbuild } from './chunks/dep-CG5ueZZV.js';
4
- export { VERSION as version } from './constants.js';
2
+ import { i as isInNodeModules, a as arraify } from './chunks/dep-C6qYk3zB.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-C6qYk3zB.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';
5
5
  export { version as esbuildVersion } from 'esbuild';
6
6
  import 'node:fs';
7
7
  import 'node:fs/promises';
@@ -21,7 +21,6 @@ import 'net';
21
21
  import 'events';
22
22
  import 'url';
23
23
  import 'http';
24
- import 'fs/promises';
25
24
  import 'stream';
26
25
  import 'os';
27
26
  import 'child_process';
@@ -33,17 +32,17 @@ import 'module';
33
32
  import 'node:readline';
34
33
  import 'node:process';
35
34
  import 'node:buffer';
35
+ import 'node:events';
36
36
  import 'crypto';
37
37
  import 'node:assert';
38
38
  import 'node:v8';
39
39
  import 'node:worker_threads';
40
- import 'node:events';
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 = (
@@ -77,7 +77,7 @@ interface ModuleRunnerTransport {
77
77
  interface NormalizedModuleRunnerTransport {
78
78
  connect?(onMessage?: (data: HotPayload) => void): Promise<void> | void;
79
79
  disconnect?(): Promise<void> | void;
80
- send(data: HotPayload): void;
80
+ send(data: HotPayload): Promise<void>;
81
81
  invoke<T extends keyof InvokeMethods>(name: T, data: Parameters<InvokeMethods[T]>): Promise<ReturnType<Awaited<InvokeMethods[T]>>>;
82
82
  }
83
83
  declare const createWebSocketModuleRunnerTransport: (options: {
@@ -186,7 +186,7 @@ declare class ModuleRunner {
186
186
  private readonly root;
187
187
  private readonly concurrentModuleNodePromises;
188
188
  private closed;
189
- constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
189
+ constructor(options: ModuleRunnerOptions, evaluator?: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
190
190
  /**
191
191
  * URL to execute. Accepts file path, server path or id relative to the root.
192
192
  */
@@ -286,6 +286,8 @@ interface ModuleRunnerOptions {
286
286
  sourcemapInterceptor?: false | 'node' | 'prepareStackTrace' | InterceptorOptions;
287
287
  /**
288
288
  * Disable HMR or configure HMR options.
289
+ *
290
+ * @default true
289
291
  */
290
292
  hmr?: boolean | ModuleRunnerHmr;
291
293
  /**
@@ -364,4 +366,4 @@ declare class ESModulesEvaluator implements ModuleEvaluator {
364
366
  runExternalModule(filepath: string): Promise<any>;
365
367
  }
366
368
 
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 };
369
+ export { ESModulesEvaluator, EvaluatedModuleNode, EvaluatedModules, type FetchFunction, type FetchFunctionOptions, type FetchResult, type HMRLogger, type InterceptorOptions, 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 };
@@ -1,7 +1,7 @@
1
1
  const VALID_ID_PREFIX = "/@id/", NULL_BYTE_PLACEHOLDER = "__x00__";
2
2
  let SOURCEMAPPING_URL = "sourceMa";
3
3
  SOURCEMAPPING_URL += "ppingURL";
4
- const isWindows = typeof process < "u" && process.platform === "win32";
4
+ const ERR_OUTDATED_OPTIMIZED_DEP = "ERR_OUTDATED_OPTIMIZED_DEP", isWindows = typeof process < "u" && process.platform === "win32";
5
5
  function unwrapId(id) {
6
6
  return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
7
7
  }
@@ -332,7 +332,12 @@ class EvaluatedModules {
332
332
  this.idToModuleMap.clear(), this.fileToModulesMap.clear(), this.urlToIdModuleMap.clear();
333
333
  }
334
334
  }
335
- const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test", "node:sqlite"]);
335
+ const prefixedBuiltins = /* @__PURE__ */ new Set([
336
+ "node:sea",
337
+ "node:sqlite",
338
+ "node:test",
339
+ "node:test/reporters"
340
+ ]);
336
341
  function normalizeModuleId(file) {
337
342
  return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\//, "/");
338
343
  }
@@ -443,7 +448,9 @@ class HMRClient {
443
448
  cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
444
449
  }
445
450
  send(payload) {
446
- this.transport.send(payload);
451
+ this.transport.send(payload).catch((err) => {
452
+ this.logger.error(err);
453
+ });
447
454
  }
448
455
  clear() {
449
456
  this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
@@ -530,6 +537,14 @@ let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzr
530
537
  id += urlAlphabet[Math.random() * 64 | 0];
531
538
  return id;
532
539
  };
540
+ function reviveInvokeError(e) {
541
+ const error = new Error(e.message || "Unknown invoke error");
542
+ return Object.assign(error, e, {
543
+ // pass the whole error instead of just the stacktrace
544
+ // so that it gets formatted nicely with console.log
545
+ runnerError: new Error("RunnerError")
546
+ }), error;
547
+ }
533
548
  const createInvokeableTransport = (transport) => {
534
549
  if (transport.invoke)
535
550
  return {
@@ -545,7 +560,7 @@ const createInvokeableTransport = (transport) => {
545
560
  }
546
561
  });
547
562
  if ("e" in result)
548
- throw result.e;
563
+ throw reviveInvokeError(result.e);
549
564
  return result.r;
550
565
  }
551
566
  };
@@ -598,7 +613,7 @@ const createInvokeableTransport = (transport) => {
598
613
  }
599
614
  }, sendPromise = transport.send(wrappedData), { promise, resolve: resolve2, reject } = promiseWithResolvers(), timeout = transport.timeout ?? 6e4;
600
615
  let timeoutId;
601
- return timeout > 0 && (timeoutId = setTimeout(() => {
616
+ timeout > 0 && (timeoutId = setTimeout(() => {
602
617
  rpcPromises.delete(promiseId), reject(
603
618
  new Error(
604
619
  `transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`
@@ -606,7 +621,12 @@ const createInvokeableTransport = (transport) => {
606
621
  );
607
622
  }, timeout), timeoutId?.unref?.()), rpcPromises.set(promiseId, { resolve: resolve2, reject, name, timeoutId }), sendPromise && sendPromise.catch((err) => {
608
623
  clearTimeout(timeoutId), rpcPromises.delete(promiseId), reject(err);
609
- }), await promise;
624
+ });
625
+ try {
626
+ return await promise;
627
+ } catch (err) {
628
+ throw reviveInvokeError(err);
629
+ }
610
630
  }
611
631
  };
612
632
  }, normalizeModuleRunnerTransport = (transport) => {
@@ -738,7 +758,15 @@ async function handleHotPayload(runner, payload) {
738
758
  if (!clearEntrypointUrls.size) break;
739
759
  hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.evaluatedModules.clear();
740
760
  for (const url of clearEntrypointUrls)
741
- await runner.import(url);
761
+ try {
762
+ await runner.import(url);
763
+ } catch (err) {
764
+ err.code !== ERR_OUTDATED_OPTIMIZED_DEP && hmrClient.logger.error(
765
+ `An error happened during full reload
766
+ ${err.message}
767
+ ${err.stack}`
768
+ );
769
+ }
742
770
  break;
743
771
  }
744
772
  case "prune":
@@ -1019,12 +1047,35 @@ function enableSourceMapSupport(runner) {
1019
1047
  typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
1020
1048
  );
1021
1049
  }
1050
+ class ESModulesEvaluator {
1051
+ startOffset = getAsyncFunctionDeclarationPaddingLineCount();
1052
+ async runInlinedModule(context, code) {
1053
+ await new AsyncFunction(
1054
+ ssrModuleExportsKey,
1055
+ ssrImportMetaKey,
1056
+ ssrImportKey,
1057
+ ssrDynamicImportKey,
1058
+ ssrExportAllKey,
1059
+ // source map should already be inlined by Vite
1060
+ '"use strict";' + code
1061
+ )(
1062
+ context[ssrModuleExportsKey],
1063
+ context[ssrImportMetaKey],
1064
+ context[ssrImportKey],
1065
+ context[ssrDynamicImportKey],
1066
+ context[ssrExportAllKey]
1067
+ ), Object.seal(context[ssrModuleExportsKey]);
1068
+ }
1069
+ runExternalModule(filepath) {
1070
+ return import(filepath);
1071
+ }
1072
+ }
1022
1073
  class ModuleRunner {
1023
- constructor(options, evaluator, debug) {
1074
+ constructor(options, evaluator = new ESModulesEvaluator(), debug) {
1024
1075
  this.options = options, this.evaluator = evaluator, this.debug = debug;
1025
1076
  const root = this.options.root;
1026
- if (this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr) {
1027
- const resolvedHmrLogger = options.hmr === !0 || options.hmr.logger === void 0 ? hmrLogger : options.hmr.logger === !1 ? silentConsole : options.hmr.logger;
1077
+ if (this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules(), this.transport = normalizeModuleRunnerTransport(options.transport), options.hmr !== !1) {
1078
+ const optionsHmr = options.hmr ?? !0, resolvedHmrLogger = optionsHmr === !0 || optionsHmr.logger === void 0 ? hmrLogger : optionsHmr.logger === !1 ? silentConsole : optionsHmr.logger;
1028
1079
  if (this.hmrClient = new HMRClient(
1029
1080
  resolvedHmrLogger,
1030
1081
  this.transport,
@@ -1242,29 +1293,6 @@ function exportAll(exports, sourceModule) {
1242
1293
  }
1243
1294
  }
1244
1295
  }
1245
- class ESModulesEvaluator {
1246
- startOffset = getAsyncFunctionDeclarationPaddingLineCount();
1247
- async runInlinedModule(context, code) {
1248
- await new AsyncFunction(
1249
- ssrModuleExportsKey,
1250
- ssrImportMetaKey,
1251
- ssrImportKey,
1252
- ssrDynamicImportKey,
1253
- ssrExportAllKey,
1254
- // source map should already be inlined by Vite
1255
- '"use strict";' + code
1256
- )(
1257
- context[ssrModuleExportsKey],
1258
- context[ssrImportMetaKey],
1259
- context[ssrImportKey],
1260
- context[ssrDynamicImportKey],
1261
- context[ssrExportAllKey]
1262
- ), Object.seal(context[ssrModuleExportsKey]);
1263
- }
1264
- runExternalModule(filepath) {
1265
- return import(filepath);
1266
- }
1267
- }
1268
1296
  export {
1269
1297
  ESModulesEvaluator,
1270
1298
  EvaluatedModules,