vite 8.2.1 → 8.3.0-beta.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.
- package/bin/vite.js +17 -6
- package/dist/client/bundledDevClient.mjs +149 -65
- package/dist/client/client.mjs +426 -392
- package/dist/node/chunks/build.js +70 -64
- package/dist/node/chunks/dist.js +36 -29
- package/dist/node/chunks/node.js +29216 -28843
- package/dist/node/chunks/postcss-import.js +23 -25
- package/dist/node/cli.js +11 -7
- package/dist/node/index.d.ts +1601 -1555
- package/dist/node/index.js +1 -1
- package/dist/node/module-runner.d.ts +14 -14
- package/dist/node/module-runner.js +200 -198
- package/package.json +18 -18
- package/types/customEvent.d.ts +8 -0
- package/types/hmrPayload.d.ts +8 -0
- package/types/internal/cssPreprocessorOptions.d.ts +2 -2
package/dist/client/client.mjs
CHANGED
|
@@ -1,5 +1,387 @@
|
|
|
1
1
|
import "@vite/env";
|
|
2
|
-
//#region
|
|
2
|
+
//#region ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/non-secure/index.js
|
|
3
|
+
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
4
|
+
let nanoid = (size = 21) => {
|
|
5
|
+
let id = "";
|
|
6
|
+
let i = size | 0;
|
|
7
|
+
while (i-- > 0) id += urlAlphabet[Math.random() * 64 | 0];
|
|
8
|
+
return id;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region 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__`;
|
|
28
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
|
29
|
+
SOURCEMAPPING_URL += "ppingURL";
|
|
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
|
+
}
|
|
39
|
+
(async function() {}).constructor;
|
|
40
|
+
function promiseWithResolvers() {
|
|
41
|
+
let resolve;
|
|
42
|
+
let reject;
|
|
43
|
+
return {
|
|
44
|
+
promise: new Promise((_resolve, _reject) => {
|
|
45
|
+
resolve = _resolve;
|
|
46
|
+
reject = _reject;
|
|
47
|
+
}),
|
|
48
|
+
resolve,
|
|
49
|
+
reject
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/shared/moduleRunnerTransport.ts
|
|
54
|
+
function reviveInvokeError(e) {
|
|
55
|
+
const error = new Error(e.message || "Unknown invoke error");
|
|
56
|
+
Object.assign(error, e, { runnerError: /* @__PURE__ */ new Error("RunnerError") });
|
|
57
|
+
return error;
|
|
58
|
+
}
|
|
59
|
+
const createInvokeableTransport = (transport) => {
|
|
60
|
+
if (transport.invoke) return {
|
|
61
|
+
...transport,
|
|
62
|
+
async invoke(name, data) {
|
|
63
|
+
const result = await transport.invoke({
|
|
64
|
+
type: "custom",
|
|
65
|
+
event: "vite:invoke",
|
|
66
|
+
data: {
|
|
67
|
+
id: "send",
|
|
68
|
+
name,
|
|
69
|
+
data
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
if ("error" in result) throw reviveInvokeError(result.error);
|
|
73
|
+
return result.result;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
if (!transport.send || !transport.connect) throw new Error("transport must implement send and connect when invoke is not implemented");
|
|
77
|
+
const rpcPromises = /* @__PURE__ */ new Map();
|
|
78
|
+
return {
|
|
79
|
+
...transport,
|
|
80
|
+
connect({ onMessage, onDisconnection }) {
|
|
81
|
+
return transport.connect({
|
|
82
|
+
onMessage(payload) {
|
|
83
|
+
if (payload.type === "custom" && payload.event === "vite:invoke") {
|
|
84
|
+
const data = payload.data;
|
|
85
|
+
if (data.id.startsWith("response:")) {
|
|
86
|
+
const invokeId = data.id.slice(9);
|
|
87
|
+
const promise = rpcPromises.get(invokeId);
|
|
88
|
+
if (!promise) return;
|
|
89
|
+
if (promise.timeoutId) clearTimeout(promise.timeoutId);
|
|
90
|
+
rpcPromises.delete(invokeId);
|
|
91
|
+
const { error, result } = data.data;
|
|
92
|
+
if (error) promise.reject(error);
|
|
93
|
+
else promise.resolve(result);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
onMessage(payload);
|
|
98
|
+
},
|
|
99
|
+
onDisconnection
|
|
100
|
+
});
|
|
101
|
+
},
|
|
102
|
+
disconnect() {
|
|
103
|
+
rpcPromises.forEach((promise) => {
|
|
104
|
+
promise.reject(/* @__PURE__ */ new Error(`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`));
|
|
105
|
+
});
|
|
106
|
+
rpcPromises.clear();
|
|
107
|
+
return transport.disconnect?.();
|
|
108
|
+
},
|
|
109
|
+
send(data) {
|
|
110
|
+
return transport.send(data);
|
|
111
|
+
},
|
|
112
|
+
async invoke(name, data) {
|
|
113
|
+
const promiseId = nanoid();
|
|
114
|
+
const wrappedData = {
|
|
115
|
+
type: "custom",
|
|
116
|
+
event: "vite:invoke",
|
|
117
|
+
data: {
|
|
118
|
+
name,
|
|
119
|
+
id: `send:${promiseId}`,
|
|
120
|
+
data
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const sendPromise = transport.send(wrappedData);
|
|
124
|
+
const { promise, resolve, reject } = promiseWithResolvers();
|
|
125
|
+
const timeout = transport.timeout ?? 6e4;
|
|
126
|
+
let timeoutId;
|
|
127
|
+
if (timeout > 0) {
|
|
128
|
+
timeoutId = setTimeout(() => {
|
|
129
|
+
rpcPromises.delete(promiseId);
|
|
130
|
+
reject(/* @__PURE__ */ new Error(`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`));
|
|
131
|
+
}, timeout);
|
|
132
|
+
timeoutId?.unref?.();
|
|
133
|
+
}
|
|
134
|
+
rpcPromises.set(promiseId, {
|
|
135
|
+
resolve,
|
|
136
|
+
reject,
|
|
137
|
+
name,
|
|
138
|
+
timeoutId
|
|
139
|
+
});
|
|
140
|
+
if (sendPromise) sendPromise.catch((err) => {
|
|
141
|
+
clearTimeout(timeoutId);
|
|
142
|
+
rpcPromises.delete(promiseId);
|
|
143
|
+
reject(err);
|
|
144
|
+
});
|
|
145
|
+
try {
|
|
146
|
+
return await promise;
|
|
147
|
+
} catch (err) {
|
|
148
|
+
throw reviveInvokeError(err);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
const normalizeModuleRunnerTransport = (transport) => {
|
|
154
|
+
const invokeableTransport = createInvokeableTransport(transport);
|
|
155
|
+
let isConnected = !invokeableTransport.connect;
|
|
156
|
+
let connectingPromise;
|
|
157
|
+
return {
|
|
158
|
+
...transport,
|
|
159
|
+
...invokeableTransport.connect ? { async connect(onMessage) {
|
|
160
|
+
if (isConnected) return;
|
|
161
|
+
if (connectingPromise) {
|
|
162
|
+
await connectingPromise;
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
const maybePromise = invokeableTransport.connect({
|
|
166
|
+
onMessage: onMessage ?? (() => {}),
|
|
167
|
+
onDisconnection() {
|
|
168
|
+
isConnected = false;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
if (maybePromise) {
|
|
172
|
+
connectingPromise = maybePromise;
|
|
173
|
+
await connectingPromise;
|
|
174
|
+
connectingPromise = void 0;
|
|
175
|
+
}
|
|
176
|
+
isConnected = true;
|
|
177
|
+
} } : {},
|
|
178
|
+
...invokeableTransport.disconnect ? { async disconnect() {
|
|
179
|
+
if (!isConnected) return;
|
|
180
|
+
if (connectingPromise) await connectingPromise;
|
|
181
|
+
isConnected = false;
|
|
182
|
+
await invokeableTransport.disconnect();
|
|
183
|
+
} } : {},
|
|
184
|
+
async send(data) {
|
|
185
|
+
if (!invokeableTransport.send) return;
|
|
186
|
+
if (!isConnected) {
|
|
187
|
+
if (connectingPromise) await connectingPromise;
|
|
188
|
+
else throw new SendBeforeConnectError("send was called before connect");
|
|
189
|
+
}
|
|
190
|
+
await invokeableTransport.send(data);
|
|
191
|
+
},
|
|
192
|
+
async invoke(name, data) {
|
|
193
|
+
if (!isConnected) {
|
|
194
|
+
if (connectingPromise) await connectingPromise;
|
|
195
|
+
else throw new SendBeforeConnectError("invoke was called before connect");
|
|
196
|
+
}
|
|
197
|
+
return invokeableTransport.invoke(name, data);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
var SendBeforeConnectError = class extends Error {
|
|
202
|
+
constructor(message) {
|
|
203
|
+
super(message);
|
|
204
|
+
this.name = "SendBeforeConnectError";
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const createWebSocketModuleRunnerTransport = (options) => {
|
|
208
|
+
const pingInterval = options.pingInterval ?? 3e4;
|
|
209
|
+
let ws;
|
|
210
|
+
let pingIntervalId;
|
|
211
|
+
return {
|
|
212
|
+
async connect({ onMessage, onDisconnection }) {
|
|
213
|
+
const socket = options.createConnection();
|
|
214
|
+
socket.addEventListener("message", ({ data }) => {
|
|
215
|
+
onMessage(JSON.parse(data));
|
|
216
|
+
});
|
|
217
|
+
let isOpened = socket.readyState === socket.OPEN;
|
|
218
|
+
if (!isOpened) await new Promise((resolve, reject) => {
|
|
219
|
+
socket.addEventListener("open", () => {
|
|
220
|
+
isOpened = true;
|
|
221
|
+
resolve();
|
|
222
|
+
}, { once: true });
|
|
223
|
+
socket.addEventListener("close", () => {
|
|
224
|
+
if (!isOpened) {
|
|
225
|
+
reject(/* @__PURE__ */ new Error("WebSocket closed without opened."));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
onMessage({
|
|
229
|
+
type: "custom",
|
|
230
|
+
event: "vite:ws:disconnect",
|
|
231
|
+
data: { webSocket: socket }
|
|
232
|
+
});
|
|
233
|
+
onDisconnection();
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
onMessage({
|
|
237
|
+
type: "custom",
|
|
238
|
+
event: "vite:ws:connect",
|
|
239
|
+
data: { webSocket: socket }
|
|
240
|
+
});
|
|
241
|
+
ws = socket;
|
|
242
|
+
pingIntervalId = setInterval(() => {
|
|
243
|
+
if (socket.readyState === socket.OPEN) socket.send(JSON.stringify({ type: "ping" }));
|
|
244
|
+
}, pingInterval);
|
|
245
|
+
},
|
|
246
|
+
disconnect() {
|
|
247
|
+
clearInterval(pingIntervalId);
|
|
248
|
+
ws?.close();
|
|
249
|
+
},
|
|
250
|
+
send(data) {
|
|
251
|
+
ws.send(JSON.stringify(data));
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/shared/forwardConsole.ts
|
|
257
|
+
function setupForwardConsoleHandler(transport, options, console = globalThis.console) {
|
|
258
|
+
if (!options.enabled) return;
|
|
259
|
+
async function sendError(type, error) {
|
|
260
|
+
await transport.send({
|
|
261
|
+
type: "custom",
|
|
262
|
+
event: "vite:forward-console",
|
|
263
|
+
data: {
|
|
264
|
+
type,
|
|
265
|
+
data: {
|
|
266
|
+
name: error?.name || "Unknown Error",
|
|
267
|
+
message: error?.message || String(error),
|
|
268
|
+
stack: error?.stack
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
async function sendLog(level, args) {
|
|
274
|
+
try {
|
|
275
|
+
await transport.send({
|
|
276
|
+
type: "custom",
|
|
277
|
+
event: "vite:forward-console",
|
|
278
|
+
data: {
|
|
279
|
+
type: "log",
|
|
280
|
+
data: {
|
|
281
|
+
level,
|
|
282
|
+
message: formatConsoleArgs(args)
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
} catch (err) {
|
|
287
|
+
try {
|
|
288
|
+
await sendError("unhandled-rejection", err);
|
|
289
|
+
} catch (err) {
|
|
290
|
+
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const originalConsoleError = console.error;
|
|
295
|
+
for (const level of options.logLevels) {
|
|
296
|
+
const original = console[level];
|
|
297
|
+
if (typeof original !== "function") continue;
|
|
298
|
+
console[level] = (...args) => {
|
|
299
|
+
original(...args);
|
|
300
|
+
sendLog(level, args);
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
if (options.unhandledErrors && typeof window !== "undefined") {
|
|
304
|
+
window.addEventListener("error", async (event) => {
|
|
305
|
+
const error = event.error ?? (event.message ? new Error(event.message) : event);
|
|
306
|
+
try {
|
|
307
|
+
await sendError("error", error);
|
|
308
|
+
} catch (err) {
|
|
309
|
+
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
window.addEventListener("unhandledrejection", async (event) => {
|
|
313
|
+
try {
|
|
314
|
+
await sendError("unhandled-rejection", event.reason);
|
|
315
|
+
} catch (err) {
|
|
316
|
+
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function formatConsoleArgs(args) {
|
|
322
|
+
if (args.length === 0) return "";
|
|
323
|
+
if (typeof args[0] !== "string") return args.map((arg) => stringifyConsoleArg(arg)).join(" ");
|
|
324
|
+
const len = args.length;
|
|
325
|
+
let i = 1;
|
|
326
|
+
let message = args[0].replace(/%[sdjifoOc%]/g, (specifier) => {
|
|
327
|
+
if (specifier === "%%") return "%";
|
|
328
|
+
if (i >= len) return specifier;
|
|
329
|
+
const arg = args[i++];
|
|
330
|
+
switch (specifier) {
|
|
331
|
+
case "%s":
|
|
332
|
+
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
333
|
+
return typeof arg === "object" && arg != null ? stringifyConsoleArg(arg) : String(arg);
|
|
334
|
+
case "%d":
|
|
335
|
+
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
336
|
+
if (typeof arg === "symbol") return "NaN";
|
|
337
|
+
return Number(arg).toString();
|
|
338
|
+
case "%i":
|
|
339
|
+
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
340
|
+
return Number.parseInt(String(arg), 10).toString();
|
|
341
|
+
case "%f": return Number.parseFloat(String(arg)).toString();
|
|
342
|
+
case "%o":
|
|
343
|
+
case "%O": return stringifyConsoleArg(arg);
|
|
344
|
+
case "%j": try {
|
|
345
|
+
return JSON.stringify(arg) ?? "undefined";
|
|
346
|
+
} catch {
|
|
347
|
+
return "[Circular]";
|
|
348
|
+
}
|
|
349
|
+
case "%c": return "";
|
|
350
|
+
default: return specifier;
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
for (let arg = args[i]; i < len; arg = args[++i]) if (arg == null || typeof arg !== "object") message += ` ${typeof arg === "symbol" ? arg.toString() : String(arg)}`;
|
|
354
|
+
else message += ` ${stringifyConsoleArg(arg)}`;
|
|
355
|
+
return message;
|
|
356
|
+
}
|
|
357
|
+
function stringifyConsoleArg(value) {
|
|
358
|
+
if (typeof value === "string") return value;
|
|
359
|
+
if (typeof value === "number" || typeof value === "boolean" || typeof value === "undefined") return String(value);
|
|
360
|
+
if (typeof value === "symbol") return value.toString();
|
|
361
|
+
if (typeof value === "function") return value.name ? `[Function: ${value.name}]` : "[Function]";
|
|
362
|
+
if (value instanceof Error) return value.stack || `${value.name}: ${value.message}`;
|
|
363
|
+
if (typeof value === "bigint") return `${value}n`;
|
|
364
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
365
|
+
try {
|
|
366
|
+
return JSON.stringify(value, (_, nested) => {
|
|
367
|
+
if (typeof nested === "bigint") return `${nested}n`;
|
|
368
|
+
if (nested instanceof Error) return {
|
|
369
|
+
name: nested.name,
|
|
370
|
+
message: nested.message,
|
|
371
|
+
stack: nested.stack
|
|
372
|
+
};
|
|
373
|
+
if (nested && typeof nested === "object") {
|
|
374
|
+
if (seen.has(nested)) return "[Circular]";
|
|
375
|
+
seen.add(nested);
|
|
376
|
+
}
|
|
377
|
+
return nested;
|
|
378
|
+
}) ?? String(value);
|
|
379
|
+
} catch {
|
|
380
|
+
return String(value);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/typeof.js
|
|
3
385
|
function _typeof(o) {
|
|
4
386
|
"@babel/helpers - typeof";
|
|
5
387
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -9,7 +391,7 @@ function _typeof(o) {
|
|
|
9
391
|
}, _typeof(o);
|
|
10
392
|
}
|
|
11
393
|
//#endregion
|
|
12
|
-
//#region \0@oxc-project+runtime@0.
|
|
394
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPrimitive.js
|
|
13
395
|
function toPrimitive(t, r) {
|
|
14
396
|
if ("object" != _typeof(t) || !t) return t;
|
|
15
397
|
var e = t[Symbol.toPrimitive];
|
|
@@ -21,13 +403,13 @@ function toPrimitive(t, r) {
|
|
|
21
403
|
return ("string" === r ? String : Number)(t);
|
|
22
404
|
}
|
|
23
405
|
//#endregion
|
|
24
|
-
//#region \0@oxc-project+runtime@0.
|
|
406
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/toPropertyKey.js
|
|
25
407
|
function toPropertyKey(t) {
|
|
26
408
|
var i = toPrimitive(t, "string");
|
|
27
409
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
28
410
|
}
|
|
29
411
|
//#endregion
|
|
30
|
-
//#region \0@oxc-project+runtime@0.
|
|
412
|
+
//#region \0@oxc-project+runtime@0.147.0/helpers/esm/defineProperty.js
|
|
31
413
|
function _defineProperty(e, r, t) {
|
|
32
414
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
33
415
|
value: t,
|
|
@@ -190,265 +572,39 @@ var HMRClient = class {
|
|
|
190
572
|
this.pendingUpdateQueue = true;
|
|
191
573
|
await Promise.resolve();
|
|
192
574
|
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
|
-
//#region ../../node_modules/.pnpm/nanoid@5.1.16/node_modules/nanoid/non-secure/index.js
|
|
228
|
-
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
229
|
-
let nanoid = (size = 21) => {
|
|
230
|
-
let id = "";
|
|
231
|
-
let i = size | 0;
|
|
232
|
-
while (i-- > 0) id += urlAlphabet[Math.random() * 64 | 0];
|
|
233
|
-
return id;
|
|
234
|
-
};
|
|
235
|
-
//#endregion
|
|
236
|
-
//#region src/shared/constants.ts
|
|
237
|
-
let SOURCEMAPPING_URL = "sourceMa";
|
|
238
|
-
SOURCEMAPPING_URL += "ppingURL";
|
|
239
|
-
typeof process !== "undefined" && process.platform;
|
|
240
|
-
(async function() {}).constructor;
|
|
241
|
-
function promiseWithResolvers() {
|
|
242
|
-
let resolve;
|
|
243
|
-
let reject;
|
|
244
|
-
return {
|
|
245
|
-
promise: new Promise((_resolve, _reject) => {
|
|
246
|
-
resolve = _resolve;
|
|
247
|
-
reject = _reject;
|
|
248
|
-
}),
|
|
249
|
-
resolve,
|
|
250
|
-
reject
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
//#endregion
|
|
254
|
-
//#region src/shared/moduleRunnerTransport.ts
|
|
255
|
-
function reviveInvokeError(e) {
|
|
256
|
-
const error = new Error(e.message || "Unknown invoke error");
|
|
257
|
-
Object.assign(error, e, { runnerError: /* @__PURE__ */ new Error("RunnerError") });
|
|
258
|
-
return error;
|
|
259
|
-
}
|
|
260
|
-
const createInvokeableTransport = (transport) => {
|
|
261
|
-
if (transport.invoke) return {
|
|
262
|
-
...transport,
|
|
263
|
-
async invoke(name, data) {
|
|
264
|
-
const result = await transport.invoke({
|
|
265
|
-
type: "custom",
|
|
266
|
-
event: "vite:invoke",
|
|
267
|
-
data: {
|
|
268
|
-
id: "send",
|
|
269
|
-
name,
|
|
270
|
-
data
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
if ("error" in result) throw reviveInvokeError(result.error);
|
|
274
|
-
return result.result;
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
if (!transport.send || !transport.connect) throw new Error("transport must implement send and connect when invoke is not implemented");
|
|
278
|
-
const rpcPromises = /* @__PURE__ */ new Map();
|
|
279
|
-
return {
|
|
280
|
-
...transport,
|
|
281
|
-
connect({ onMessage, onDisconnection }) {
|
|
282
|
-
return transport.connect({
|
|
283
|
-
onMessage(payload) {
|
|
284
|
-
if (payload.type === "custom" && payload.event === "vite:invoke") {
|
|
285
|
-
const data = payload.data;
|
|
286
|
-
if (data.id.startsWith("response:")) {
|
|
287
|
-
const invokeId = data.id.slice(9);
|
|
288
|
-
const promise = rpcPromises.get(invokeId);
|
|
289
|
-
if (!promise) return;
|
|
290
|
-
if (promise.timeoutId) clearTimeout(promise.timeoutId);
|
|
291
|
-
rpcPromises.delete(invokeId);
|
|
292
|
-
const { error, result } = data.data;
|
|
293
|
-
if (error) promise.reject(error);
|
|
294
|
-
else promise.resolve(result);
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
onMessage(payload);
|
|
299
|
-
},
|
|
300
|
-
onDisconnection
|
|
301
|
-
});
|
|
302
|
-
},
|
|
303
|
-
disconnect() {
|
|
304
|
-
rpcPromises.forEach((promise) => {
|
|
305
|
-
promise.reject(/* @__PURE__ */ new Error(`transport was disconnected, cannot call ${JSON.stringify(promise.name)}`));
|
|
306
|
-
});
|
|
307
|
-
rpcPromises.clear();
|
|
308
|
-
return transport.disconnect?.();
|
|
309
|
-
},
|
|
310
|
-
send(data) {
|
|
311
|
-
return transport.send(data);
|
|
312
|
-
},
|
|
313
|
-
async invoke(name, data) {
|
|
314
|
-
const promiseId = nanoid();
|
|
315
|
-
const wrappedData = {
|
|
316
|
-
type: "custom",
|
|
317
|
-
event: "vite:invoke",
|
|
318
|
-
data: {
|
|
319
|
-
name,
|
|
320
|
-
id: `send:${promiseId}`,
|
|
321
|
-
data
|
|
322
|
-
}
|
|
323
|
-
};
|
|
324
|
-
const sendPromise = transport.send(wrappedData);
|
|
325
|
-
const { promise, resolve, reject } = promiseWithResolvers();
|
|
326
|
-
const timeout = transport.timeout ?? 6e4;
|
|
327
|
-
let timeoutId;
|
|
328
|
-
if (timeout > 0) {
|
|
329
|
-
timeoutId = setTimeout(() => {
|
|
330
|
-
rpcPromises.delete(promiseId);
|
|
331
|
-
reject(/* @__PURE__ */ new Error(`transport invoke timed out after ${timeout}ms (data: ${JSON.stringify(wrappedData)})`));
|
|
332
|
-
}, timeout);
|
|
333
|
-
timeoutId?.unref?.();
|
|
334
|
-
}
|
|
335
|
-
rpcPromises.set(promiseId, {
|
|
336
|
-
resolve,
|
|
337
|
-
reject,
|
|
338
|
-
name,
|
|
339
|
-
timeoutId
|
|
340
|
-
});
|
|
341
|
-
if (sendPromise) sendPromise.catch((err) => {
|
|
342
|
-
clearTimeout(timeoutId);
|
|
343
|
-
rpcPromises.delete(promiseId);
|
|
344
|
-
reject(err);
|
|
345
|
-
});
|
|
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));
|
|
346
590
|
try {
|
|
347
|
-
|
|
348
|
-
} catch (
|
|
349
|
-
|
|
591
|
+
fetchedModule = await this.importUpdatedModule(update);
|
|
592
|
+
} catch (e) {
|
|
593
|
+
this.warnFailedUpdate(e, acceptedPath);
|
|
350
594
|
}
|
|
351
595
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
...invokeableTransport.connect ? { async connect(onMessage) {
|
|
361
|
-
if (isConnected) return;
|
|
362
|
-
if (connectingPromise) {
|
|
363
|
-
await connectingPromise;
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
const maybePromise = invokeableTransport.connect({
|
|
367
|
-
onMessage: onMessage ?? (() => {}),
|
|
368
|
-
onDisconnection() {
|
|
369
|
-
isConnected = false;
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
if (maybePromise) {
|
|
373
|
-
connectingPromise = maybePromise;
|
|
374
|
-
await connectingPromise;
|
|
375
|
-
connectingPromise = void 0;
|
|
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;
|
|
376
604
|
}
|
|
377
|
-
|
|
378
|
-
} } : {},
|
|
379
|
-
...invokeableTransport.disconnect ? { async disconnect() {
|
|
380
|
-
if (!isConnected) return;
|
|
381
|
-
if (connectingPromise) await connectingPromise;
|
|
382
|
-
isConnected = false;
|
|
383
|
-
await invokeableTransport.disconnect();
|
|
384
|
-
} } : {},
|
|
385
|
-
async send(data) {
|
|
386
|
-
if (!invokeableTransport.send) return;
|
|
387
|
-
if (!isConnected) if (connectingPromise) await connectingPromise;
|
|
388
|
-
else throw new SendBeforeConnectError("send was called before connect");
|
|
389
|
-
await invokeableTransport.send(data);
|
|
390
|
-
},
|
|
391
|
-
async invoke(name, data) {
|
|
392
|
-
if (!isConnected) if (connectingPromise) await connectingPromise;
|
|
393
|
-
else throw new SendBeforeConnectError("invoke was called before connect");
|
|
394
|
-
return invokeableTransport.invoke(name, data);
|
|
395
|
-
}
|
|
396
|
-
};
|
|
397
|
-
};
|
|
398
|
-
var SendBeforeConnectError = class extends Error {
|
|
399
|
-
constructor(message) {
|
|
400
|
-
super(message);
|
|
401
|
-
this.name = "SendBeforeConnectError";
|
|
605
|
+
};
|
|
402
606
|
}
|
|
403
607
|
};
|
|
404
|
-
const createWebSocketModuleRunnerTransport = (options) => {
|
|
405
|
-
const pingInterval = options.pingInterval ?? 3e4;
|
|
406
|
-
let ws;
|
|
407
|
-
let pingIntervalId;
|
|
408
|
-
return {
|
|
409
|
-
async connect({ onMessage, onDisconnection }) {
|
|
410
|
-
const socket = options.createConnection();
|
|
411
|
-
socket.addEventListener("message", ({ data }) => {
|
|
412
|
-
onMessage(JSON.parse(data));
|
|
413
|
-
});
|
|
414
|
-
let isOpened = socket.readyState === socket.OPEN;
|
|
415
|
-
if (!isOpened) await new Promise((resolve, reject) => {
|
|
416
|
-
socket.addEventListener("open", () => {
|
|
417
|
-
isOpened = true;
|
|
418
|
-
resolve();
|
|
419
|
-
}, { once: true });
|
|
420
|
-
socket.addEventListener("close", () => {
|
|
421
|
-
if (!isOpened) {
|
|
422
|
-
reject(/* @__PURE__ */ new Error("WebSocket closed without opened."));
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
onMessage({
|
|
426
|
-
type: "custom",
|
|
427
|
-
event: "vite:ws:disconnect",
|
|
428
|
-
data: { webSocket: socket }
|
|
429
|
-
});
|
|
430
|
-
onDisconnection();
|
|
431
|
-
});
|
|
432
|
-
});
|
|
433
|
-
onMessage({
|
|
434
|
-
type: "custom",
|
|
435
|
-
event: "vite:ws:connect",
|
|
436
|
-
data: { webSocket: socket }
|
|
437
|
-
});
|
|
438
|
-
ws = socket;
|
|
439
|
-
pingIntervalId = setInterval(() => {
|
|
440
|
-
if (socket.readyState === socket.OPEN) socket.send(JSON.stringify({ type: "ping" }));
|
|
441
|
-
}, pingInterval);
|
|
442
|
-
},
|
|
443
|
-
disconnect() {
|
|
444
|
-
clearInterval(pingIntervalId);
|
|
445
|
-
ws?.close();
|
|
446
|
-
},
|
|
447
|
-
send(data) {
|
|
448
|
-
ws.send(JSON.stringify(data));
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
};
|
|
452
608
|
//#endregion
|
|
453
609
|
//#region src/shared/hmrHandler.ts
|
|
454
610
|
function createHMRHandler(handler) {
|
|
@@ -483,134 +639,6 @@ var Queue = class {
|
|
|
483
639
|
}
|
|
484
640
|
};
|
|
485
641
|
//#endregion
|
|
486
|
-
//#region src/shared/forwardConsole.ts
|
|
487
|
-
function setupForwardConsoleHandler(transport, options, console = globalThis.console) {
|
|
488
|
-
if (!options.enabled) return;
|
|
489
|
-
async function sendError(type, error) {
|
|
490
|
-
await transport.send({
|
|
491
|
-
type: "custom",
|
|
492
|
-
event: "vite:forward-console",
|
|
493
|
-
data: {
|
|
494
|
-
type,
|
|
495
|
-
data: {
|
|
496
|
-
name: error?.name || "Unknown Error",
|
|
497
|
-
message: error?.message || String(error),
|
|
498
|
-
stack: error?.stack
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
async function sendLog(level, args) {
|
|
504
|
-
try {
|
|
505
|
-
await transport.send({
|
|
506
|
-
type: "custom",
|
|
507
|
-
event: "vite:forward-console",
|
|
508
|
-
data: {
|
|
509
|
-
type: "log",
|
|
510
|
-
data: {
|
|
511
|
-
level,
|
|
512
|
-
message: formatConsoleArgs(args)
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
} catch (err) {
|
|
517
|
-
try {
|
|
518
|
-
await sendError("unhandled-rejection", err);
|
|
519
|
-
} catch (err) {
|
|
520
|
-
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
const originalConsoleError = console.error;
|
|
525
|
-
for (const level of options.logLevels) {
|
|
526
|
-
const original = console[level];
|
|
527
|
-
if (typeof original !== "function") continue;
|
|
528
|
-
console[level] = (...args) => {
|
|
529
|
-
original(...args);
|
|
530
|
-
sendLog(level, args);
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
if (options.unhandledErrors && typeof window !== "undefined") {
|
|
534
|
-
window.addEventListener("error", async (event) => {
|
|
535
|
-
const error = event.error ?? (event.message ? new Error(event.message) : event);
|
|
536
|
-
try {
|
|
537
|
-
await sendError("error", error);
|
|
538
|
-
} catch (err) {
|
|
539
|
-
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
540
|
-
}
|
|
541
|
-
});
|
|
542
|
-
window.addEventListener("unhandledrejection", async (event) => {
|
|
543
|
-
try {
|
|
544
|
-
await sendError("unhandled-rejection", event.reason);
|
|
545
|
-
} catch (err) {
|
|
546
|
-
if (!(err instanceof SendBeforeConnectError)) originalConsoleError("Failed to send error to Vite server:", err);
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
function formatConsoleArgs(args) {
|
|
552
|
-
if (args.length === 0) return "";
|
|
553
|
-
if (typeof args[0] !== "string") return args.map((arg) => stringifyConsoleArg(arg)).join(" ");
|
|
554
|
-
const len = args.length;
|
|
555
|
-
let i = 1;
|
|
556
|
-
let message = args[0].replace(/%[sdjifoOc%]/g, (specifier) => {
|
|
557
|
-
if (specifier === "%%") return "%";
|
|
558
|
-
if (i >= len) return specifier;
|
|
559
|
-
const arg = args[i++];
|
|
560
|
-
switch (specifier) {
|
|
561
|
-
case "%s":
|
|
562
|
-
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
563
|
-
return typeof arg === "object" && arg != null ? stringifyConsoleArg(arg) : String(arg);
|
|
564
|
-
case "%d":
|
|
565
|
-
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
566
|
-
if (typeof arg === "symbol") return "NaN";
|
|
567
|
-
return Number(arg).toString();
|
|
568
|
-
case "%i":
|
|
569
|
-
if (typeof arg === "bigint") return `${arg.toString()}n`;
|
|
570
|
-
return Number.parseInt(String(arg), 10).toString();
|
|
571
|
-
case "%f": return Number.parseFloat(String(arg)).toString();
|
|
572
|
-
case "%o":
|
|
573
|
-
case "%O": return stringifyConsoleArg(arg);
|
|
574
|
-
case "%j": try {
|
|
575
|
-
return JSON.stringify(arg) ?? "undefined";
|
|
576
|
-
} catch {
|
|
577
|
-
return "[Circular]";
|
|
578
|
-
}
|
|
579
|
-
case "%c": return "";
|
|
580
|
-
default: return specifier;
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
for (let arg = args[i]; i < len; arg = args[++i]) if (arg == null || typeof arg !== "object") message += ` ${typeof arg === "symbol" ? arg.toString() : String(arg)}`;
|
|
584
|
-
else message += ` ${stringifyConsoleArg(arg)}`;
|
|
585
|
-
return message;
|
|
586
|
-
}
|
|
587
|
-
function stringifyConsoleArg(value) {
|
|
588
|
-
if (typeof value === "string") return value;
|
|
589
|
-
if (typeof value === "number" || typeof value === "boolean" || typeof value === "undefined") return String(value);
|
|
590
|
-
if (typeof value === "symbol") return value.toString();
|
|
591
|
-
if (typeof value === "function") return value.name ? `[Function: ${value.name}]` : "[Function]";
|
|
592
|
-
if (value instanceof Error) return value.stack || `${value.name}: ${value.message}`;
|
|
593
|
-
if (typeof value === "bigint") return `${value}n`;
|
|
594
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
595
|
-
try {
|
|
596
|
-
return JSON.stringify(value, (_, nested) => {
|
|
597
|
-
if (typeof nested === "bigint") return `${nested}n`;
|
|
598
|
-
if (nested instanceof Error) return {
|
|
599
|
-
name: nested.name,
|
|
600
|
-
message: nested.message,
|
|
601
|
-
stack: nested.stack
|
|
602
|
-
};
|
|
603
|
-
if (nested && typeof nested === "object") {
|
|
604
|
-
if (seen.has(nested)) return "[Circular]";
|
|
605
|
-
seen.add(nested);
|
|
606
|
-
}
|
|
607
|
-
return nested;
|
|
608
|
-
}) ?? String(value);
|
|
609
|
-
} catch {
|
|
610
|
-
return String(value);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
//#endregion
|
|
614
642
|
//#region src/client/overlay.ts
|
|
615
643
|
const hmrConfigName = __HMR_CONFIG_NAME__;
|
|
616
644
|
const base$1 = __BASE__ || "/";
|
|
@@ -928,14 +956,18 @@ const debounceReload = (time) => {
|
|
|
928
956
|
};
|
|
929
957
|
};
|
|
930
958
|
const pageReload = debounceReload(20);
|
|
959
|
+
function wrapIdIfNeeded(id) {
|
|
960
|
+
return id[0] === "." || id[0] === "/" ? id : wrapId(id);
|
|
961
|
+
}
|
|
931
962
|
const hmrClient = new HMRClient({
|
|
932
963
|
error: (err) => console.error("[vite]", err),
|
|
933
964
|
debug: (...msg) => console.debug("[vite]", ...msg)
|
|
934
965
|
}, transport, async function importUpdatedModule({ acceptedPath, timestamp, explicitImportRequired, isWithinCircularImport }) {
|
|
935
966
|
const [acceptedPathWithoutQuery, query] = acceptedPath.split(`?`);
|
|
967
|
+
const browserPath = wrapIdIfNeeded(acceptedPathWithoutQuery);
|
|
936
968
|
const importPromise = import(
|
|
937
969
|
/* @vite-ignore */
|
|
938
|
-
base +
|
|
970
|
+
base + browserPath.slice(1) + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`
|
|
939
971
|
);
|
|
940
972
|
if (isWithinCircularImport) importPromise.catch(() => {
|
|
941
973
|
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.`);
|
|
@@ -1008,12 +1040,14 @@ async function handleMessage(payload) {
|
|
|
1008
1040
|
case "full-reload":
|
|
1009
1041
|
if (payload.ifFallback && !globalThis.__vite_is_fallback_page__) break;
|
|
1010
1042
|
await activeHmrClient.notifyListeners("vite:beforeFullReload", payload);
|
|
1011
|
-
if (hasDocument)
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1043
|
+
if (hasDocument) {
|
|
1044
|
+
if (payload.path && payload.path.endsWith(".html")) {
|
|
1045
|
+
const pagePath = decodeURI(location.pathname);
|
|
1046
|
+
const payloadPath = base + payload.path.slice(1);
|
|
1047
|
+
if (pagePath === payloadPath || payload.path === "/index.html" || pagePath.endsWith("/") && pagePath + "index.html" === payloadPath) pageReload();
|
|
1048
|
+
return;
|
|
1049
|
+
} else pageReload();
|
|
1050
|
+
}
|
|
1017
1051
|
break;
|
|
1018
1052
|
case "prune":
|
|
1019
1053
|
await activeHmrClient.notifyListeners("vite:beforePrune", payload);
|