vite 6.0.0-alpha.1 → 6.0.0-alpha.3

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,17 +1,16 @@
1
1
  export { parseAst, parseAstAsync } from 'rollup/parseAst';
2
- import { i as isInNodeModules, a as arraify } from './chunks/dep-gq9_cnPm.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-gq9_cnPm.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-DitPlFWl.js';
3
+ export { B as BuildEnvironment, D as DevEnvironment, S as ServerHMRConnector, b as build, h as buildErrorMessage, u as createFilter, j as createNodeDevEnvironment, c as createServer, m as createServerModuleRunner, e as createViteBuilder, 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-DitPlFWl.js';
6
4
  export { VERSION as version } from './constants.js';
7
5
  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';
15
14
  import 'path';
16
15
  import 'fs';
17
16
  import 'events';
@@ -19,6 +18,7 @@ import 'assert';
19
18
  import 'node:child_process';
20
19
  import 'node:http';
21
20
  import 'node:https';
21
+ import 'tty';
22
22
  import 'util';
23
23
  import 'net';
24
24
  import 'url';
@@ -29,19 +29,20 @@ import 'child_process';
29
29
  import 'node:os';
30
30
  import 'node:crypto';
31
31
  import 'node:dns';
32
+ import 'vite/module-runner';
33
+ import 'module';
32
34
  import 'node:assert';
33
35
  import 'node:v8';
34
- import 'module';
35
36
  import 'node:worker_threads';
36
37
  import 'node:events';
37
38
  import 'crypto';
39
+ import 'querystring';
38
40
  import 'node:buffer';
39
41
  import 'node:readline';
40
42
  import 'zlib';
41
43
  import 'buffer';
42
44
  import 'https';
43
45
  import 'tls';
44
- import 'querystring';
45
46
  import 'node:zlib';
46
47
 
47
48
  // This file will be built for both ESM and CJS. Avoid relying on other modules as possible.
@@ -199,116 +200,4 @@ class RemoteEnvironmentTransport {
199
200
  }
200
201
  }
201
202
 
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.");
238
- }
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) {
264
- return {
265
- connection: options.hmr.connection,
266
- logger: options.hmr.logger,
267
- };
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
- }
280
- },
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';
294
- }
295
- return prepareStackTrace;
296
- }
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());
312
- }
313
-
314
- export { RemoteEnvironmentTransport, ServerHMRConnector, createServerModuleRunner, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
203
+ export { RemoteEnvironmentTransport, isCSSRequest, splitVendorChunk, splitVendorChunkPlugin };
@@ -117,12 +117,12 @@ 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 destroyed;
126
126
  constructor(options: ModuleRunnerOptions, evaluator: ModuleEvaluator, debug?: ModuleRunnerDebugger | undefined);
127
127
  /**
128
128
  * URL to execute. Accepts file path, server path or id relative to the root.
@@ -141,12 +141,11 @@ declare class ModuleRunner {
141
141
  * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
142
142
  */
143
143
  isDestroyed(): boolean;
144
- private invalidateFiles;
145
144
  private normalizeEntryUrl;
146
145
  private processImport;
147
146
  private cachedRequest;
148
147
  private cachedModule;
149
- protected directRequest(id: string, fetchResult: ResolvedResult, _callstack: string[]): Promise<any>;
148
+ protected directRequest(id: string, mod: ModuleCache, _callstack: string[]): Promise<any>;
150
149
  }
151
150
 
152
151
  interface RetrieveFileHandler {
@@ -217,7 +216,8 @@ interface ModuleCache {
217
216
  exports?: any;
218
217
  evaluated?: boolean;
219
218
  map?: DecodedMap;
220
- meta?: FetchResult;
219
+ meta?: ResolvedResult;
220
+ timestamp?: number;
221
221
  /**
222
222
  * Module ids that imports this module
223
223
  */
@@ -314,7 +314,8 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
314
314
  get(fsPath: string): ModuleCache;
315
315
  deleteByModuleId(modulePath: string): boolean;
316
316
  delete(fsPath: string): boolean;
317
- invalidate(id: string): void;
317
+ invalidateUrl(id: string): void;
318
+ invalidateModule(module: ModuleCache): void;
318
319
  /**
319
320
  * Invalidate modules that dependent on the given modules, up to the main entry
320
321
  */
@@ -77,7 +77,15 @@ const isAbsolute = function(p) {
77
77
  }, dirname = function(p) {
78
78
  const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
79
79
  return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
80
- }, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8"), CHAR_FORWARD_SLASH = 47, CHAR_BACKWARD_SLASH = 92, percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g;
80
+ }, decodeBase64 = typeof atob < "u" ? atob : (str) => Buffer.from(str, "base64").toString("utf-8"), CHAR_FORWARD_SLASH = 47, CHAR_BACKWARD_SLASH = 92, percentRegEx = /%/g, backslashRegEx = /\\/g, newlineRegEx = /\n/g, carriageReturnRegEx = /\r/g, tabRegEx = /\t/g, questionRegex = /\?/g, hashRegex = /#/g, timestampRegex = /[?&]t=(\d{13})(&?)/;
81
+ function parseUrl(url) {
82
+ const idQuery = url.split("?")[1];
83
+ let timestamp = 0;
84
+ return {
85
+ query: idQuery ? ("?" + idQuery).replace(timestampRegex, (substring, tsString, nextItem) => (timestamp = Number(tsString), substring[0] === "?" && nextItem === "&" ? "?" : "")) : "",
86
+ timestamp
87
+ };
88
+ }
81
89
  function encodePathChars(filepath) {
82
90
  return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(`
83
91
  `) !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
@@ -251,7 +259,8 @@ class ModuleCacheMap extends Map {
251
259
  const mod = super.get(modulePath);
252
260
  return mod.imports || Object.assign(mod, {
253
261
  imports: /* @__PURE__ */ new Set(),
254
- importers: /* @__PURE__ */ new Set()
262
+ importers: /* @__PURE__ */ new Set(),
263
+ timestamp: 0
255
264
  }), mod;
256
265
  }
257
266
  get(fsPath) {
@@ -263,8 +272,11 @@ class ModuleCacheMap extends Map {
263
272
  delete(fsPath) {
264
273
  return this.deleteByModuleId(this.normalize(fsPath));
265
274
  }
266
- invalidate(id) {
275
+ invalidateUrl(id) {
267
276
  const module = this.get(id);
277
+ this.invalidateModule(module);
278
+ }
279
+ invalidateModule(module) {
268
280
  module.evaluated = !1, module.meta = void 0, module.map = void 0, module.promise = void 0, module.exports = void 0, module.imports?.clear();
269
281
  }
270
282
  /**
@@ -277,7 +289,7 @@ class ModuleCacheMap extends Map {
277
289
  continue;
278
290
  invalidated.add(id);
279
291
  const mod = super.get(id);
280
- mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidate(id);
292
+ mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidateUrl(id);
281
293
  }
282
294
  return invalidated;
283
295
  }
@@ -366,7 +378,7 @@ class HMRContext {
366
378
  }), this.send("vite:invalidate", {
367
379
  path: this.ownerPath,
368
380
  message
369
- }), this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
381
+ }), this.hmrClient.logger.debug(`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
370
382
  }
371
383
  on(event, cb) {
372
384
  const addToMap = (map) => {
@@ -451,7 +463,7 @@ class HMRClient {
451
463
  });
452
464
  }
453
465
  warnFailedUpdate(err, path) {
454
- err.message.includes("fetch") || this.logger.error(err), this.logger.error(`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
466
+ err.message.includes("fetch") || this.logger.error(err), this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
455
467
  }
456
468
  updateQueue = [];
457
469
  pendingUpdateQueue = !1;
@@ -486,7 +498,7 @@ class HMRClient {
486
498
  for (const { deps, fn } of qualifiedCallbacks)
487
499
  fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
488
500
  const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
489
- this.logger.debug(`[vite] hot updated: ${loggedPath}`);
501
+ this.logger.debug(`hot updated: ${loggedPath}`);
490
502
  };
491
503
  }
492
504
  }
@@ -517,6 +529,9 @@ const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_i
517
529
  }, silentConsole = {
518
530
  debug: noop,
519
531
  error: noop
532
+ }, hmrLogger = {
533
+ debug: (...msg) => console.log("[vite]", ...msg),
534
+ error: (error) => console.log("[vite]", error)
520
535
  };
521
536
  function createHMRHandler(runner) {
522
537
  const queue = new Queue();
@@ -527,13 +542,13 @@ async function handleHMRPayload(runner, payload) {
527
542
  if (!(!hmrClient || runner.isDestroyed()))
528
543
  switch (payload.type) {
529
544
  case "connected":
530
- hmrClient.logger.debug("[vite] connected."), hmrClient.messenger.flush();
545
+ hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
531
546
  break;
532
547
  case "update":
533
548
  await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(payload.updates.map(async (update) => {
534
549
  if (update.type === "js-update")
535
550
  return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
536
- hmrClient.logger.error("[vite] css hmr is not supported in runner mode.");
551
+ hmrClient.logger.error("css hmr is not supported in runner mode.");
537
552
  })), await hmrClient.notifyListeners("vite:afterUpdate", payload);
538
553
  break;
539
554
  case "custom": {
@@ -544,7 +559,7 @@ async function handleHMRPayload(runner, payload) {
544
559
  const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(runner, getModulesByFile(runner, slash(triggeredBy))) : findAllEntrypoints(runner);
545
560
  if (!clearEntrypoints.size)
546
561
  break;
547
- hmrClient.logger.debug("[vite] program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
562
+ hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
548
563
  for (const id of clearEntrypoints)
549
564
  await runner.import(id);
550
565
  break;
@@ -555,7 +570,7 @@ async function handleHMRPayload(runner, payload) {
555
570
  case "error": {
556
571
  await hmrClient.notifyListeners("vite:error", payload);
557
572
  const err = payload.err;
558
- hmrClient.logger.error(`[vite] Internal Server Error
573
+ hmrClient.logger.error(`Internal Server Error
559
574
  ${err.message}
560
575
  ${err.stack}`);
561
576
  break;
@@ -826,7 +841,7 @@ class ModuleRunner {
826
841
  */
827
842
  moduleCache;
828
843
  hmrClient;
829
- idToUrlMap = /* @__PURE__ */ new Map();
844
+ urlToIdMap = /* @__PURE__ */ new Map();
830
845
  fileToIdMap = /* @__PURE__ */ new Map();
831
846
  envProxy = new Proxy({}, {
832
847
  get(_, p) {
@@ -834,10 +849,13 @@ class ModuleRunner {
834
849
  }
835
850
  });
836
851
  transport;
837
- _destroyed = !1;
838
- _resetSourceMapSupport;
852
+ resetSourceMapSupport;
853
+ destroyed = !1;
839
854
  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));
855
+ 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 || hmrLogger, options.hmr.connection, ({ acceptedPath, explicitImportRequired, timestamp }) => {
856
+ const [acceptedPathWithoutQuery, query] = acceptedPath.split("?"), url = acceptedPathWithoutQuery + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`;
857
+ return this.import(url);
858
+ }), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
841
859
  }
842
860
  /**
843
861
  * URL to execute. Accepts file path, server path or id relative to the root.
@@ -851,27 +869,20 @@ class ModuleRunner {
851
869
  * Clear all caches including HMR listeners.
852
870
  */
853
871
  clearCache() {
854
- this.moduleCache.clear(), this.idToUrlMap.clear(), this.hmrClient?.clear();
872
+ this.moduleCache.clear(), this.urlToIdMap.clear(), this.hmrClient?.clear();
855
873
  }
856
874
  /**
857
875
  * Clears all caches, removes all HMR listeners, and resets source map support.
858
876
  * This method doesn't stop the HMR connection.
859
877
  */
860
878
  async destroy() {
861
- this._resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this._destroyed = !0;
879
+ this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.destroyed = !0;
862
880
  }
863
881
  /**
864
882
  * Returns `true` if the runtime has been destroyed by calling `destroy()` method.
865
883
  */
866
884
  isDestroyed() {
867
- return this._destroyed;
868
- }
869
- // map files to modules and invalidate them
870
- invalidateFiles(files) {
871
- files.forEach((file) => {
872
- const ids = this.fileToIdMap.get(file);
873
- ids && ids.forEach((id) => this.moduleCache.invalidate(id));
874
- });
885
+ return this.destroyed;
875
886
  }
876
887
  // we don't use moduleCache.normalize because this URL doesn't have to follow the same rules
877
888
  // this URL is something that user passes down manually, and is later resolved by fetchModule
@@ -889,10 +900,10 @@ class ModuleRunner {
889
900
  const { id, type } = fetchResult;
890
901
  return type !== "module" && type !== "commonjs" ? exports : (analyzeImportedModDifference(exports, id, type, metadata), proxyGuardOnlyEsm(exports, id, metadata));
891
902
  }
892
- async cachedRequest(id, fetchedModule, callstack = [], metadata) {
893
- const moduleId = fetchedModule.id, mod = this.moduleCache.getByModuleId(moduleId), { imports, importers } = mod, importee = callstack[callstack.length - 1];
903
+ async cachedRequest(id, mod, callstack = [], metadata) {
904
+ const meta = mod.meta, moduleId = meta.id, { imports, importers } = mod, importee = callstack[callstack.length - 1];
894
905
  if (importee && importers.add(importee), (callstack.includes(moduleId) || Array.from(imports.values()).some((i) => importers.has(i))) && mod.exports)
895
- return this.processImport(mod.exports, fetchedModule, metadata);
906
+ return this.processImport(mod.exports, meta, metadata);
896
907
  let debugTimer;
897
908
  this.debug && (debugTimer = setTimeout(() => {
898
909
  const getStack = () => `stack:
@@ -903,35 +914,35 @@ ${getStack()}`);
903
914
  }, 2e3));
904
915
  try {
905
916
  if (mod.promise)
906
- return this.processImport(await mod.promise, fetchedModule, metadata);
907
- const promise = this.directRequest(id, fetchedModule, callstack);
908
- return mod.promise = promise, mod.evaluated = !1, this.processImport(await promise, fetchedModule, metadata);
917
+ return this.processImport(await mod.promise, meta, metadata);
918
+ const promise = this.directRequest(id, mod, callstack);
919
+ return mod.promise = promise, mod.evaluated = !1, this.processImport(await promise, meta, metadata);
909
920
  } finally {
910
921
  mod.evaluated = !0, debugTimer && clearTimeout(debugTimer);
911
922
  }
912
923
  }
913
- async cachedModule(id, importer) {
914
- if (this._destroyed)
915
- throw new Error("[vite] Vite runtime has been destroyed.");
916
- const normalized = this.idToUrlMap.get(id);
924
+ async cachedModule(url, importer) {
925
+ if (this.destroyed)
926
+ throw new Error("Vite module runner has been destroyed.");
927
+ const normalized = this.urlToIdMap.get(url);
917
928
  if (normalized) {
918
929
  const mod2 = this.moduleCache.getByModuleId(normalized);
919
930
  if (mod2.meta)
920
- return mod2.meta;
931
+ return mod2;
921
932
  }
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);
924
- if (fetchedModule.id = moduleId, mod.meta = fetchedModule, file) {
933
+ this.debug?.("[module runner] fetching", url);
934
+ const fetchedModule = url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.fetchModule(url, importer), { query, timestamp } = parseUrl(url), file = "file" in fetchedModule ? fetchedModule.file : void 0, fileId = file ? `${file}${query}` : url, moduleId = this.moduleCache.normalize(fileId), mod = this.moduleCache.getByModuleId(moduleId);
935
+ if (mod.timestamp != null && timestamp > 0 && mod.timestamp < timestamp && this.moduleCache.invalidateModule(mod), fetchedModule.id = moduleId, mod.meta = fetchedModule, mod.timestamp = timestamp, file) {
925
936
  const fileModules = this.fileToIdMap.get(file) || [];
926
937
  fileModules.push(moduleId), this.fileToIdMap.set(file, fileModules);
927
938
  }
928
- return this.idToUrlMap.set(id, moduleId), this.idToUrlMap.set(unwrapId(id), moduleId), fetchedModule;
939
+ return this.urlToIdMap.set(url, moduleId), this.urlToIdMap.set(unwrapId(url), moduleId), mod;
929
940
  }
930
941
  // override is allowed, consider this a public API
931
- async directRequest(id, fetchResult, _callstack) {
932
- const moduleId = fetchResult.id, callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep, metadata) => {
933
- const fetchedModule = await this.cachedModule(dep, moduleId);
934
- return this.moduleCache.getByModuleId(fetchedModule.id).importers.add(moduleId), mod.imports.add(fetchedModule.id), this.cachedRequest(dep, fetchedModule, callstack, metadata);
942
+ async directRequest(id, mod, _callstack) {
943
+ const fetchResult = mod.meta, moduleId = fetchResult.id, callstack = [..._callstack, moduleId], request = async (dep, metadata) => {
944
+ const importer = "file" in fetchResult && fetchResult.file || moduleId, fetchedModule = await this.cachedModule(dep, importer), resolvedId = fetchedModule.meta.id;
945
+ return this.moduleCache.getByModuleId(resolvedId).importers.add(moduleId), mod.imports.add(resolvedId), this.cachedRequest(dep, fetchedModule, callstack, metadata);
935
946
  }, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(id), dep)), request(dep, { isDynamicImport: !0 }));
936
947
  if ("externalize" in fetchResult) {
937
948
  const { externalize } = fetchResult;