@voidzero-dev/vite-plus-core 0.3.1 → 0.3.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.
Files changed (68) hide show
  1. package/LICENSE +0 -29
  2. package/dist/rolldown/cli.mjs +6 -6
  3. package/dist/rolldown/config.d.mts +1 -1
  4. package/dist/rolldown/config.mjs +2 -2
  5. package/dist/rolldown/experimental-index.d.mts +9 -4
  6. package/dist/rolldown/experimental-index.mjs +10 -9
  7. package/dist/rolldown/experimental-runtime-types.d.ts +19 -0
  8. package/dist/rolldown/experimental-runtime.d.ts +19 -0
  9. package/dist/rolldown/experimental-runtime.mjs +42 -0
  10. package/dist/rolldown/filter-index.d.mts +1 -1
  11. package/dist/rolldown/index.d.mts +2 -2
  12. package/dist/rolldown/index.mjs +4 -4
  13. package/dist/rolldown/parallel-plugin-worker.mjs +2 -2
  14. package/dist/rolldown/parallel-plugin.d.mts +1 -1
  15. package/dist/rolldown/parse-ast-index.d.mts +1 -1
  16. package/dist/rolldown/parse-ast-index.mjs +1 -1
  17. package/dist/rolldown/plugins-index.d.mts +3 -3
  18. package/dist/rolldown/plugins-index.mjs +2 -2
  19. package/dist/rolldown/shared/{binding-DZuNHVw4.d.mts → binding-BTa6BPQe.d.mts} +23 -36
  20. package/dist/rolldown/shared/{binding-DmImI4pj.mjs → binding-BbrDfv1x.mjs} +53 -28
  21. package/dist/rolldown/shared/{bindingify-input-options-BYClWKnj.mjs → bindingify-input-options-CbBAjvu6.mjs} +9 -8
  22. package/dist/rolldown/shared/{constructors-BM20b11r.d.mts → constructors-CmDKpWIU.d.mts} +2 -2
  23. package/dist/rolldown/shared/{constructors-mRbcbLyX.mjs → constructors-D9jwEbE4.mjs} +1 -1
  24. package/dist/rolldown/shared/{create-bundler-option-CHTBktos.mjs → create-bundler-option-wxuQPB7F.mjs} +120 -160
  25. package/dist/rolldown/shared/{define-config-DNX0WekP.d.mts → define-config-BFdLpVut.d.mts} +10 -1
  26. package/dist/rolldown/shared/{error-BP8lJHle.mjs → error-CGhV1ebk.mjs} +1 -1
  27. package/dist/rolldown/shared/{load-config-Cx5fx_8Q.mjs → load-config-DOMKIWz0.mjs} +1 -1
  28. package/dist/rolldown/shared/{normalize-string-or-regex-Dm69lpQ-.mjs → normalize-string-or-regex-zc1bUto6.mjs} +1 -1
  29. package/dist/rolldown/shared/{parse-8sr82jSR.mjs → parse-B-7jgDap.mjs} +2 -2
  30. package/dist/rolldown/shared/{resolve-tsconfig-BlNGaH3Y.mjs → resolve-tsconfig-Bf6oL9fm.mjs} +2 -2
  31. package/dist/rolldown/shared/{rolldown-CaX_Wmqc.mjs → rolldown-DZGaRc5R.mjs} +4 -4
  32. package/dist/rolldown/shared/{transform-CVse9_mH.d.mts → transform-DK_nCt9j.d.mts} +1 -1
  33. package/dist/rolldown/shared/{watch-YKfJgIxz.mjs → watch-CUKYWzxY.mjs} +4 -4
  34. package/dist/rolldown/utils-index.d.mts +3 -3
  35. package/dist/rolldown/utils-index.mjs +5 -5
  36. package/dist/tsdown/{build-JVmLFaZt-kqQJ2U7s.js → build-JVmLFaZt-BN9yuB6k.js} +13 -426
  37. package/dist/tsdown/{debug-CpC4hV25-tvH_Dsg5.js → debug-CpC4hV25-BeCITV83.js} +4 -90
  38. package/dist/tsdown/{detect-Bg-d8iUV-KfbO7neP.js → detect-Bg-d8iUV-Cr_BRLVW.js} +1 -1
  39. package/dist/tsdown/{dist-Cuw3Ngo4.js → dist-ByW_jJfv.js} +5 -5
  40. package/dist/tsdown/index-types.d.ts +52 -52
  41. package/dist/tsdown/index.js +4 -4
  42. package/dist/tsdown/internal-DTYQdXId.js +3 -0
  43. package/dist/tsdown/{main-CyNcZUzu.js → main-bgV9NlwM.js} +88 -3
  44. package/dist/tsdown/{resolver-DE0_sy8o-ZQqHQjRu.js → resolver-DE0_sy8o-UMsN-SXx.js} +2 -2
  45. package/dist/tsdown/run.js +4 -4
  46. package/dist/tsdown/{src-BWidcM5N.js → src-D5xv98Iu.js} +4 -4
  47. package/dist/tsdown/target-DgdLrXba-DaJJ11xX.js +586 -0
  48. package/dist/tsdown/{tsc-ChjRhsoQ.js → tsc-BFDF_Im9.js} +3 -3
  49. package/dist/tsdown/tsdown-css.js +5 -3
  50. package/dist/tsdown/tsdown-exe.js +4 -15
  51. package/dist/vite/client/bundledDevClient.mjs +105 -40
  52. package/dist/vite/client/client.mjs +288 -260
  53. package/dist/vite/node/chunks/build.js +19 -19
  54. package/dist/vite/node/chunks/node.js +32770 -32305
  55. package/dist/vite/node/chunks/postcss-import.js +10 -10
  56. package/dist/vite/node/cli.js +12 -8
  57. package/dist/vite/node/index.d.ts +1568 -1577
  58. package/dist/vite/node/index.js +1 -1
  59. package/dist/vite/node/module-runner.d.ts +1 -1
  60. package/dist/vite/node/module-runner.js +199 -200
  61. package/dist/vite/types/customEvent.d.ts +2 -0
  62. package/dist/vite/types/hmrPayload.d.ts +2 -0
  63. package/dist/vite/types/internal/cssPreprocessorOptions.d.ts +2 -2
  64. package/dist/vite/types/internal/devtoolsOptions.d.ts +9 -0
  65. package/package.json +23 -26
  66. package/dist/tsdown/internal-D-JfB5uT.js +0 -29
  67. package/dist/tsdown/internal-lhH-5yya.js +0 -62
  68. package/dist/tsdown/version-CQ98ZBpL-Obdnv4J7.js +0 -141
@@ -1,229 +1,4 @@
1
1
  import "@vite/env";
2
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/typeof.js
3
- function _typeof(o) {
4
- "@babel/helpers - typeof";
5
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
6
- return typeof o;
7
- } : function(o) {
8
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9
- }, _typeof(o);
10
- }
11
- //#endregion
12
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPrimitive.js
13
- function toPrimitive(t, r) {
14
- if ("object" != _typeof(t) || !t) return t;
15
- var e = t[Symbol.toPrimitive];
16
- if (void 0 !== e) {
17
- var i = e.call(t, r || "default");
18
- if ("object" != _typeof(i)) return i;
19
- throw new TypeError("@@toPrimitive must return a primitive value.");
20
- }
21
- return ("string" === r ? String : Number)(t);
22
- }
23
- //#endregion
24
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/toPropertyKey.js
25
- function toPropertyKey(t) {
26
- var i = toPrimitive(t, "string");
27
- return "symbol" == _typeof(i) ? i : i + "";
28
- }
29
- //#endregion
30
- //#region \0@oxc-project+runtime@0.148.0/helpers/esm/defineProperty.js
31
- function _defineProperty(e, r, t) {
32
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
33
- value: t,
34
- enumerable: !0,
35
- configurable: !0,
36
- writable: !0
37
- }) : e[r] = t, e;
38
- }
39
- //#endregion
40
- //#region ../../vite/packages/vite/src/shared/hmr.ts
41
- var HMRContext = class {
42
- constructor(hmrClient, ownerPath) {
43
- this.hmrClient = hmrClient;
44
- this.ownerPath = ownerPath;
45
- _defineProperty(this, "newListeners", void 0);
46
- if (!hmrClient.dataMap.has(ownerPath)) hmrClient.dataMap.set(ownerPath, {});
47
- const mod = hmrClient.hotModulesMap.get(ownerPath);
48
- if (mod) mod.callbacks = [];
49
- const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
50
- if (staleListeners) for (const [event, staleFns] of staleListeners) {
51
- const listeners = hmrClient.customListenersMap.get(event);
52
- if (listeners) hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
53
- }
54
- this.newListeners = /* @__PURE__ */ new Map();
55
- hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
56
- }
57
- get data() {
58
- return this.hmrClient.dataMap.get(this.ownerPath);
59
- }
60
- accept(deps, callback) {
61
- if (typeof deps === "function" || !deps) this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
62
- else if (typeof deps === "string") this.acceptDeps([deps], ([mod]) => callback?.(mod));
63
- else if (Array.isArray(deps)) this.acceptDeps(deps, callback);
64
- else throw new Error(`invalid hot.accept() usage.`);
65
- }
66
- acceptExports(_, callback) {
67
- this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
68
- }
69
- dispose(cb) {
70
- this.hmrClient.disposeMap.set(this.ownerPath, cb);
71
- }
72
- prune(cb) {
73
- this.hmrClient.pruneMap.set(this.ownerPath, cb);
74
- }
75
- decline() {}
76
- invalidate(message) {
77
- const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
78
- this.hmrClient.notifyListeners("vite:invalidate", {
79
- path: this.ownerPath,
80
- message,
81
- firstInvalidatedBy
82
- });
83
- this.send("vite:invalidate", {
84
- path: this.ownerPath,
85
- message,
86
- firstInvalidatedBy
87
- });
88
- this.hmrClient.logger.debug(`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
89
- }
90
- on(event, cb) {
91
- const addToMap = (map) => {
92
- const existing = map.get(event) || [];
93
- existing.push(cb);
94
- map.set(event, existing);
95
- };
96
- addToMap(this.hmrClient.customListenersMap);
97
- addToMap(this.newListeners);
98
- }
99
- off(event, cb) {
100
- const removeFromMap = (map) => {
101
- const existing = map.get(event);
102
- if (existing === void 0) return;
103
- const pruned = existing.filter((l) => l !== cb);
104
- if (pruned.length === 0) {
105
- map.delete(event);
106
- return;
107
- }
108
- map.set(event, pruned);
109
- };
110
- removeFromMap(this.hmrClient.customListenersMap);
111
- removeFromMap(this.newListeners);
112
- }
113
- send(event, data) {
114
- this.hmrClient.send({
115
- type: "custom",
116
- event,
117
- data
118
- });
119
- }
120
- acceptDeps(deps, callback = () => {}) {
121
- const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
122
- id: this.ownerPath,
123
- callbacks: []
124
- };
125
- mod.callbacks.push({
126
- deps,
127
- fn: callback
128
- });
129
- this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
130
- }
131
- };
132
- var HMRClient = class {
133
- constructor(logger, transport, importUpdatedModule) {
134
- this.logger = logger;
135
- this.transport = transport;
136
- this.importUpdatedModule = importUpdatedModule;
137
- _defineProperty(this, "hotModulesMap", /* @__PURE__ */ new Map());
138
- _defineProperty(this, "disposeMap", /* @__PURE__ */ new Map());
139
- _defineProperty(this, "pruneMap", /* @__PURE__ */ new Map());
140
- _defineProperty(this, "dataMap", /* @__PURE__ */ new Map());
141
- _defineProperty(this, "customListenersMap", /* @__PURE__ */ new Map());
142
- _defineProperty(this, "ctxToListenersMap", /* @__PURE__ */ new Map());
143
- _defineProperty(this, "currentFirstInvalidatedBy", void 0);
144
- _defineProperty(this, "updateQueue", []);
145
- _defineProperty(this, "pendingUpdateQueue", false);
146
- }
147
- async notifyListeners(event, data) {
148
- const cbs = this.customListenersMap.get(event);
149
- if (cbs) await Promise.allSettled(cbs.map((cb) => cb(data)));
150
- }
151
- send(payload) {
152
- this.transport.send(payload).catch((err) => {
153
- this.logger.error(err);
154
- });
155
- }
156
- clear() {
157
- this.hotModulesMap.clear();
158
- this.disposeMap.clear();
159
- this.pruneMap.clear();
160
- this.dataMap.clear();
161
- this.customListenersMap.clear();
162
- this.ctxToListenersMap.clear();
163
- }
164
- async prunePaths(paths) {
165
- try {
166
- await Promise.all(paths.map((path) => {
167
- const disposer = this.disposeMap.get(path);
168
- if (disposer) return disposer(this.dataMap.get(path));
169
- }));
170
- await Promise.all(paths.map((path) => {
171
- const fn = this.pruneMap.get(path);
172
- if (fn) return fn(this.dataMap.get(path));
173
- }));
174
- } finally {
175
- paths.forEach((path) => this.dataMap.delete(path));
176
- }
177
- }
178
- warnFailedUpdate(err, path) {
179
- if (!(err instanceof Error) || !err.message.includes("fetch")) this.logger.error(err);
180
- this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
181
- }
182
- /**
183
- * buffer multiple hot updates triggered by the same src change
184
- * so that they are invoked in the same order they were sent.
185
- * (otherwise the order may be inconsistent because of the http request round trip)
186
- */
187
- async queueUpdate(payload) {
188
- this.updateQueue.push(this.fetchUpdate(payload));
189
- if (!this.pendingUpdateQueue) {
190
- this.pendingUpdateQueue = true;
191
- await Promise.resolve();
192
- this.pendingUpdateQueue = false;
193
- const loading = [...this.updateQueue];
194
- this.updateQueue = [];
195
- (await Promise.all(loading)).forEach((fn) => fn && fn());
196
- }
197
- }
198
- async fetchUpdate(update) {
199
- const { path, acceptedPath, firstInvalidatedBy } = update;
200
- const mod = this.hotModulesMap.get(path);
201
- if (!mod) return;
202
- let fetchedModule;
203
- const isSelfUpdate = path === acceptedPath;
204
- const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
205
- if (isSelfUpdate || qualifiedCallbacks.length > 0) {
206
- const disposer = this.disposeMap.get(acceptedPath);
207
- if (disposer) await disposer(this.dataMap.get(acceptedPath));
208
- try {
209
- fetchedModule = await this.importUpdatedModule(update);
210
- } catch (e) {
211
- this.warnFailedUpdate(e, acceptedPath);
212
- }
213
- }
214
- return () => {
215
- try {
216
- this.currentFirstInvalidatedBy = firstInvalidatedBy;
217
- for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
218
- const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
219
- this.logger.debug(`hot updated: ${loggedPath}`);
220
- } finally {
221
- this.currentFirstInvalidatedBy = void 0;
222
- }
223
- };
224
- }
225
- };
226
- //#endregion
227
2
  //#region ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/non-secure/index.js
228
3
  let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
229
4
  let nanoid = (size = 21) => {
@@ -234,9 +9,33 @@ let nanoid = (size = 21) => {
234
9
  };
235
10
  //#endregion
236
11
  //#region ../../vite/packages/vite/src/shared/constants.ts
12
+ /**
13
+ * Prefix for resolved Ids that are not valid browser import specifiers
14
+ */
15
+ const VALID_ID_PREFIX = `/@id/`;
16
+ /**
17
+ * Plugins that use 'virtual modules' (e.g. for helper functions), prefix the
18
+ * module ID with `\0`, a convention from the rollup ecosystem.
19
+ * This prevents other plugins from trying to process the id (like node resolution),
20
+ * and core features like sourcemaps can use this info to differentiate between
21
+ * virtual modules and regular files.
22
+ * `\0` is not a permitted char in import URLs so we have to replace them during
23
+ * import analysis. The id will be decoded back before entering the plugins pipeline.
24
+ * These encoded virtual ids are also prefixed by the VALID_ID_PREFIX, so virtual
25
+ * modules in the browser end up encoded as `/@id/__x00__{id}`
26
+ */
27
+ const NULL_BYTE_PLACEHOLDER = `__x00__`;
237
28
  let SOURCEMAPPING_URL = "sourceMa";
238
29
  SOURCEMAPPING_URL += "ppingURL";
239
30
  typeof process !== "undefined" && process.platform;
31
+ /**
32
+ * Prepend `/@id/` and replace null byte so the id is URL-safe.
33
+ * This is prepended to resolved ids that are not valid browser
34
+ * import specifiers by the importAnalysis plugin.
35
+ */
36
+ function wrapId(id) {
37
+ return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
38
+ }
240
39
  (async function() {}).constructor;
241
40
  function promiseWithResolvers() {
242
41
  let resolve;
@@ -451,40 +250,7 @@ const createWebSocketModuleRunnerTransport = (options) => {
451
250
  send(data) {
452
251
  ws.send(JSON.stringify(data));
453
252
  }
454
- };
455
- };
456
- //#endregion
457
- //#region ../../vite/packages/vite/src/shared/hmrHandler.ts
458
- function createHMRHandler(handler) {
459
- const queue = new Queue();
460
- return (payload) => queue.enqueue(() => handler(payload));
461
- }
462
- var Queue = class {
463
- constructor() {
464
- _defineProperty(this, "queue", []);
465
- _defineProperty(this, "pending", false);
466
- }
467
- enqueue(promise) {
468
- return new Promise((resolve, reject) => {
469
- this.queue.push({
470
- promise,
471
- resolve,
472
- reject
473
- });
474
- this.dequeue();
475
- });
476
- }
477
- dequeue() {
478
- if (this.pending) return false;
479
- const item = this.queue.shift();
480
- if (!item) return false;
481
- this.pending = true;
482
- item.promise().then(item.resolve).catch(item.reject).finally(() => {
483
- this.pending = false;
484
- this.dequeue();
485
- });
486
- return true;
487
- }
253
+ };
488
254
  };
489
255
  //#endregion
490
256
  //#region ../../vite/packages/vite/src/shared/forwardConsole.ts
@@ -615,6 +381,264 @@ function stringifyConsoleArg(value) {
615
381
  }
616
382
  }
617
383
  //#endregion
384
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/typeof.js
385
+ function _typeof(o) {
386
+ "@babel/helpers - typeof";
387
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
388
+ return typeof o;
389
+ } : function(o) {
390
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
391
+ }, _typeof(o);
392
+ }
393
+ //#endregion
394
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPrimitive.js
395
+ function toPrimitive(t, r) {
396
+ if ("object" != _typeof(t) || !t) return t;
397
+ var e = t[Symbol.toPrimitive];
398
+ if (void 0 !== e) {
399
+ var i = e.call(t, r || "default");
400
+ if ("object" != _typeof(i)) return i;
401
+ throw new TypeError("@@toPrimitive must return a primitive value.");
402
+ }
403
+ return ("string" === r ? String : Number)(t);
404
+ }
405
+ //#endregion
406
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/toPropertyKey.js
407
+ function toPropertyKey(t) {
408
+ var i = toPrimitive(t, "string");
409
+ return "symbol" == _typeof(i) ? i : i + "";
410
+ }
411
+ //#endregion
412
+ //#region \0@oxc-project+runtime@0.150.0/helpers/esm/defineProperty.js
413
+ function _defineProperty(e, r, t) {
414
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
415
+ value: t,
416
+ enumerable: !0,
417
+ configurable: !0,
418
+ writable: !0
419
+ }) : e[r] = t, e;
420
+ }
421
+ //#endregion
422
+ //#region ../../vite/packages/vite/src/shared/hmr.ts
423
+ var HMRContext = class {
424
+ constructor(hmrClient, ownerPath) {
425
+ this.hmrClient = hmrClient;
426
+ this.ownerPath = ownerPath;
427
+ _defineProperty(this, "newListeners", void 0);
428
+ if (!hmrClient.dataMap.has(ownerPath)) hmrClient.dataMap.set(ownerPath, {});
429
+ const mod = hmrClient.hotModulesMap.get(ownerPath);
430
+ if (mod) mod.callbacks = [];
431
+ const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
432
+ if (staleListeners) for (const [event, staleFns] of staleListeners) {
433
+ const listeners = hmrClient.customListenersMap.get(event);
434
+ if (listeners) hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
435
+ }
436
+ this.newListeners = /* @__PURE__ */ new Map();
437
+ hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
438
+ }
439
+ get data() {
440
+ return this.hmrClient.dataMap.get(this.ownerPath);
441
+ }
442
+ accept(deps, callback) {
443
+ if (typeof deps === "function" || !deps) this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
444
+ else if (typeof deps === "string") this.acceptDeps([deps], ([mod]) => callback?.(mod));
445
+ else if (Array.isArray(deps)) this.acceptDeps(deps, callback);
446
+ else throw new Error(`invalid hot.accept() usage.`);
447
+ }
448
+ acceptExports(_, callback) {
449
+ this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
450
+ }
451
+ dispose(cb) {
452
+ this.hmrClient.disposeMap.set(this.ownerPath, cb);
453
+ }
454
+ prune(cb) {
455
+ this.hmrClient.pruneMap.set(this.ownerPath, cb);
456
+ }
457
+ decline() {}
458
+ invalidate(message) {
459
+ const firstInvalidatedBy = this.hmrClient.currentFirstInvalidatedBy ?? this.ownerPath;
460
+ this.hmrClient.notifyListeners("vite:invalidate", {
461
+ path: this.ownerPath,
462
+ message,
463
+ firstInvalidatedBy
464
+ });
465
+ this.send("vite:invalidate", {
466
+ path: this.ownerPath,
467
+ message,
468
+ firstInvalidatedBy
469
+ });
470
+ this.hmrClient.logger.debug(`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
471
+ }
472
+ on(event, cb) {
473
+ const addToMap = (map) => {
474
+ const existing = map.get(event) || [];
475
+ existing.push(cb);
476
+ map.set(event, existing);
477
+ };
478
+ addToMap(this.hmrClient.customListenersMap);
479
+ addToMap(this.newListeners);
480
+ }
481
+ off(event, cb) {
482
+ const removeFromMap = (map) => {
483
+ const existing = map.get(event);
484
+ if (existing === void 0) return;
485
+ const pruned = existing.filter((l) => l !== cb);
486
+ if (pruned.length === 0) {
487
+ map.delete(event);
488
+ return;
489
+ }
490
+ map.set(event, pruned);
491
+ };
492
+ removeFromMap(this.hmrClient.customListenersMap);
493
+ removeFromMap(this.newListeners);
494
+ }
495
+ send(event, data) {
496
+ this.hmrClient.send({
497
+ type: "custom",
498
+ event,
499
+ data
500
+ });
501
+ }
502
+ acceptDeps(deps, callback = () => {}) {
503
+ const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
504
+ id: this.ownerPath,
505
+ callbacks: []
506
+ };
507
+ mod.callbacks.push({
508
+ deps,
509
+ fn: callback
510
+ });
511
+ this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
512
+ }
513
+ };
514
+ var HMRClient = class {
515
+ constructor(logger, transport, importUpdatedModule) {
516
+ this.logger = logger;
517
+ this.transport = transport;
518
+ this.importUpdatedModule = importUpdatedModule;
519
+ _defineProperty(this, "hotModulesMap", /* @__PURE__ */ new Map());
520
+ _defineProperty(this, "disposeMap", /* @__PURE__ */ new Map());
521
+ _defineProperty(this, "pruneMap", /* @__PURE__ */ new Map());
522
+ _defineProperty(this, "dataMap", /* @__PURE__ */ new Map());
523
+ _defineProperty(this, "customListenersMap", /* @__PURE__ */ new Map());
524
+ _defineProperty(this, "ctxToListenersMap", /* @__PURE__ */ new Map());
525
+ _defineProperty(this, "currentFirstInvalidatedBy", void 0);
526
+ _defineProperty(this, "updateQueue", []);
527
+ _defineProperty(this, "pendingUpdateQueue", false);
528
+ }
529
+ async notifyListeners(event, data) {
530
+ const cbs = this.customListenersMap.get(event);
531
+ if (cbs) await Promise.allSettled(cbs.map((cb) => cb(data)));
532
+ }
533
+ send(payload) {
534
+ this.transport.send(payload).catch((err) => {
535
+ this.logger.error(err);
536
+ });
537
+ }
538
+ clear() {
539
+ this.hotModulesMap.clear();
540
+ this.disposeMap.clear();
541
+ this.pruneMap.clear();
542
+ this.dataMap.clear();
543
+ this.customListenersMap.clear();
544
+ this.ctxToListenersMap.clear();
545
+ }
546
+ async prunePaths(paths) {
547
+ try {
548
+ await Promise.all(paths.map((path) => {
549
+ const disposer = this.disposeMap.get(path);
550
+ if (disposer) return disposer(this.dataMap.get(path));
551
+ }));
552
+ await Promise.all(paths.map((path) => {
553
+ const fn = this.pruneMap.get(path);
554
+ if (fn) return fn(this.dataMap.get(path));
555
+ }));
556
+ } finally {
557
+ paths.forEach((path) => this.dataMap.delete(path));
558
+ }
559
+ }
560
+ warnFailedUpdate(err, path) {
561
+ if (!(err instanceof Error) || !err.message.includes("fetch")) this.logger.error(err);
562
+ this.logger.error(`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`);
563
+ }
564
+ /**
565
+ * buffer multiple hot updates triggered by the same src change
566
+ * so that they are invoked in the same order they were sent.
567
+ * (otherwise the order may be inconsistent because of the http request round trip)
568
+ */
569
+ async queueUpdate(payload) {
570
+ this.updateQueue.push(this.fetchUpdate(payload));
571
+ if (!this.pendingUpdateQueue) {
572
+ this.pendingUpdateQueue = true;
573
+ await Promise.resolve();
574
+ this.pendingUpdateQueue = false;
575
+ const loading = [...this.updateQueue];
576
+ this.updateQueue = [];
577
+ (await Promise.all(loading)).forEach((fn) => fn && fn());
578
+ }
579
+ }
580
+ async fetchUpdate(update) {
581
+ const { path, acceptedPath, firstInvalidatedBy } = update;
582
+ const mod = this.hotModulesMap.get(path);
583
+ if (!mod) return;
584
+ let fetchedModule;
585
+ const isSelfUpdate = path === acceptedPath;
586
+ const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
587
+ if (isSelfUpdate || qualifiedCallbacks.length > 0) {
588
+ const disposer = this.disposeMap.get(acceptedPath);
589
+ if (disposer) await disposer(this.dataMap.get(acceptedPath));
590
+ try {
591
+ fetchedModule = await this.importUpdatedModule(update);
592
+ } catch (e) {
593
+ this.warnFailedUpdate(e, acceptedPath);
594
+ }
595
+ }
596
+ return () => {
597
+ try {
598
+ this.currentFirstInvalidatedBy = firstInvalidatedBy;
599
+ for (const { deps, fn } of qualifiedCallbacks) fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
600
+ const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
601
+ this.logger.debug(`hot updated: ${loggedPath}`);
602
+ } finally {
603
+ this.currentFirstInvalidatedBy = void 0;
604
+ }
605
+ };
606
+ }
607
+ };
608
+ //#endregion
609
+ //#region ../../vite/packages/vite/src/shared/hmrHandler.ts
610
+ function createHMRHandler(handler) {
611
+ const queue = new Queue();
612
+ return (payload) => queue.enqueue(() => handler(payload));
613
+ }
614
+ var Queue = class {
615
+ constructor() {
616
+ _defineProperty(this, "queue", []);
617
+ _defineProperty(this, "pending", false);
618
+ }
619
+ enqueue(promise) {
620
+ return new Promise((resolve, reject) => {
621
+ this.queue.push({
622
+ promise,
623
+ resolve,
624
+ reject
625
+ });
626
+ this.dequeue();
627
+ });
628
+ }
629
+ dequeue() {
630
+ if (this.pending) return false;
631
+ const item = this.queue.shift();
632
+ if (!item) return false;
633
+ this.pending = true;
634
+ item.promise().then(item.resolve).catch(item.reject).finally(() => {
635
+ this.pending = false;
636
+ this.dequeue();
637
+ });
638
+ return true;
639
+ }
640
+ };
641
+ //#endregion
618
642
  //#region ../../vite/packages/vite/src/client/overlay.ts
619
643
  const hmrConfigName = __HMR_CONFIG_NAME__;
620
644
  const base$1 = __BASE__ || "/";
@@ -934,14 +958,18 @@ const debounceReload = (time) => {
934
958
  };
935
959
  };
936
960
  const pageReload = debounceReload(20);
961
+ function wrapIdIfNeeded(id) {
962
+ return id[0] === "." || id[0] === "/" ? id : wrapId(id);
963
+ }
937
964
  const hmrClient = new HMRClient({
938
965
  error: (err) => console.error("[vite]", err),
939
966
  debug: (...msg) => console.debug("[vite]", ...msg)
940
967
  }, transport, async function importUpdatedModule({ acceptedPath, timestamp, explicitImportRequired, isWithinCircularImport }) {
941
968
  const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
969
+ const browserPath = wrapIdIfNeeded(acceptedPathWithoutQuery);
942
970
  const importPromise = import(
943
971
  /* @vite-ignore */
944
- base + acceptedPathWithoutQuery.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
972
+ base + browserPath.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
945
973
  );
946
974
  if (isWithinCircularImport) importPromise.catch(() => {
947
975
  console.info(`[hmr] ${acceptedPath} failed to apply HMR as it's within a circular import. Reloading page to reset the execution order. To debug and break the circular import, you can run \`vite --debug hmr\` to log the circular dependency path if a file change triggered it.`);