vite 6.3.0-beta.1 → 6.3.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.

package/LICENSE.md CHANGED
@@ -1056,21 +1056,6 @@ Repository: git://github.com/primus/eventemitter3.git
1056
1056
 
1057
1057
  ---------------------------------------
1058
1058
 
1059
- ## fdir
1060
- License: MIT
1061
- By: thecodrr
1062
- Repository: git+https://github.com/thecodrr/fdir.git
1063
-
1064
- > Copyright 2023 Abdullah Atta
1065
- >
1066
- > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1067
- >
1068
- > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1069
- >
1070
- > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1071
-
1072
- ---------------------------------------
1073
-
1074
1059
  ## finalhandler
1075
1060
  License: MIT
1076
1061
  By: Douglas Christopher Wilson
@@ -56,13 +56,16 @@ class HMRContext {
56
56
  decline() {
57
57
  }
58
58
  invalidate(message) {
59
+ const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
59
60
  this.hmrClient.notifyListeners("vite:invalidate", {
60
61
  path: this.ownerPath,
61
- message
62
+ message,
63
+ firstInvalidatedBy
62
64
  });
63
65
  this.send("vite:invalidate", {
64
66
  path: this.ownerPath,
65
- message
67
+ message,
68
+ firstInvalidatedBy
66
69
  });
67
70
  this.hmrClient.logger.debug(
68
71
  `invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
@@ -184,7 +187,7 @@ class HMRClient {
184
187
  }
185
188
  }
186
189
  async fetchUpdate(update) {
187
- const { path, acceptedPath } = update;
190
+ const { path, acceptedPath, firstInvalidatedBy } = update;
188
191
  const mod = this.hotModulesMap.get(path);
189
192
  if (!mod) {
190
193
  return;
@@ -204,13 +207,20 @@ class HMRClient {
204
207
  }
205
208
  }
206
209
  return () => {
207
- for (const { deps, fn } of qualifiedCallbacks) {
208
- fn(
209
- deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
210
- );
210
+ try {
211
+ this.currentFirstInvalidatedBy = firstInvalidatedBy;
212
+ for (const { deps, fn } of qualifiedCallbacks) {
213
+ fn(
214
+ deps.map(
215
+ (dep) => dep === acceptedPath ? fetchedModule : void 0
216
+ )
217
+ );
218
+ }
219
+ const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
220
+ this.logger.debug(`hot updated: ${loggedPath}`);
221
+ } finally {
222
+ this.currentFirstInvalidatedBy = void 0;
211
223
  }
212
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
213
- this.logger.debug(`hot updated: ${loggedPath}`);
214
224
  };
215
225
  }
216
226
  }
@@ -475,6 +485,42 @@ const createWebSocketModuleRunnerTransport = (options) => {
475
485
  };
476
486
  };
477
487
 
488
+ function createHMRHandler(handler) {
489
+ const queue = new Queue();
490
+ return (payload) => queue.enqueue(() => handler(payload));
491
+ }
492
+ class Queue {
493
+ constructor() {
494
+ this.queue = [];
495
+ this.pending = false;
496
+ }
497
+ enqueue(promise) {
498
+ return new Promise((resolve, reject) => {
499
+ this.queue.push({
500
+ promise,
501
+ resolve,
502
+ reject
503
+ });
504
+ this.dequeue();
505
+ });
506
+ }
507
+ dequeue() {
508
+ if (this.pending) {
509
+ return false;
510
+ }
511
+ const item = this.queue.shift();
512
+ if (!item) {
513
+ return false;
514
+ }
515
+ this.pending = true;
516
+ item.promise().then(item.resolve).catch(item.reject).finally(() => {
517
+ this.pending = false;
518
+ this.dequeue();
519
+ });
520
+ return true;
521
+ }
522
+ }
523
+
478
524
  const hmrConfigName = __HMR_CONFIG_NAME__;
479
525
  const base$1 = __BASE__ || "/";
480
526
  function h(e, attrs = {}, ...children) {
@@ -859,14 +905,14 @@ const hmrClient = new HMRClient(
859
905
  return await importPromise;
860
906
  }
861
907
  );
862
- transport.connect(handleMessage);
908
+ transport.connect(createHMRHandler(handleMessage));
863
909
  async function handleMessage(payload) {
864
910
  switch (payload.type) {
865
911
  case "connected":
866
912
  console.debug(`[vite] connected.`);
867
913
  break;
868
914
  case "update":
869
- notifyListeners("vite:beforeUpdate", payload);
915
+ await hmrClient.notifyListeners("vite:beforeUpdate", payload);
870
916
  if (hasDocument) {
871
917
  if (isFirstUpdate && hasErrorOverlay()) {
872
918
  location.reload();
@@ -909,10 +955,10 @@ async function handleMessage(payload) {
909
955
  });
910
956
  })
911
957
  );
912
- notifyListeners("vite:afterUpdate", payload);
958
+ await hmrClient.notifyListeners("vite:afterUpdate", payload);
913
959
  break;
914
960
  case "custom": {
915
- notifyListeners(payload.event, payload.data);
961
+ await hmrClient.notifyListeners(payload.event, payload.data);
916
962
  if (payload.event === "vite:ws:disconnect") {
917
963
  if (hasDocument && !willUnload) {
918
964
  console.log(`[vite] server connection lost. Polling for restart...`);
@@ -926,7 +972,7 @@ async function handleMessage(payload) {
926
972
  break;
927
973
  }
928
974
  case "full-reload":
929
- notifyListeners("vite:beforeFullReload", payload);
975
+ await hmrClient.notifyListeners("vite:beforeFullReload", payload);
930
976
  if (hasDocument) {
931
977
  if (payload.path && payload.path.endsWith(".html")) {
932
978
  const pagePath = decodeURI(location.pathname);
@@ -941,11 +987,11 @@ async function handleMessage(payload) {
941
987
  }
942
988
  break;
943
989
  case "prune":
944
- notifyListeners("vite:beforePrune", payload);
990
+ await hmrClient.notifyListeners("vite:beforePrune", payload);
945
991
  await hmrClient.prunePaths(payload.paths);
946
992
  break;
947
993
  case "error": {
948
- notifyListeners("vite:error", payload);
994
+ await hmrClient.notifyListeners("vite:error", payload);
949
995
  if (hasDocument) {
950
996
  const err = payload.err;
951
997
  if (enableOverlay) {
@@ -968,9 +1014,6 @@ ${err.stack}`
968
1014
  }
969
1015
  }
970
1016
  }
971
- function notifyListeners(event, data) {
972
- hmrClient.notifyListeners(event, data);
973
- }
974
1017
  const enableOverlay = __HMR_ENABLE_OVERLAY__;
975
1018
  const hasDocument = "document" in globalThis;
976
1019
  function createErrorOverlay(err) {