vite 5.2.8 → 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.
@@ -225,7 +225,7 @@ function getOriginalPosition(map, needle) {
225
225
  const result = originalPositionFor(map, needle);
226
226
  return result.column == null ? null : result;
227
227
  }
228
- const VITE_RUNTIME_SOURCEMAPPING_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
228
+ const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`);
229
229
  class ModuleCacheMap extends Map {
230
230
  root;
231
231
  constructor(root, entries) {
@@ -267,25 +267,6 @@ class ModuleCacheMap extends Map {
267
267
  const module = this.get(id);
268
268
  module.evaluated = !1, module.meta = void 0, module.map = void 0, module.promise = void 0, module.exports = void 0, module.imports?.clear();
269
269
  }
270
- isImported({ importedId, importedBy }, seen = /* @__PURE__ */ new Set()) {
271
- if (importedId = this.normalize(importedId), importedBy = this.normalize(importedBy), importedBy === importedId)
272
- return !0;
273
- if (seen.has(importedId))
274
- return !1;
275
- seen.add(importedId);
276
- const importers = this.getByModuleId(importedId)?.importers;
277
- if (!importers)
278
- return !1;
279
- if (importers.has(importedBy))
280
- return !0;
281
- for (const importer of importers)
282
- if (this.isImported({
283
- importedBy,
284
- importedId: importer
285
- }))
286
- return !0;
287
- return !1;
288
- }
289
270
  /**
290
271
  * Invalidate modules that dependent on the given modules, up to the main entry
291
272
  */
@@ -296,7 +277,7 @@ class ModuleCacheMap extends Map {
296
277
  continue;
297
278
  invalidated.add(id);
298
279
  const mod = super.get(id);
299
- mod?.importers && this.invalidateDepTree(mod.importers, invalidated), super.delete(id);
280
+ mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidate(id);
300
281
  }
301
282
  return invalidated;
302
283
  }
@@ -320,7 +301,7 @@ class ModuleCacheMap extends Map {
320
301
  return mod.map;
321
302
  if (!mod.meta || !("code" in mod.meta))
322
303
  return null;
323
- const mapString = mod.meta.code.match(VITE_RUNTIME_SOURCEMAPPING_REGEXP)?.[1];
304
+ const mapString = mod.meta.code.match(MODULE_RUNNER_SOURCEMAPPING_REGEXP)?.[1];
324
305
  if (!mapString)
325
306
  return null;
326
307
  const baseFile = mod.meta.file || moduleId.split("?")[0];
@@ -382,7 +363,10 @@ class HMRContext {
382
363
  this.hmrClient.notifyListeners("vite:invalidate", {
383
364
  path: this.ownerPath,
384
365
  message
385
- }), this.send("vite:invalidate", { path: this.ownerPath, message }), this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
366
+ }), this.send("vite:invalidate", {
367
+ path: this.ownerPath,
368
+ message
369
+ }), this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
386
370
  }
387
371
  on(event, cb) {
388
372
  const addToMap = (map) => {
@@ -534,13 +518,13 @@ const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_i
534
518
  debug: noop,
535
519
  error: noop
536
520
  };
537
- function createHMRHandler(runtime) {
521
+ function createHMRHandler(runner) {
538
522
  const queue = new Queue();
539
- return (payload) => queue.enqueue(() => handleHMRPayload(runtime, payload));
523
+ return (payload) => queue.enqueue(() => handleHMRPayload(runner, payload));
540
524
  }
541
- async function handleHMRPayload(runtime, payload) {
542
- const hmrClient = runtime.hmrClient;
543
- if (!(!hmrClient || runtime.isDestroyed()))
525
+ async function handleHMRPayload(runner, payload) {
526
+ const hmrClient = runner.hmrClient;
527
+ if (!(!hmrClient || runner.isDestroyed()))
544
528
  switch (payload.type) {
545
529
  case "connected":
546
530
  hmrClient.logger.debug("[vite] connected."), hmrClient.messenger.flush();
@@ -549,7 +533,7 @@ async function handleHMRPayload(runtime, payload) {
549
533
  await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(payload.updates.map(async (update) => {
550
534
  if (update.type === "js-update")
551
535
  return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
552
- hmrClient.logger.error("[vite] css hmr is not supported in runtime mode.");
536
+ hmrClient.logger.error("[vite] css hmr is not supported in runner mode.");
553
537
  })), await hmrClient.notifyListeners("vite:afterUpdate", payload);
554
538
  break;
555
539
  case "custom": {
@@ -557,15 +541,12 @@ async function handleHMRPayload(runtime, payload) {
557
541
  break;
558
542
  }
559
543
  case "full-reload": {
560
- const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? [...runtime.entrypoints].filter((entrypoint) => runtime.moduleCache.isImported({
561
- importedId: triggeredBy,
562
- importedBy: entrypoint
563
- })) : [...runtime.entrypoints];
564
- if (!clearEntrypoints.length)
544
+ const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(runner, getModulesByFile(runner, slash(triggeredBy))) : findAllEntrypoints(runner);
545
+ if (!clearEntrypoints.size)
565
546
  break;
566
- hmrClient.logger.debug("[vite] program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runtime.moduleCache.clear();
547
+ hmrClient.logger.debug("[vite] program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
567
548
  for (const id of clearEntrypoints)
568
- await runtime.executeUrl(id);
549
+ await runner.import(id);
569
550
  break;
570
551
  }
571
552
  case "prune":
@@ -604,6 +585,32 @@ class Queue {
604
585
  }), !0) : !1;
605
586
  }
606
587
  }
588
+ function getModulesByFile(runner, file) {
589
+ const modules = [];
590
+ for (const [id, mod] of runner.moduleCache.entries())
591
+ mod.meta && "file" in mod.meta && mod.meta.file === file && modules.push(id);
592
+ return modules;
593
+ }
594
+ function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Set(), entrypoints = /* @__PURE__ */ new Set()) {
595
+ for (const moduleId of modules) {
596
+ if (visited.has(moduleId))
597
+ continue;
598
+ visited.add(moduleId);
599
+ const module = runner.moduleCache.getByModuleId(moduleId);
600
+ if (module.importers && !module.importers.size) {
601
+ entrypoints.add(moduleId);
602
+ continue;
603
+ }
604
+ for (const importer of module.importers || [])
605
+ getModulesEntrypoints(runner, [importer], visited, entrypoints);
606
+ }
607
+ return entrypoints;
608
+ }
609
+ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
610
+ for (const [id, mod] of runner.moduleCache.entries())
611
+ mod.importers && !mod.importers.size && entrypoints.add(id);
612
+ return entrypoints;
613
+ }
607
614
  const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
608
615
  for (const handler of handlers) {
609
616
  const result = handler(...args);
@@ -614,11 +621,11 @@ const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ *
614
621
  }, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
615
622
  let overridden = !1;
616
623
  const originalPrepare = Error.prepareStackTrace;
617
- function resetInterceptor(runtime, options) {
618
- moduleGraphs.delete(runtime.moduleCache), options.retrieveFile && retrieveFileHandlers.delete(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.delete(options.retrieveSourceMap), moduleGraphs.size === 0 && (Error.prepareStackTrace = originalPrepare, overridden = !1);
624
+ function resetInterceptor(runner, options) {
625
+ moduleGraphs.delete(runner.moduleCache), options.retrieveFile && retrieveFileHandlers.delete(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.delete(options.retrieveSourceMap), moduleGraphs.size === 0 && (Error.prepareStackTrace = originalPrepare, overridden = !1);
619
626
  }
620
- function interceptStackTrace(runtime, options = {}) {
621
- return overridden || (Error.prepareStackTrace = prepareStackTrace, overridden = !0), moduleGraphs.add(runtime.moduleCache), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runtime, options);
627
+ function interceptStackTrace(runner, options = {}) {
628
+ return overridden || (Error.prepareStackTrace = prepareStackTrace, overridden = !0), moduleGraphs.add(runner.moduleCache), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runner, options);
622
629
  }
623
630
  function supportRelativeURL(file, url) {
624
631
  if (!file)
@@ -628,7 +635,7 @@ function supportRelativeURL(file, url) {
628
635
  const startPath = dir.slice(protocol.length);
629
636
  return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + slash(posixResolve(startPath, url))) : protocol + posixResolve(startPath, url);
630
637
  }
631
- function getRuntimeSourceMap(position) {
638
+ function getRunnerSourceMap(position) {
632
639
  for (const moduleCache of moduleGraphs) {
633
640
  const sourceMap = moduleCache.getSourceMap(position.source);
634
641
  if (sourceMap)
@@ -678,7 +685,7 @@ function retrieveSourceMap(source) {
678
685
  function mapSourcePosition(position) {
679
686
  if (!position.source)
680
687
  return position;
681
- let sourceMap = getRuntimeSourceMap(position);
688
+ let sourceMap = getRunnerSourceMap(position);
682
689
  if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
683
690
  const urlAndMap = retrieveSourceMap(position.source);
684
691
  if (urlAndMap && urlAndMap.map) {
@@ -798,8 +805,8 @@ function prepareStackTrace(error, stack) {
798
805
  at ${wrapCallSite(stack[i], state)}`), state.nextPosition = state.curPosition;
799
806
  return state.curPosition = state.nextPosition = null, errorString + processedStack.reverse().join("");
800
807
  }
801
- function enableSourceMapSupport(runtime) {
802
- if (runtime.options.sourcemapInterceptor === "node") {
808
+ function enableSourceMapSupport(runner) {
809
+ if (runner.options.sourcemapInterceptor === "node") {
803
810
  if (typeof process > "u")
804
811
  throw new TypeError(`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`);
805
812
  if (typeof process.setSourceMapsEnabled != "function")
@@ -807,11 +814,11 @@ function enableSourceMapSupport(runtime) {
807
814
  const isEnabledAlready = process.sourceMapsEnabled ?? !1;
808
815
  return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
809
816
  }
810
- return interceptStackTrace(runtime, typeof runtime.options.sourcemapInterceptor == "object" ? runtime.options.sourcemapInterceptor : void 0);
817
+ return interceptStackTrace(runner, typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0);
811
818
  }
812
- class ViteRuntime {
819
+ class ModuleRunner {
813
820
  options;
814
- runner;
821
+ evaluator;
815
822
  debug;
816
823
  /**
817
824
  * Holds the cache of modules
@@ -819,44 +826,32 @@ class ViteRuntime {
819
826
  */
820
827
  moduleCache;
821
828
  hmrClient;
822
- entrypoints = /* @__PURE__ */ new Set();
823
829
  idToUrlMap = /* @__PURE__ */ new Map();
824
830
  fileToIdMap = /* @__PURE__ */ new Map();
825
831
  envProxy = new Proxy({}, {
826
832
  get(_, p) {
827
- throw new Error(`[vite-runtime] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
833
+ throw new Error(`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
828
834
  }
829
835
  });
836
+ transport;
830
837
  _destroyed = !1;
831
838
  _resetSourceMapSupport;
832
- constructor(options, runner, debug) {
833
- this.options = options, this.runner = runner, this.debug = debug, this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root), typeof options.hmr == "object" && (this.hmrClient = new HMRClient(options.hmr.logger === !1 ? silentConsole : options.hmr.logger || console, options.hmr.connection, ({ acceptedPath, ssrInvalidates }) => (this.moduleCache.invalidate(acceptedPath), ssrInvalidates && this.invalidateFiles(ssrInvalidates), this.executeUrl(acceptedPath))), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this._resetSourceMapSupport = enableSourceMapSupport(this));
839
+ constructor(options, evaluator, debug) {
840
+ this.options = options, this.evaluator = evaluator, this.debug = debug, this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root), this.transport = options.transport, typeof options.hmr == "object" && (this.hmrClient = new HMRClient(options.hmr.logger === !1 ? silentConsole : options.hmr.logger || console, options.hmr.connection, ({ acceptedPath, invalidates }) => (this.moduleCache.invalidate(acceptedPath), invalidates && this.invalidateFiles(invalidates), this.import(acceptedPath))), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this._resetSourceMapSupport = enableSourceMapSupport(this));
834
841
  }
835
842
  /**
836
843
  * URL to execute. Accepts file path, server path or id relative to the root.
837
844
  */
838
- async executeUrl(url) {
845
+ async import(url) {
839
846
  url = this.normalizeEntryUrl(url);
840
847
  const fetchedModule = await this.cachedModule(url);
841
848
  return await this.cachedRequest(url, fetchedModule);
842
849
  }
843
- /**
844
- * Entrypoint URL to execute. Accepts file path, server path or id relative to the root.
845
- * In the case of a full reload triggered by HMR, this is the module that will be reloaded.
846
- * If this method is called multiple times, all entrypoints will be reloaded one at a time.
847
- */
848
- async executeEntrypoint(url) {
849
- url = this.normalizeEntryUrl(url);
850
- const fetchedModule = await this.cachedModule(url);
851
- return await this.cachedRequest(url, fetchedModule, [], {
852
- entrypoint: !0
853
- });
854
- }
855
850
  /**
856
851
  * Clear all caches including HMR listeners.
857
852
  */
858
853
  clearCache() {
859
- this.moduleCache.clear(), this.idToUrlMap.clear(), this.entrypoints.clear(), this.hmrClient?.clear();
854
+ this.moduleCache.clear(), this.idToUrlMap.clear(), this.hmrClient?.clear();
860
855
  }
861
856
  /**
862
857
  * Clears all caches, removes all HMR listeners, and resets source map support.
@@ -871,6 +866,7 @@ class ViteRuntime {
871
866
  isDestroyed() {
872
867
  return this._destroyed;
873
868
  }
869
+ // map files to modules and invalidate them
874
870
  invalidateFiles(files) {
875
871
  files.forEach((file) => {
876
872
  const ids = this.fileToIdMap.get(file);
@@ -894,9 +890,7 @@ class ViteRuntime {
894
890
  return type !== "module" && type !== "commonjs" ? exports : (analyzeImportedModDifference(exports, id, type, metadata), proxyGuardOnlyEsm(exports, id, metadata));
895
891
  }
896
892
  async cachedRequest(id, fetchedModule, callstack = [], metadata) {
897
- const moduleId = fetchedModule.id;
898
- metadata?.entrypoint && this.entrypoints.add(moduleId);
899
- const mod = this.moduleCache.getByModuleId(moduleId), { imports, importers } = mod, importee = callstack[callstack.length - 1];
893
+ const moduleId = fetchedModule.id, mod = this.moduleCache.getByModuleId(moduleId), { imports, importers } = mod, importee = callstack[callstack.length - 1];
900
894
  if (importee && importers.add(importee), (callstack.includes(moduleId) || Array.from(imports.values()).some((i) => importers.has(i))) && mod.exports)
901
895
  return this.processImport(mod.exports, fetchedModule, metadata);
902
896
  let debugTimer;
@@ -904,7 +898,7 @@ class ViteRuntime {
904
898
  const getStack = () => `stack:
905
899
  ${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(`
906
900
  `)}`;
907
- this.debug(`[vite-runtime] module ${moduleId} takes over 2s to load.
901
+ this.debug(`[module runner] module ${moduleId} takes over 2s to load.
908
902
  ${getStack()}`);
909
903
  }, 2e3));
910
904
  try {
@@ -925,8 +919,8 @@ ${getStack()}`);
925
919
  if (mod2.meta)
926
920
  return mod2.meta;
927
921
  }
928
- this.debug?.("[vite-runtime] fetching", id);
929
- const fetchedModule = id.startsWith("data:") ? { externalize: id, type: "builtin" } : await this.options.fetchModule(id, importer), idQuery = id.split("?")[1], query = idQuery ? `?${idQuery}` : "", file = "file" in fetchedModule ? fetchedModule.file : void 0, fullFile = file ? `${file}${query}` : id, moduleId = this.moduleCache.normalize(fullFile), mod = this.moduleCache.getByModuleId(moduleId);
922
+ this.debug?.("[module runner] fetching", id);
923
+ const fetchedModule = id.startsWith("data:") ? { externalize: id, type: "builtin" } : await this.transport.fetchModule(id, importer), idQuery = id.split("?")[1], query = idQuery ? `?${idQuery}` : "", file = "file" in fetchedModule ? fetchedModule.file : void 0, fullFile = file ? `${file}${query}` : id, moduleId = this.moduleCache.normalize(fullFile), mod = this.moduleCache.getByModuleId(moduleId);
930
924
  if (fetchedModule.id = moduleId, mod.meta = fetchedModule, file) {
931
925
  const fileModules = this.fileToIdMap.get(file) || [];
932
926
  fileModules.push(moduleId), this.fileToIdMap.set(file, fileModules);
@@ -941,14 +935,14 @@ ${getStack()}`);
941
935
  }, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(id), dep)), request(dep, { isDynamicImport: !0 }));
942
936
  if ("externalize" in fetchResult) {
943
937
  const { externalize } = fetchResult;
944
- this.debug?.("[vite-runtime] externalizing", externalize);
945
- const exports2 = await this.runner.runExternalModule(externalize);
938
+ this.debug?.("[module runner] externalizing", externalize);
939
+ const exports2 = await this.evaluator.runExternalModule(externalize);
946
940
  return mod.exports = exports2, exports2;
947
941
  }
948
942
  const { code, file } = fetchResult;
949
943
  if (code == null) {
950
944
  const importer = callstack[callstack.length - 2];
951
- throw new Error(`[vite-runtime] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`);
945
+ throw new Error(`[module runner] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`);
952
946
  }
953
947
  const modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
954
948
  filename: isWindows ? toWindowsPath(filename) : filename,
@@ -956,11 +950,11 @@ ${getStack()}`);
956
950
  url: href,
957
951
  env: this.envProxy,
958
952
  resolve(id2, parent) {
959
- throw new Error('[vite-runtime] "import.meta.resolve" is not supported.');
953
+ throw new Error('[module runner] "import.meta.resolve" is not supported.');
960
954
  },
961
955
  // should be replaced during transformation
962
956
  glob() {
963
- throw new Error('[vite-runtime] "import.meta.glob" is not supported.');
957
+ throw new Error('[module runner] "import.meta.glob" is not supported.');
964
958
  }
965
959
  }, exports = /* @__PURE__ */ Object.create(null);
966
960
  Object.defineProperty(exports, Symbol.toStringTag, {
@@ -973,8 +967,8 @@ ${getStack()}`);
973
967
  enumerable: !0,
974
968
  get: () => {
975
969
  if (!this.hmrClient)
976
- throw new Error("[vite-runtime] HMR client was destroyed.");
977
- return this.debug?.("[vite-runtime] creating hmr context for", moduleId), hotContext ||= new HMRContext(this.hmrClient, moduleId), hotContext;
970
+ throw new Error("[module runner] HMR client was destroyed.");
971
+ return this.debug?.("[module runner] creating hmr context for", moduleId), hotContext ||= new HMRContext(this.hmrClient, moduleId), hotContext;
978
972
  },
979
973
  set: (value) => {
980
974
  hotContext = value;
@@ -987,7 +981,7 @@ ${getStack()}`);
987
981
  [ssrExportAllKey]: (obj) => exportAll(exports, obj),
988
982
  [ssrImportMetaKey]: meta
989
983
  };
990
- return this.debug?.("[vite-runtime] executing", href), await this.runner.runViteModule(context, code, id), exports;
984
+ return this.debug?.("[module runner] executing", href), await this.evaluator.runInlinedModule(context, code, id), exports;
991
985
  }
992
986
  }
993
987
  function exportAll(exports, sourceModule) {
@@ -1004,8 +998,8 @@ function exportAll(exports, sourceModule) {
1004
998
  }
1005
999
  }
1006
1000
  }
1007
- class ESModulesRunner {
1008
- async runViteModule(context, code) {
1001
+ class ESModulesEvaluator {
1002
+ async runInlinedModule(context, code) {
1009
1003
  await new AsyncFunction(
1010
1004
  ssrModuleExportsKey,
1011
1005
  ssrImportMetaKey,
@@ -1020,10 +1014,48 @@ class ESModulesRunner {
1020
1014
  return import(filepath);
1021
1015
  }
1022
1016
  }
1017
+ class RemoteRunnerTransport {
1018
+ options;
1019
+ rpcPromises = /* @__PURE__ */ new Map();
1020
+ constructor(options) {
1021
+ this.options = options, this.options.onMessage(async (data) => {
1022
+ if (typeof data != "object" || !data || !data.__v)
1023
+ return;
1024
+ const promise = this.rpcPromises.get(data.i);
1025
+ promise && (promise.timeoutId && clearTimeout(promise.timeoutId), this.rpcPromises.delete(data.i), data.e ? promise.reject(data.e) : promise.resolve(data.r));
1026
+ });
1027
+ }
1028
+ resolve(method, ...args) {
1029
+ const promiseId = nanoid();
1030
+ return this.options.send({
1031
+ __v: !0,
1032
+ m: method,
1033
+ a: args,
1034
+ i: promiseId
1035
+ }), new Promise((resolve2, reject) => {
1036
+ const timeout = this.options.timeout ?? 6e4;
1037
+ let timeoutId;
1038
+ timeout > 0 && (timeoutId = setTimeout(() => {
1039
+ this.rpcPromises.delete(promiseId), reject(new Error(`${method}(${args.map((arg) => JSON.stringify(arg)).join(", ")}) timed out after ${timeout}ms`));
1040
+ }, timeout), timeoutId?.unref?.()), this.rpcPromises.set(promiseId, { resolve: resolve2, reject, timeoutId });
1041
+ });
1042
+ }
1043
+ fetchModule(id, importer) {
1044
+ return this.resolve("fetchModule", id, importer);
1045
+ }
1046
+ }
1047
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
1048
+ function nanoid(size = 21) {
1049
+ let id = "", i = size;
1050
+ for (; i--; )
1051
+ id += urlAlphabet[Math.random() * 64 | 0];
1052
+ return id;
1053
+ }
1023
1054
  export {
1024
- ESModulesRunner,
1055
+ ESModulesEvaluator,
1025
1056
  ModuleCacheMap,
1026
- ViteRuntime,
1057
+ ModuleRunner,
1058
+ RemoteRunnerTransport,
1027
1059
  ssrDynamicImportKey,
1028
1060
  ssrExportAllKey,
1029
1061
  ssrImportKey,
@@ -3510,7 +3510,7 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
3510
3510
  merged[key] = [].concat(existing, value);
3511
3511
  continue;
3512
3512
  }
3513
- else if (key === 'noExternal' &&
3513
+ else if (key === 'noExternal' && // TODO: environments
3514
3514
  rootPath === 'ssr' &&
3515
3515
  (existing === true || value === true)) {
3516
3516
  merged[key] = true;
@@ -5567,7 +5567,7 @@ function isFileServingAllowed(url, server) {
5567
5567
  const file = fsPathFromUrl(url);
5568
5568
  if (server._fsDenyGlob(file))
5569
5569
  return false;
5570
- if (server.moduleGraph.safeModulesPath.has(file))
5570
+ if (server._safeModulesPath.has(file))
5571
5571
  return true;
5572
5572
  if (server.config.server.fs.allow.some((uri) => isSameFileUri(uri, file) || isParentDirectory(uri, file)))
5573
5573
  return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite",
3
- "version": "5.2.8",
3
+ "version": "6.0.0-alpha.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Evan You",
@@ -32,9 +32,9 @@
32
32
  "./client": {
33
33
  "types": "./client.d.ts"
34
34
  },
35
- "./runtime": {
36
- "types": "./dist/node/runtime.d.ts",
37
- "import": "./dist/node/runtime.js"
35
+ "./module-runner": {
36
+ "types": "./dist/node/module-runner.d.ts",
37
+ "import": "./dist/node/module-runner.js"
38
38
  },
39
39
  "./dist/client/*": "./dist/client/*",
40
40
  "./types/*": {
@@ -44,8 +44,8 @@
44
44
  },
45
45
  "typesVersions": {
46
46
  "*": {
47
- "runtime": [
48
- "dist/node/runtime.d.ts"
47
+ "module-runner": [
48
+ "dist/node/module-runner.d.ts"
49
49
  ]
50
50
  }
51
51
  },
@@ -131,11 +131,10 @@
131
131
  "rollup-plugin-dts": "^6.1.0",
132
132
  "rollup-plugin-esbuild": "^6.1.1",
133
133
  "rollup-plugin-license": "^3.3.1",
134
- "sass": "^1.72.0",
135
134
  "sirv": "^2.0.4",
136
135
  "source-map-support": "^0.5.21",
137
136
  "strip-ansi": "^7.1.0",
138
- "strip-literal": "^2.1.0",
137
+ "strip-literal": "^2.0.0",
139
138
  "tsconfck": "^3.0.3",
140
139
  "tslib": "^2.6.2",
141
140
  "types": "link:./types",
@@ -25,7 +25,7 @@ export interface Update {
25
25
  /** @internal */
26
26
  isWithinCircularImport?: boolean
27
27
  /** @internal */
28
- ssrInvalidates?: string[]
28
+ invalidates?: string[]
29
29
  }
30
30
 
31
31
  export interface PrunePayload {
@@ -1,63 +0,0 @@
1
- import { V as ViteRuntimeOptions, b as ViteModuleRunner, M as ModuleCacheMap, c as HMRClient, R as ResolvedResult, d as ViteRuntimeModuleContext } from './types.d-aGj9QkWt.js';
2
- export { a as FetchFunction, F as FetchResult, e as HMRConnection, H as HMRLogger, g as HMRRuntimeConnection, f as ModuleCache, S as SSRImportMetadata, h as ViteRuntimeImportMeta, s as ssrDynamicImportKey, i as ssrExportAllKey, j as ssrImportKey, k as ssrImportMetaKey, l as ssrModuleExportsKey } from './types.d-aGj9QkWt.js';
3
- import '../../types/hot.js';
4
- import '../../types/hmrPayload.js';
5
- import '../../types/customEvent.js';
6
-
7
- interface ViteRuntimeDebugger {
8
- (formatter: unknown, ...args: unknown[]): void;
9
- }
10
- declare class ViteRuntime {
11
- options: ViteRuntimeOptions;
12
- runner: ViteModuleRunner;
13
- private debug?;
14
- /**
15
- * Holds the cache of modules
16
- * Keys of the map are ids
17
- */
18
- moduleCache: ModuleCacheMap;
19
- hmrClient?: HMRClient;
20
- entrypoints: Set<string>;
21
- private idToUrlMap;
22
- private fileToIdMap;
23
- private envProxy;
24
- private _destroyed;
25
- private _resetSourceMapSupport?;
26
- constructor(options: ViteRuntimeOptions, runner: ViteModuleRunner, debug?: ViteRuntimeDebugger | undefined);
27
- /**
28
- * URL to execute. Accepts file path, server path or id relative to the root.
29
- */
30
- executeUrl<T = any>(url: string): Promise<T>;
31
- /**
32
- * Entrypoint URL to execute. Accepts file path, server path or id relative to the root.
33
- * In the case of a full reload triggered by HMR, this is the module that will be reloaded.
34
- * If this method is called multiple times, all entrypoints will be reloaded one at a time.
35
- */
36
- executeEntrypoint<T = any>(url: string): Promise<T>;
37
- /**
38
- * Clear all caches including HMR listeners.
39
- */
40
- clearCache(): void;
41
- /**
42
- * Clears all caches, removes all HMR listeners, and resets source map support.
43
- * This method doesn't stop the HMR connection.
44
- */
45
- destroy(): Promise<void>;
46
- /**
47
- * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
48
- */
49
- isDestroyed(): boolean;
50
- private invalidateFiles;
51
- private normalizeEntryUrl;
52
- private processImport;
53
- private cachedRequest;
54
- private cachedModule;
55
- protected directRequest(id: string, fetchResult: ResolvedResult, _callstack: string[]): Promise<any>;
56
- }
57
-
58
- declare class ESModulesRunner implements ViteModuleRunner {
59
- runViteModule(context: ViteRuntimeModuleContext, code: string): Promise<any>;
60
- runExternalModule(filepath: string): Promise<any>;
61
- }
62
-
63
- export { ESModulesRunner, ModuleCacheMap, ResolvedResult, ViteModuleRunner, ViteRuntime, ViteRuntimeModuleContext, ViteRuntimeOptions };