vite 5.1.4 → 5.1.5
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/dist/node/chunks/{dep-jDlpJiMN.js → dep-G-px366b.js} +250 -220
- package/dist/node/chunks/{dep-wALyWXZB.js → dep-OHeF5w5D.js} +1 -1
- package/dist/node/chunks/{dep-g6LmopN4.js → dep-WMYkPWs9.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -17
- package/dist/node/index.d.ts +3 -2
- package/dist/node/index.js +3 -3
- package/dist/node/runtime.d.ts +54 -3
- package/dist/node/runtime.js +928 -1524
- package/dist/node/{types.d-jgA8ss1A.d.ts → types.d-AKzkD8vd.d.ts} +6 -52
- package/dist/node-cjs/publicUtils.cjs +44 -60
- package/package.json +7 -5
- package/types/hmrPayload.d.ts +2 -0
package/dist/node/runtime.js
CHANGED
@@ -1,1617 +1,1021 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
constructor(hmrClient, ownerPath) {
|
6
|
-
this.hmrClient = hmrClient;
|
7
|
-
this.ownerPath = ownerPath;
|
8
|
-
if (!hmrClient.dataMap.has(ownerPath)) {
|
9
|
-
hmrClient.dataMap.set(ownerPath, {});
|
10
|
-
}
|
11
|
-
// when a file is hot updated, a new context is created
|
12
|
-
// clear its stale callbacks
|
13
|
-
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
14
|
-
if (mod) {
|
15
|
-
mod.callbacks = [];
|
16
|
-
}
|
17
|
-
// clear stale custom event listeners
|
18
|
-
const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
|
19
|
-
if (staleListeners) {
|
20
|
-
for (const [event, staleFns] of staleListeners) {
|
21
|
-
const listeners = hmrClient.customListenersMap.get(event);
|
22
|
-
if (listeners) {
|
23
|
-
hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
this.newListeners = new Map();
|
28
|
-
hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
29
|
-
}
|
30
|
-
get data() {
|
31
|
-
return this.hmrClient.dataMap.get(this.ownerPath);
|
32
|
-
}
|
33
|
-
accept(deps, callback) {
|
34
|
-
if (typeof deps === 'function' || !deps) {
|
35
|
-
// self-accept: hot.accept(() => {})
|
36
|
-
this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
|
37
|
-
}
|
38
|
-
else if (typeof deps === 'string') {
|
39
|
-
// explicit deps
|
40
|
-
this.acceptDeps([deps], ([mod]) => callback?.(mod));
|
41
|
-
}
|
42
|
-
else if (Array.isArray(deps)) {
|
43
|
-
this.acceptDeps(deps, callback);
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
throw new Error(`invalid hot.accept() usage.`);
|
47
|
-
}
|
48
|
-
}
|
49
|
-
// export names (first arg) are irrelevant on the client side, they're
|
50
|
-
// extracted in the server for propagation
|
51
|
-
acceptExports(_, callback) {
|
52
|
-
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
|
53
|
-
}
|
54
|
-
dispose(cb) {
|
55
|
-
this.hmrClient.disposeMap.set(this.ownerPath, cb);
|
56
|
-
}
|
57
|
-
prune(cb) {
|
58
|
-
this.hmrClient.pruneMap.set(this.ownerPath, cb);
|
59
|
-
}
|
60
|
-
// Kept for backward compatibility (#11036)
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
62
|
-
decline() { }
|
63
|
-
invalidate(message) {
|
64
|
-
this.hmrClient.notifyListeners('vite:invalidate', {
|
65
|
-
path: this.ownerPath,
|
66
|
-
message,
|
67
|
-
});
|
68
|
-
this.send('vite:invalidate', { path: this.ownerPath, message });
|
69
|
-
this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ''}`);
|
70
|
-
}
|
71
|
-
on(event, cb) {
|
72
|
-
const addToMap = (map) => {
|
73
|
-
const existing = map.get(event) || [];
|
74
|
-
existing.push(cb);
|
75
|
-
map.set(event, existing);
|
76
|
-
};
|
77
|
-
addToMap(this.hmrClient.customListenersMap);
|
78
|
-
addToMap(this.newListeners);
|
79
|
-
}
|
80
|
-
off(event, cb) {
|
81
|
-
const removeFromMap = (map) => {
|
82
|
-
const existing = map.get(event);
|
83
|
-
if (existing === undefined) {
|
84
|
-
return;
|
85
|
-
}
|
86
|
-
const pruned = existing.filter((l) => l !== cb);
|
87
|
-
if (pruned.length === 0) {
|
88
|
-
map.delete(event);
|
89
|
-
return;
|
90
|
-
}
|
91
|
-
map.set(event, pruned);
|
92
|
-
};
|
93
|
-
removeFromMap(this.hmrClient.customListenersMap);
|
94
|
-
removeFromMap(this.newListeners);
|
95
|
-
}
|
96
|
-
send(event, data) {
|
97
|
-
this.hmrClient.messenger.send(JSON.stringify({ type: 'custom', event, data }));
|
98
|
-
}
|
99
|
-
acceptDeps(deps, callback = () => { }) {
|
100
|
-
const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
101
|
-
id: this.ownerPath,
|
102
|
-
callbacks: [],
|
103
|
-
};
|
104
|
-
mod.callbacks.push({
|
105
|
-
deps,
|
106
|
-
fn: callback,
|
107
|
-
});
|
108
|
-
this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
class HMRMessenger {
|
112
|
-
connection;
|
113
|
-
constructor(connection) {
|
114
|
-
this.connection = connection;
|
115
|
-
}
|
116
|
-
queue = [];
|
117
|
-
send(message) {
|
118
|
-
this.queue.push(message);
|
119
|
-
this.flush();
|
120
|
-
}
|
121
|
-
flush() {
|
122
|
-
if (this.connection.isReady()) {
|
123
|
-
this.queue.forEach((msg) => this.connection.send(msg));
|
124
|
-
this.queue = [];
|
125
|
-
}
|
126
|
-
}
|
127
|
-
}
|
128
|
-
class HMRClient {
|
129
|
-
logger;
|
130
|
-
importUpdatedModule;
|
131
|
-
hotModulesMap = new Map();
|
132
|
-
disposeMap = new Map();
|
133
|
-
pruneMap = new Map();
|
134
|
-
dataMap = new Map();
|
135
|
-
customListenersMap = new Map();
|
136
|
-
ctxToListenersMap = new Map();
|
137
|
-
messenger;
|
138
|
-
constructor(logger, connection,
|
139
|
-
// This allows implementing reloading via different methods depending on the environment
|
140
|
-
importUpdatedModule) {
|
141
|
-
this.logger = logger;
|
142
|
-
this.importUpdatedModule = importUpdatedModule;
|
143
|
-
this.messenger = new HMRMessenger(connection);
|
144
|
-
}
|
145
|
-
async notifyListeners(event, data) {
|
146
|
-
const cbs = this.customListenersMap.get(event);
|
147
|
-
if (cbs) {
|
148
|
-
await Promise.allSettled(cbs.map((cb) => cb(data)));
|
149
|
-
}
|
150
|
-
}
|
151
|
-
clear() {
|
152
|
-
this.hotModulesMap.clear();
|
153
|
-
this.disposeMap.clear();
|
154
|
-
this.pruneMap.clear();
|
155
|
-
this.dataMap.clear();
|
156
|
-
this.customListenersMap.clear();
|
157
|
-
this.ctxToListenersMap.clear();
|
158
|
-
}
|
159
|
-
// After an HMR update, some modules are no longer imported on the page
|
160
|
-
// but they may have left behind side effects that need to be cleaned up
|
161
|
-
// (.e.g style injections)
|
162
|
-
// TODO Trigger their dispose callbacks.
|
163
|
-
prunePaths(paths) {
|
164
|
-
paths.forEach((path) => {
|
165
|
-
const fn = this.pruneMap.get(path);
|
166
|
-
if (fn) {
|
167
|
-
fn(this.dataMap.get(path));
|
168
|
-
}
|
169
|
-
});
|
170
|
-
}
|
171
|
-
warnFailedUpdate(err, path) {
|
172
|
-
if (!err.message.includes('fetch')) {
|
173
|
-
this.logger.error(err);
|
174
|
-
}
|
175
|
-
this.logger.error(`[hmr] Failed to reload ${path}. ` +
|
176
|
-
`This could be due to syntax errors or importing non-existent ` +
|
177
|
-
`modules. (see errors above)`);
|
178
|
-
}
|
179
|
-
updateQueue = [];
|
180
|
-
pendingUpdateQueue = false;
|
181
|
-
/**
|
182
|
-
* buffer multiple hot updates triggered by the same src change
|
183
|
-
* so that they are invoked in the same order they were sent.
|
184
|
-
* (otherwise the order may be inconsistent because of the http request round trip)
|
185
|
-
*/
|
186
|
-
async queueUpdate(payload) {
|
187
|
-
this.updateQueue.push(this.fetchUpdate(payload));
|
188
|
-
if (!this.pendingUpdateQueue) {
|
189
|
-
this.pendingUpdateQueue = true;
|
190
|
-
await Promise.resolve();
|
191
|
-
this.pendingUpdateQueue = false;
|
192
|
-
const loading = [...this.updateQueue];
|
193
|
-
this.updateQueue = [];
|
194
|
-
(await Promise.all(loading)).forEach((fn) => fn && fn());
|
195
|
-
}
|
196
|
-
}
|
197
|
-
async fetchUpdate(update) {
|
198
|
-
const { path, acceptedPath } = update;
|
199
|
-
const mod = this.hotModulesMap.get(path);
|
200
|
-
if (!mod) {
|
201
|
-
// In a code-splitting project,
|
202
|
-
// it is common that the hot-updating module is not loaded yet.
|
203
|
-
// https://github.com/vitejs/vite/issues/721
|
204
|
-
return;
|
205
|
-
}
|
206
|
-
let fetchedModule;
|
207
|
-
const isSelfUpdate = path === acceptedPath;
|
208
|
-
// determine the qualified callbacks before we re-import the modules
|
209
|
-
const qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
210
|
-
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
211
|
-
const disposer = this.disposeMap.get(acceptedPath);
|
212
|
-
if (disposer)
|
213
|
-
await disposer(this.dataMap.get(acceptedPath));
|
214
|
-
try {
|
215
|
-
fetchedModule = await this.importUpdatedModule(update);
|
216
|
-
}
|
217
|
-
catch (e) {
|
218
|
-
this.warnFailedUpdate(e, acceptedPath);
|
219
|
-
}
|
220
|
-
}
|
221
|
-
return () => {
|
222
|
-
for (const { deps, fn } of qualifiedCallbacks) {
|
223
|
-
fn(deps.map((dep) => (dep === acceptedPath ? fetchedModule : undefined)));
|
224
|
-
}
|
225
|
-
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
226
|
-
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
227
|
-
};
|
228
|
-
}
|
229
|
-
}
|
230
|
-
|
231
|
-
const isWindows = typeof process !== 'undefined' && process.platform === 'win32';
|
232
|
-
const decodeBase64 = typeof atob !== 'undefined'
|
233
|
-
? atob
|
234
|
-
: (str) => Buffer.from(str, 'base64').toString('utf-8');
|
235
|
-
// currently we copy this from '../../constants' - maybe we can inline it somewhow?
|
236
|
-
const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
237
|
-
const VALID_ID_PREFIX = `/@id/`;
|
1
|
+
const VALID_ID_PREFIX = "/@id/", NULL_BYTE_PLACEHOLDER = "__x00__";
|
2
|
+
let SOURCEMAPPING_URL = "sourceMa";
|
3
|
+
SOURCEMAPPING_URL += "ppingURL";
|
4
|
+
const VITE_RUNTIME_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`, isWindows = typeof process < "u" && process.platform === "win32";
|
238
5
|
function wrapId(id) {
|
239
|
-
|
240
|
-
? id
|
241
|
-
: VALID_ID_PREFIX + id.replace('\0', NULL_BYTE_PLACEHOLDER);
|
6
|
+
return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
242
7
|
}
|
243
8
|
function unwrapId(id) {
|
244
|
-
|
245
|
-
? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, '\0')
|
246
|
-
: id;
|
247
|
-
}
|
248
|
-
const windowsSlashRE = /\\/g;
|
249
|
-
function slash(p) {
|
250
|
-
return p.replace(windowsSlashRE, '/');
|
9
|
+
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
|
251
10
|
}
|
252
11
|
const postfixRE = /[?#].*$/;
|
253
12
|
function cleanUrl(url) {
|
254
|
-
|
13
|
+
return url.replace(postfixRE, "");
|
255
14
|
}
|
256
15
|
function isPrimitive(value) {
|
257
|
-
|
16
|
+
return !value || typeof value != "object" && typeof value != "function";
|
258
17
|
}
|
259
|
-
|
260
|
-
|
261
|
-
const percentRegEx = /%/g;
|
262
|
-
const backslashRegEx = /\\/g;
|
263
|
-
const newlineRegEx = /\n/g;
|
264
|
-
const carriageReturnRegEx = /\r/g;
|
265
|
-
const tabRegEx = /\t/g;
|
266
|
-
const questionRegex = /\?/g;
|
267
|
-
const hashRegex = /#/g;
|
268
|
-
function encodePathChars(filepath) {
|
269
|
-
if (filepath.indexOf('%') !== -1)
|
270
|
-
filepath = filepath.replace(percentRegEx, '%25');
|
271
|
-
// In posix, backslash is a valid character in paths:
|
272
|
-
if (!isWindows && filepath.indexOf('\\') !== -1)
|
273
|
-
filepath = filepath.replace(backslashRegEx, '%5C');
|
274
|
-
if (filepath.indexOf('\n') !== -1)
|
275
|
-
filepath = filepath.replace(newlineRegEx, '%0A');
|
276
|
-
if (filepath.indexOf('\r') !== -1)
|
277
|
-
filepath = filepath.replace(carriageReturnRegEx, '%0D');
|
278
|
-
if (filepath.indexOf('\t') !== -1)
|
279
|
-
filepath = filepath.replace(tabRegEx, '%09');
|
280
|
-
return filepath;
|
281
|
-
}
|
282
|
-
function posixPathToFileHref(posixPath) {
|
283
|
-
let resolved = posixResolve(posixPath);
|
284
|
-
// path.resolve strips trailing slashes so we must add them back
|
285
|
-
const filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
286
|
-
if ((filePathLast === CHAR_FORWARD_SLASH ||
|
287
|
-
(isWindows && filePathLast === CHAR_BACKWARD_SLASH)) &&
|
288
|
-
resolved[resolved.length - 1] !== '/')
|
289
|
-
resolved += '/';
|
290
|
-
// Call encodePathChars first to avoid encoding % again for ? and #.
|
291
|
-
resolved = encodePathChars(resolved);
|
292
|
-
// Question and hash character should be included in pathname.
|
293
|
-
// Therefore, encoding is required to eliminate parsing them in different states.
|
294
|
-
// This is done as an optimization to not creating a URL instance and
|
295
|
-
// later triggering pathname setter, which impacts performance
|
296
|
-
if (resolved.indexOf('?') !== -1)
|
297
|
-
resolved = resolved.replace(questionRegex, '%3F');
|
298
|
-
if (resolved.indexOf('#') !== -1)
|
299
|
-
resolved = resolved.replace(hashRegex, '%23');
|
300
|
-
return new URL(`file://${resolved}`).href;
|
301
|
-
}
|
302
|
-
function posixDirname(filepath) {
|
303
|
-
const normalizedPath = filepath.endsWith('/')
|
304
|
-
? filepath.substring(0, filepath.length - 1)
|
305
|
-
: filepath;
|
306
|
-
return normalizedPath.substring(0, normalizedPath.lastIndexOf('/')) || '/';
|
18
|
+
function withTrailingSlash(path) {
|
19
|
+
return path[path.length - 1] !== "/" ? `${path}/` : path;
|
307
20
|
}
|
308
|
-
|
309
|
-
|
21
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
22
|
+
function normalizeWindowsPath(input = "") {
|
23
|
+
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
310
24
|
}
|
311
|
-
|
25
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
|
312
26
|
function cwd() {
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
const path = index >= 0 ? segments[index] : cwd();
|
325
|
-
// Skip empty entries
|
326
|
-
if (!path || path.length === 0) {
|
327
|
-
continue;
|
328
|
-
}
|
329
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
330
|
-
resolvedAbsolute = isAbsolute(path);
|
331
|
-
}
|
332
|
-
// At this point the path should be resolved to a full absolute path, but
|
333
|
-
// handle relative paths to be safe (might happen when process.cwd() fails)
|
334
|
-
// Normalize the path
|
335
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
336
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
337
|
-
return `/${resolvedPath}`;
|
338
|
-
}
|
339
|
-
return resolvedPath.length > 0 ? resolvedPath : '.';
|
340
|
-
}
|
341
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
342
|
-
function isAbsolute(p) {
|
343
|
-
return _IS_ABSOLUTE_RE.test(p);
|
344
|
-
}
|
345
|
-
// Resolves . and .. elements in a path with directory names
|
27
|
+
return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
|
28
|
+
}
|
29
|
+
const resolve = function(...arguments_) {
|
30
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
31
|
+
let resolvedPath = "", resolvedAbsolute = !1;
|
32
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
33
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
34
|
+
!path || path.length === 0 || (resolvedPath = `${path}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path));
|
35
|
+
}
|
36
|
+
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
37
|
+
};
|
346
38
|
function normalizeString(path, allowAboveRoot) {
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
else if (
|
365
|
-
|
366
|
-
|
367
|
-
res[res.length - 1] !== '.' ||
|
368
|
-
res[res.length - 2] !== '.') {
|
369
|
-
if (res.length > 2) {
|
370
|
-
const lastSlashIndex = res.lastIndexOf('/');
|
371
|
-
if (lastSlashIndex === -1) {
|
372
|
-
res = '';
|
373
|
-
lastSegmentLength = 0;
|
374
|
-
}
|
375
|
-
else {
|
376
|
-
res = res.slice(0, lastSlashIndex);
|
377
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
|
378
|
-
}
|
379
|
-
lastSlash = index;
|
380
|
-
dots = 0;
|
381
|
-
continue;
|
382
|
-
}
|
383
|
-
else if (res.length > 0) {
|
384
|
-
res = '';
|
385
|
-
lastSegmentLength = 0;
|
386
|
-
lastSlash = index;
|
387
|
-
dots = 0;
|
388
|
-
continue;
|
389
|
-
}
|
390
|
-
}
|
391
|
-
if (allowAboveRoot) {
|
392
|
-
res += res.length > 0 ? '/..' : '..';
|
393
|
-
lastSegmentLength = 2;
|
394
|
-
}
|
395
|
-
}
|
396
|
-
else {
|
397
|
-
if (res.length > 0) {
|
398
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
399
|
-
}
|
400
|
-
else {
|
401
|
-
res = path.slice(lastSlash + 1, index);
|
402
|
-
}
|
403
|
-
lastSegmentLength = index - lastSlash - 1;
|
39
|
+
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
40
|
+
for (let index = 0; index <= path.length; ++index) {
|
41
|
+
if (index < path.length)
|
42
|
+
char = path[index];
|
43
|
+
else {
|
44
|
+
if (char === "/")
|
45
|
+
break;
|
46
|
+
char = "/";
|
47
|
+
}
|
48
|
+
if (char === "/") {
|
49
|
+
if (!(lastSlash === index - 1 || dots === 1))
|
50
|
+
if (dots === 2) {
|
51
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
52
|
+
if (res.length > 2) {
|
53
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
54
|
+
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
55
|
+
continue;
|
56
|
+
} else if (res.length > 0) {
|
57
|
+
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
58
|
+
continue;
|
404
59
|
}
|
405
|
-
|
406
|
-
|
407
|
-
}
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
60
|
+
}
|
61
|
+
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
62
|
+
} else
|
63
|
+
res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
64
|
+
lastSlash = index, dots = 0;
|
65
|
+
} else
|
66
|
+
char === "." && dots !== -1 ? ++dots : dots = -1;
|
67
|
+
}
|
68
|
+
return res;
|
69
|
+
}
|
70
|
+
const isAbsolute = function(p) {
|
71
|
+
return _IS_ABSOLUTE_RE.test(p);
|
72
|
+
}, dirname = function(p) {
|
73
|
+
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
74
|
+
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
75
|
+
}, 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;
|
76
|
+
function encodePathChars(filepath) {
|
77
|
+
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(`
|
78
|
+
`) !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
416
79
|
}
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
_decodedMemo;
|
423
|
-
url;
|
424
|
-
version;
|
425
|
-
names = [];
|
426
|
-
resolvedSources;
|
427
|
-
constructor(map, from) {
|
428
|
-
this.map = map;
|
429
|
-
const { mappings, names, sources } = map;
|
430
|
-
this.version = map.version;
|
431
|
-
this.names = names || [];
|
432
|
-
this._encoded = mappings || '';
|
433
|
-
this._decodedMemo = memoizedState();
|
434
|
-
this.url = from;
|
435
|
-
this.resolvedSources = (sources || []).map((s) => posixResolve(s || '', from));
|
436
|
-
}
|
80
|
+
const posixDirname = dirname, posixResolve = resolve;
|
81
|
+
function posixPathToFileHref(posixPath) {
|
82
|
+
let resolved = posixResolve(posixPath);
|
83
|
+
const filePathLast = posixPath.charCodeAt(posixPath.length - 1);
|
84
|
+
return (filePathLast === CHAR_FORWARD_SLASH || isWindows && filePathLast === CHAR_BACKWARD_SLASH) && resolved[resolved.length - 1] !== "/" && (resolved += "/"), resolved = encodePathChars(resolved), resolved.indexOf("?") !== -1 && (resolved = resolved.replace(questionRegex, "%3F")), resolved.indexOf("#") !== -1 && (resolved = resolved.replace(hashRegex, "%23")), new URL(`file://${resolved}`).href;
|
437
85
|
}
|
438
|
-
|
439
|
-
|
440
|
-
const idx = mappings.indexOf(';', index);
|
441
|
-
return idx === -1 ? mappings.length : idx;
|
86
|
+
function toWindowsPath(path) {
|
87
|
+
return path.replace(/\//g, "\\");
|
442
88
|
}
|
443
|
-
const chars =
|
444
|
-
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
89
|
+
const comma = ",".charCodeAt(0), chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", intToChar = new Uint8Array(64), charToInt = new Uint8Array(128);
|
445
90
|
for (let i = 0; i < chars.length; i++) {
|
446
|
-
|
447
|
-
|
91
|
+
const c = chars.charCodeAt(i);
|
92
|
+
intToChar[i] = c, charToInt[c] = i;
|
93
|
+
}
|
94
|
+
function decode(mappings) {
|
95
|
+
const state = new Int32Array(5), decoded = [];
|
96
|
+
let index = 0;
|
97
|
+
do {
|
98
|
+
const semi = indexOf(mappings, index), line = [];
|
99
|
+
let sorted = !0, lastCol = 0;
|
100
|
+
state[0] = 0;
|
101
|
+
for (let i = index; i < semi; i++) {
|
102
|
+
let seg;
|
103
|
+
i = decodeInteger(mappings, i, state, 0);
|
104
|
+
const col = state[0];
|
105
|
+
col < lastCol && (sorted = !1), lastCol = col, hasMoreVlq(mappings, i, semi) ? (i = decodeInteger(mappings, i, state, 1), i = decodeInteger(mappings, i, state, 2), i = decodeInteger(mappings, i, state, 3), hasMoreVlq(mappings, i, semi) ? (i = decodeInteger(mappings, i, state, 4), seg = [col, state[1], state[2], state[3], state[4]]) : seg = [col, state[1], state[2], state[3]]) : seg = [col], line.push(seg);
|
106
|
+
}
|
107
|
+
sorted || sort(line), decoded.push(line), index = semi + 1;
|
108
|
+
} while (index <= mappings.length);
|
109
|
+
return decoded;
|
110
|
+
}
|
111
|
+
function indexOf(mappings, index) {
|
112
|
+
const idx = mappings.indexOf(";", index);
|
113
|
+
return idx === -1 ? mappings.length : idx;
|
448
114
|
}
|
449
115
|
function decodeInteger(mappings, pos, state, j) {
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
shift += 5;
|
458
|
-
} while (integer & 32);
|
459
|
-
const shouldNegate = value & 1;
|
460
|
-
value >>>= 1;
|
461
|
-
if (shouldNegate) {
|
462
|
-
value = -0x80000000 | -value;
|
463
|
-
}
|
464
|
-
state[j] += value;
|
465
|
-
return pos;
|
116
|
+
let value = 0, shift = 0, integer = 0;
|
117
|
+
do {
|
118
|
+
const c = mappings.charCodeAt(pos++);
|
119
|
+
integer = charToInt[c], value |= (integer & 31) << shift, shift += 5;
|
120
|
+
} while (integer & 32);
|
121
|
+
const shouldNegate = value & 1;
|
122
|
+
return value >>>= 1, shouldNegate && (value = -2147483648 | -value), state[j] += value, pos;
|
466
123
|
}
|
467
|
-
const comma = ','.charCodeAt(0);
|
468
124
|
function hasMoreVlq(mappings, i, length) {
|
469
|
-
|
470
|
-
return false;
|
471
|
-
return mappings.charCodeAt(i) !== comma;
|
472
|
-
}
|
473
|
-
function decode(mappings) {
|
474
|
-
const state = new Int32Array(5);
|
475
|
-
const decoded = [];
|
476
|
-
let index = 0;
|
477
|
-
do {
|
478
|
-
const semi = indexOf(mappings, index);
|
479
|
-
const line = [];
|
480
|
-
let sorted = true;
|
481
|
-
let lastCol = 0;
|
482
|
-
state[0] = 0;
|
483
|
-
for (let i = index; i < semi; i++) {
|
484
|
-
let seg;
|
485
|
-
i = decodeInteger(mappings, i, state, 0); // genColumn
|
486
|
-
const col = state[0];
|
487
|
-
if (col < lastCol)
|
488
|
-
sorted = false;
|
489
|
-
lastCol = col;
|
490
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
491
|
-
i = decodeInteger(mappings, i, state, 1); // sourcesIndex
|
492
|
-
i = decodeInteger(mappings, i, state, 2); // sourceLine
|
493
|
-
i = decodeInteger(mappings, i, state, 3); // sourceColumn
|
494
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
495
|
-
i = decodeInteger(mappings, i, state, 4); // namesIndex
|
496
|
-
seg = [col, state[1], state[2], state[3], state[4]];
|
497
|
-
}
|
498
|
-
else {
|
499
|
-
seg = [col, state[1], state[2], state[3]];
|
500
|
-
}
|
501
|
-
}
|
502
|
-
else {
|
503
|
-
seg = [col];
|
504
|
-
}
|
505
|
-
line.push(seg);
|
506
|
-
}
|
507
|
-
if (!sorted)
|
508
|
-
line.sort((a, b) => a[0] - b[0]);
|
509
|
-
decoded.push(line);
|
510
|
-
index = semi + 1;
|
511
|
-
} while (index <= mappings.length);
|
512
|
-
return decoded;
|
125
|
+
return i >= length ? !1 : mappings.charCodeAt(i) !== comma;
|
513
126
|
}
|
514
|
-
|
515
|
-
|
516
|
-
const COLUMN = 0;
|
517
|
-
const SOURCES_INDEX = 1;
|
518
|
-
const SOURCE_LINE = 2;
|
519
|
-
const SOURCE_COLUMN = 3;
|
520
|
-
const NAMES_INDEX = 4;
|
521
|
-
function OMapping(source, line, column, name) {
|
522
|
-
return { source, line, column, name };
|
127
|
+
function sort(line) {
|
128
|
+
line.sort(sortComparator);
|
523
129
|
}
|
524
|
-
function
|
525
|
-
|
130
|
+
function sortComparator(a, b) {
|
131
|
+
return a[0] - b[0];
|
526
132
|
}
|
527
|
-
|
133
|
+
const COLUMN = 0, SOURCES_INDEX = 1, SOURCE_LINE = 2, SOURCE_COLUMN = 3, NAMES_INDEX = 4;
|
134
|
+
let found = !1;
|
528
135
|
function binarySearch(haystack, needle, low, high) {
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
}
|
542
|
-
}
|
543
|
-
found = false;
|
544
|
-
return low - 1;
|
136
|
+
for (; low <= high; ) {
|
137
|
+
const mid = low + (high - low >> 1), cmp = haystack[mid][COLUMN] - needle;
|
138
|
+
if (cmp === 0)
|
139
|
+
return found = !0, mid;
|
140
|
+
cmp < 0 ? low = mid + 1 : high = mid - 1;
|
141
|
+
}
|
142
|
+
return found = !1, low - 1;
|
143
|
+
}
|
144
|
+
function upperBound(haystack, needle, index) {
|
145
|
+
for (let i = index + 1; i < haystack.length && haystack[i][COLUMN] === needle; index = i++)
|
146
|
+
;
|
147
|
+
return index;
|
545
148
|
}
|
546
|
-
function
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
149
|
+
function memoizedBinarySearch(haystack, needle, state, key) {
|
150
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
151
|
+
let low = 0, high = haystack.length - 1;
|
152
|
+
if (key === lastKey) {
|
153
|
+
if (needle === lastNeedle)
|
154
|
+
return found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle, lastIndex;
|
155
|
+
needle >= lastNeedle ? low = lastIndex === -1 ? 0 : lastIndex : high = lastIndex;
|
156
|
+
}
|
157
|
+
return state.lastKey = key, state.lastNeedle = needle, state.lastIndex = binarySearch(haystack, needle, low, high);
|
158
|
+
}
|
159
|
+
const LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)", COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
160
|
+
function cast(map) {
|
161
|
+
return map;
|
552
162
|
}
|
553
|
-
function
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
163
|
+
function decodedMappings(map) {
|
164
|
+
var _a;
|
165
|
+
return (_a = map)._decoded || (_a._decoded = decode(map._encoded));
|
166
|
+
}
|
167
|
+
function originalPositionFor(map, needle) {
|
168
|
+
let { line, column, bias } = needle;
|
169
|
+
if (line--, line < 0)
|
170
|
+
throw new Error(LINE_GTR_ZERO);
|
171
|
+
if (column < 0)
|
172
|
+
throw new Error(COL_GTR_EQ_ZERO);
|
173
|
+
const decoded = decodedMappings(map);
|
174
|
+
if (line >= decoded.length)
|
175
|
+
return OMapping(null, null, null, null);
|
176
|
+
const segments = decoded[line], index = traceSegmentInternal(segments, map._decodedMemo, line, column);
|
177
|
+
if (index === -1)
|
178
|
+
return OMapping(null, null, null, null);
|
179
|
+
const segment = segments[index];
|
180
|
+
if (segment.length === 1)
|
181
|
+
return OMapping(null, null, null, null);
|
182
|
+
const { names, resolvedSources } = map;
|
183
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
559
184
|
}
|
560
|
-
function
|
561
|
-
|
562
|
-
let low = 0;
|
563
|
-
let high = haystack.length - 1;
|
564
|
-
if (key === lastKey) {
|
565
|
-
if (needle === lastNeedle) {
|
566
|
-
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
567
|
-
return lastIndex;
|
568
|
-
}
|
569
|
-
if (needle >= lastNeedle) {
|
570
|
-
// lastIndex may be -1 if the previous needle was not found.
|
571
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
572
|
-
}
|
573
|
-
else {
|
574
|
-
high = lastIndex;
|
575
|
-
}
|
576
|
-
}
|
577
|
-
state.lastKey = key;
|
578
|
-
state.lastNeedle = needle;
|
579
|
-
return (state.lastIndex = binarySearch(haystack, needle, low, high));
|
185
|
+
function OMapping(source, line, column, name) {
|
186
|
+
return { source, line, column, name };
|
580
187
|
}
|
581
|
-
function traceSegmentInternal(segments, memo, line, column) {
|
582
|
-
|
583
|
-
|
584
|
-
index = lowerBound(segments, column, index);
|
585
|
-
}
|
586
|
-
if (index === -1 || index === segments.length)
|
587
|
-
return -1;
|
588
|
-
return index;
|
188
|
+
function traceSegmentInternal(segments, memo, line, column, bias) {
|
189
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
190
|
+
return found ? index = upperBound(segments, column, index) : index++, index === -1 || index === segments.length ? -1 : index;
|
589
191
|
}
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
192
|
+
class DecodedMap {
|
193
|
+
map;
|
194
|
+
_encoded;
|
195
|
+
_decoded;
|
196
|
+
_decodedMemo;
|
197
|
+
url;
|
198
|
+
version;
|
199
|
+
names = [];
|
200
|
+
resolvedSources;
|
201
|
+
constructor(map, from) {
|
202
|
+
this.map = map;
|
203
|
+
const { mappings, names, sources } = map;
|
204
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
205
|
+
}
|
206
|
+
}
|
207
|
+
function memoizedState() {
|
208
|
+
return {
|
209
|
+
lastKey: -1,
|
210
|
+
lastNeedle: -1,
|
211
|
+
lastIndex: -1
|
212
|
+
};
|
213
|
+
}
|
214
|
+
function getOriginalPosition(map, needle) {
|
215
|
+
const result = originalPositionFor(map, needle);
|
216
|
+
return result.column == null ? null : result;
|
611
217
|
}
|
612
|
-
|
613
|
-
let SOURCEMAPPING_URL = 'sourceMa';
|
614
|
-
SOURCEMAPPING_URL += 'ppingURL';
|
615
|
-
const VITE_RUNTIME_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
616
218
|
const VITE_RUNTIME_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_RUNTIME_SOURCEMAPPING_URL};base64,(.+)`);
|
617
219
|
class ModuleCacheMap extends Map {
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
get(
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
220
|
+
root;
|
221
|
+
constructor(root, entries) {
|
222
|
+
super(entries), this.root = withTrailingSlash(root);
|
223
|
+
}
|
224
|
+
normalize(fsPath) {
|
225
|
+
return normalizeModuleId(fsPath, this.root);
|
226
|
+
}
|
227
|
+
/**
|
228
|
+
* Assign partial data to the map
|
229
|
+
*/
|
230
|
+
update(fsPath, mod) {
|
231
|
+
return fsPath = this.normalize(fsPath), super.has(fsPath) ? Object.assign(super.get(fsPath), mod) : this.setByModuleId(fsPath, mod), this;
|
232
|
+
}
|
233
|
+
setByModuleId(modulePath, mod) {
|
234
|
+
return super.set(modulePath, mod);
|
235
|
+
}
|
236
|
+
set(fsPath, mod) {
|
237
|
+
return this.setByModuleId(this.normalize(fsPath), mod);
|
238
|
+
}
|
239
|
+
getByModuleId(modulePath) {
|
240
|
+
super.has(modulePath) || this.setByModuleId(modulePath, {});
|
241
|
+
const mod = super.get(modulePath);
|
242
|
+
return mod.imports || Object.assign(mod, {
|
243
|
+
imports: /* @__PURE__ */ new Set(),
|
244
|
+
importers: /* @__PURE__ */ new Set()
|
245
|
+
}), mod;
|
246
|
+
}
|
247
|
+
get(fsPath) {
|
248
|
+
return this.getByModuleId(this.normalize(fsPath));
|
249
|
+
}
|
250
|
+
deleteByModuleId(modulePath) {
|
251
|
+
return super.delete(modulePath);
|
252
|
+
}
|
253
|
+
delete(fsPath) {
|
254
|
+
return this.deleteByModuleId(this.normalize(fsPath));
|
255
|
+
}
|
256
|
+
invalidate(id) {
|
257
|
+
const module = this.get(id);
|
258
|
+
module.evaluated = !1, module.meta = void 0, module.map = void 0, module.promise = void 0, module.exports = void 0, module.imports?.clear();
|
259
|
+
}
|
260
|
+
isImported({ importedId, importedBy }, seen = /* @__PURE__ */ new Set()) {
|
261
|
+
if (importedId = this.normalize(importedId), importedBy = this.normalize(importedBy), importedBy === importedId)
|
262
|
+
return !0;
|
263
|
+
if (seen.has(importedId))
|
264
|
+
return !1;
|
265
|
+
seen.add(importedId);
|
266
|
+
const importers = this.getByModuleId(importedId)?.importers;
|
267
|
+
if (!importers)
|
268
|
+
return !1;
|
269
|
+
if (importers.has(importedBy))
|
270
|
+
return !0;
|
271
|
+
for (const importer of importers)
|
272
|
+
if (this.isImported({
|
273
|
+
importedBy,
|
274
|
+
importedId: importer
|
275
|
+
}))
|
276
|
+
return !0;
|
277
|
+
return !1;
|
278
|
+
}
|
279
|
+
/**
|
280
|
+
* Invalidate modules that dependent on the given modules, up to the main entry
|
281
|
+
*/
|
282
|
+
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
283
|
+
for (const _id of ids) {
|
284
|
+
const id = this.normalize(_id);
|
285
|
+
if (invalidated.has(id))
|
286
|
+
continue;
|
287
|
+
invalidated.add(id);
|
288
|
+
const mod = super.get(id);
|
289
|
+
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), super.delete(id);
|
290
|
+
}
|
291
|
+
return invalidated;
|
292
|
+
}
|
293
|
+
/**
|
294
|
+
* Invalidate dependency modules of the given modules, down to the bottom-level dependencies
|
295
|
+
*/
|
296
|
+
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
297
|
+
for (const _id of ids) {
|
298
|
+
const id = this.normalize(_id);
|
299
|
+
if (invalidated.has(id))
|
300
|
+
continue;
|
301
|
+
invalidated.add(id);
|
302
|
+
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
303
|
+
subIds.length && this.invalidateSubDepTree(subIds, invalidated), super.delete(id);
|
304
|
+
}
|
305
|
+
return invalidated;
|
306
|
+
}
|
307
|
+
getSourceMap(moduleId) {
|
308
|
+
const mod = this.get(moduleId);
|
309
|
+
if (mod.map)
|
310
|
+
return mod.map;
|
311
|
+
if (!mod.meta || !("code" in mod.meta))
|
312
|
+
return null;
|
313
|
+
const mapString = mod.meta.code.match(VITE_RUNTIME_SOURCEMAPPING_REGEXP)?.[1];
|
314
|
+
if (!mapString)
|
315
|
+
return null;
|
316
|
+
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
317
|
+
return mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile), mod.map;
|
318
|
+
}
|
319
|
+
}
|
320
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
321
|
+
function normalizeModuleId(file, root) {
|
322
|
+
if (prefixedBuiltins.has(file))
|
323
|
+
return file;
|
324
|
+
let unixFile = file.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
325
|
+
return unixFile.startsWith(root) && (unixFile = unixFile.slice(root.length - 1)), unixFile.replace(/^file:\//, "/");
|
710
326
|
}
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
327
|
+
class HMRContext {
|
328
|
+
hmrClient;
|
329
|
+
ownerPath;
|
330
|
+
newListeners;
|
331
|
+
constructor(hmrClient, ownerPath) {
|
332
|
+
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
333
|
+
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
334
|
+
mod && (mod.callbacks = []);
|
335
|
+
const staleListeners = hmrClient.ctxToListenersMap.get(ownerPath);
|
336
|
+
if (staleListeners)
|
337
|
+
for (const [event, staleFns] of staleListeners) {
|
338
|
+
const listeners = hmrClient.customListenersMap.get(event);
|
339
|
+
listeners && hmrClient.customListenersMap.set(event, listeners.filter((l) => !staleFns.includes(l)));
|
340
|
+
}
|
341
|
+
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
342
|
+
}
|
343
|
+
get data() {
|
344
|
+
return this.hmrClient.dataMap.get(this.ownerPath);
|
345
|
+
}
|
346
|
+
accept(deps, callback) {
|
347
|
+
if (typeof deps == "function" || !deps)
|
348
|
+
this.acceptDeps([this.ownerPath], ([mod]) => deps?.(mod));
|
349
|
+
else if (typeof deps == "string")
|
350
|
+
this.acceptDeps([deps], ([mod]) => callback?.(mod));
|
351
|
+
else if (Array.isArray(deps))
|
352
|
+
this.acceptDeps(deps, callback);
|
353
|
+
else
|
354
|
+
throw new Error("invalid hot.accept() usage.");
|
355
|
+
}
|
356
|
+
// export names (first arg) are irrelevant on the client side, they're
|
357
|
+
// extracted in the server for propagation
|
358
|
+
acceptExports(_, callback) {
|
359
|
+
this.acceptDeps([this.ownerPath], ([mod]) => callback?.(mod));
|
360
|
+
}
|
361
|
+
dispose(cb) {
|
362
|
+
this.hmrClient.disposeMap.set(this.ownerPath, cb);
|
363
|
+
}
|
364
|
+
prune(cb) {
|
365
|
+
this.hmrClient.pruneMap.set(this.ownerPath, cb);
|
366
|
+
}
|
367
|
+
// Kept for backward compatibility (#11036)
|
368
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
369
|
+
decline() {
|
370
|
+
}
|
371
|
+
invalidate(message) {
|
372
|
+
this.hmrClient.notifyListeners("vite:invalidate", {
|
373
|
+
path: this.ownerPath,
|
374
|
+
message
|
375
|
+
}), this.send("vite:invalidate", { path: this.ownerPath, message }), this.hmrClient.logger.debug(`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`);
|
376
|
+
}
|
377
|
+
on(event, cb) {
|
378
|
+
const addToMap = (map) => {
|
379
|
+
const existing = map.get(event) || [];
|
380
|
+
existing.push(cb), map.set(event, existing);
|
381
|
+
};
|
382
|
+
addToMap(this.hmrClient.customListenersMap), addToMap(this.newListeners);
|
383
|
+
}
|
384
|
+
off(event, cb) {
|
385
|
+
const removeFromMap = (map) => {
|
386
|
+
const existing = map.get(event);
|
387
|
+
if (existing === void 0)
|
388
|
+
return;
|
389
|
+
const pruned = existing.filter((l) => l !== cb);
|
390
|
+
if (pruned.length === 0) {
|
391
|
+
map.delete(event);
|
392
|
+
return;
|
393
|
+
}
|
394
|
+
map.set(event, pruned);
|
395
|
+
};
|
396
|
+
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
397
|
+
}
|
398
|
+
send(event, data) {
|
399
|
+
this.hmrClient.messenger.send(JSON.stringify({ type: "custom", event, data }));
|
400
|
+
}
|
401
|
+
acceptDeps(deps, callback = () => {
|
402
|
+
}) {
|
403
|
+
const mod = this.hmrClient.hotModulesMap.get(this.ownerPath) || {
|
404
|
+
id: this.ownerPath,
|
405
|
+
callbacks: []
|
406
|
+
};
|
407
|
+
mod.callbacks.push({
|
408
|
+
deps,
|
409
|
+
fn: callback
|
410
|
+
}), this.hmrClient.hotModulesMap.set(this.ownerPath, mod);
|
411
|
+
}
|
716
412
|
}
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
// unix style, but Windows path still starts with the drive letter to check the root
|
730
|
-
let unixFile = file
|
731
|
-
.replace(/\\/g, '/')
|
732
|
-
.replace(/^\/@fs\//, isWindows ? '' : '/')
|
733
|
-
.replace(/^node:/, '')
|
734
|
-
.replace(/^\/+/, '/');
|
735
|
-
if (unixFile.startsWith(root)) {
|
736
|
-
// keep slash
|
737
|
-
unixFile = unixFile.slice(root.length - 1);
|
738
|
-
}
|
739
|
-
// if it's not in the root, keep it as a path, not a URL
|
740
|
-
return unixFile.replace(/^file:\//, '/');
|
413
|
+
class HMRMessenger {
|
414
|
+
connection;
|
415
|
+
constructor(connection) {
|
416
|
+
this.connection = connection;
|
417
|
+
}
|
418
|
+
queue = [];
|
419
|
+
send(message) {
|
420
|
+
this.queue.push(message), this.flush();
|
421
|
+
}
|
422
|
+
flush() {
|
423
|
+
this.connection.isReady() && (this.queue.forEach((msg) => this.connection.send(msg)), this.queue = []);
|
424
|
+
}
|
741
425
|
}
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
426
|
+
class HMRClient {
|
427
|
+
logger;
|
428
|
+
importUpdatedModule;
|
429
|
+
hotModulesMap = /* @__PURE__ */ new Map();
|
430
|
+
disposeMap = /* @__PURE__ */ new Map();
|
431
|
+
pruneMap = /* @__PURE__ */ new Map();
|
432
|
+
dataMap = /* @__PURE__ */ new Map();
|
433
|
+
customListenersMap = /* @__PURE__ */ new Map();
|
434
|
+
ctxToListenersMap = /* @__PURE__ */ new Map();
|
435
|
+
messenger;
|
436
|
+
constructor(logger, connection, importUpdatedModule) {
|
437
|
+
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
438
|
+
}
|
439
|
+
async notifyListeners(event, data) {
|
440
|
+
const cbs = this.customListenersMap.get(event);
|
441
|
+
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
442
|
+
}
|
443
|
+
clear() {
|
444
|
+
this.hotModulesMap.clear(), this.disposeMap.clear(), this.pruneMap.clear(), this.dataMap.clear(), this.customListenersMap.clear(), this.ctxToListenersMap.clear();
|
445
|
+
}
|
446
|
+
// After an HMR update, some modules are no longer imported on the page
|
447
|
+
// but they may have left behind side effects that need to be cleaned up
|
448
|
+
// (.e.g style injections)
|
449
|
+
// TODO Trigger their dispose callbacks.
|
450
|
+
prunePaths(paths) {
|
451
|
+
paths.forEach((path) => {
|
452
|
+
const fn = this.pruneMap.get(path);
|
453
|
+
fn && fn(this.dataMap.get(path));
|
454
|
+
});
|
455
|
+
}
|
456
|
+
warnFailedUpdate(err, path) {
|
457
|
+
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)`);
|
458
|
+
}
|
459
|
+
updateQueue = [];
|
460
|
+
pendingUpdateQueue = !1;
|
461
|
+
/**
|
462
|
+
* buffer multiple hot updates triggered by the same src change
|
463
|
+
* so that they are invoked in the same order they were sent.
|
464
|
+
* (otherwise the order may be inconsistent because of the http request round trip)
|
465
|
+
*/
|
466
|
+
async queueUpdate(payload) {
|
467
|
+
if (this.updateQueue.push(this.fetchUpdate(payload)), !this.pendingUpdateQueue) {
|
468
|
+
this.pendingUpdateQueue = !0, await Promise.resolve(), this.pendingUpdateQueue = !1;
|
469
|
+
const loading = [...this.updateQueue];
|
470
|
+
this.updateQueue = [], (await Promise.all(loading)).forEach((fn) => fn && fn());
|
471
|
+
}
|
472
|
+
}
|
473
|
+
async fetchUpdate(update) {
|
474
|
+
const { path, acceptedPath } = update, mod = this.hotModulesMap.get(path);
|
475
|
+
if (!mod)
|
476
|
+
return;
|
477
|
+
let fetchedModule;
|
478
|
+
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(({ deps }) => deps.includes(acceptedPath));
|
479
|
+
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
480
|
+
const disposer = this.disposeMap.get(acceptedPath);
|
481
|
+
disposer && await disposer(this.dataMap.get(acceptedPath));
|
482
|
+
try {
|
483
|
+
fetchedModule = await this.importUpdatedModule(update);
|
484
|
+
} catch (e) {
|
485
|
+
this.warnFailedUpdate(e, acceptedPath);
|
486
|
+
}
|
487
|
+
}
|
488
|
+
return () => {
|
489
|
+
for (const { deps, fn } of qualifiedCallbacks)
|
490
|
+
fn(deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0));
|
491
|
+
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
492
|
+
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
493
|
+
};
|
494
|
+
}
|
495
|
+
}
|
496
|
+
const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
|
497
|
+
}, silentConsole = {
|
498
|
+
debug: noop,
|
499
|
+
error: noop
|
754
500
|
};
|
755
|
-
|
756
|
-
// updates to HMR should go one after another. It is possible to trigger another update during the invalidation for example.
|
757
501
|
function createHMRHandler(runtime) {
|
758
|
-
|
759
|
-
|
502
|
+
const queue = new Queue();
|
503
|
+
return (payload) => queue.enqueue(() => handleHMRPayload(runtime, payload));
|
760
504
|
}
|
761
505
|
async function handleHMRPayload(runtime, payload) {
|
762
|
-
|
763
|
-
|
764
|
-
return;
|
506
|
+
const hmrClient = runtime.hmrClient;
|
507
|
+
if (!(!hmrClient || runtime.isDestroyed()))
|
765
508
|
switch (payload.type) {
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
const err = payload.err;
|
806
|
-
hmrClient.logger.error(`[vite] Internal Server Error\n${err.message}\n${err.stack}`);
|
807
|
-
break;
|
808
|
-
}
|
809
|
-
default: {
|
810
|
-
const check = payload;
|
811
|
-
return check;
|
812
|
-
}
|
509
|
+
case "connected":
|
510
|
+
hmrClient.logger.debug("[vite] connected."), hmrClient.messenger.flush();
|
511
|
+
break;
|
512
|
+
case "update":
|
513
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(payload.updates.map(async (update) => {
|
514
|
+
if (update.type === "js-update")
|
515
|
+
return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
516
|
+
hmrClient.logger.error("[vite] css hmr is not supported in runtime mode.");
|
517
|
+
})), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
518
|
+
break;
|
519
|
+
case "custom": {
|
520
|
+
await hmrClient.notifyListeners(payload.event, payload.data);
|
521
|
+
break;
|
522
|
+
}
|
523
|
+
case "full-reload": {
|
524
|
+
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? [...runtime.entrypoints].filter((entrypoint) => runtime.moduleCache.isImported({
|
525
|
+
importedId: triggeredBy,
|
526
|
+
importedBy: entrypoint
|
527
|
+
})) : [...runtime.entrypoints];
|
528
|
+
if (!clearEntrypoints.length)
|
529
|
+
break;
|
530
|
+
hmrClient.logger.debug("[vite] program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runtime.moduleCache.clear();
|
531
|
+
for (const id of clearEntrypoints)
|
532
|
+
await runtime.executeUrl(id);
|
533
|
+
break;
|
534
|
+
}
|
535
|
+
case "prune":
|
536
|
+
await hmrClient.notifyListeners("vite:beforePrune", payload), hmrClient.prunePaths(payload.paths);
|
537
|
+
break;
|
538
|
+
case "error": {
|
539
|
+
await hmrClient.notifyListeners("vite:error", payload);
|
540
|
+
const err = payload.err;
|
541
|
+
hmrClient.logger.error(`[vite] Internal Server Error
|
542
|
+
${err.message}
|
543
|
+
${err.stack}`);
|
544
|
+
break;
|
545
|
+
}
|
546
|
+
default:
|
547
|
+
return payload;
|
813
548
|
}
|
814
549
|
}
|
815
550
|
class Queue {
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
this.dequeue();
|
826
|
-
});
|
827
|
-
}
|
828
|
-
dequeue() {
|
829
|
-
if (this.pending) {
|
830
|
-
return false;
|
831
|
-
}
|
832
|
-
const item = this.queue.shift();
|
833
|
-
if (!item) {
|
834
|
-
return false;
|
835
|
-
}
|
836
|
-
this.pending = true;
|
837
|
-
item
|
838
|
-
.promise()
|
839
|
-
.then(item.resolve)
|
840
|
-
.catch(item.reject)
|
841
|
-
.finally(() => {
|
842
|
-
this.pending = false;
|
843
|
-
this.dequeue();
|
844
|
-
});
|
845
|
-
return true;
|
846
|
-
}
|
847
|
-
}
|
848
|
-
|
849
|
-
const sourceMapCache = {};
|
850
|
-
const fileContentsCache = {};
|
851
|
-
const moduleGraphs = new Set();
|
852
|
-
const retrieveFileHandlers = new Set();
|
853
|
-
const retrieveSourceMapHandlers = new Set();
|
854
|
-
const createExecHandlers = (handlers) => {
|
855
|
-
return ((...args) => {
|
856
|
-
for (const handler of handlers) {
|
857
|
-
const result = handler(...args);
|
858
|
-
if (result)
|
859
|
-
return result;
|
860
|
-
}
|
861
|
-
return null;
|
551
|
+
queue = [];
|
552
|
+
pending = !1;
|
553
|
+
enqueue(promise) {
|
554
|
+
return new Promise((resolve2, reject) => {
|
555
|
+
this.queue.push({
|
556
|
+
promise,
|
557
|
+
resolve: resolve2,
|
558
|
+
reject
|
559
|
+
}), this.dequeue();
|
862
560
|
});
|
863
|
-
}
|
864
|
-
|
865
|
-
|
866
|
-
|
561
|
+
}
|
562
|
+
dequeue() {
|
563
|
+
if (this.pending)
|
564
|
+
return !1;
|
565
|
+
const item = this.queue.shift();
|
566
|
+
return item ? (this.pending = !0, item.promise().then(item.resolve).catch(item.reject).finally(() => {
|
567
|
+
this.pending = !1, this.dequeue();
|
568
|
+
}), !0) : !1;
|
569
|
+
}
|
570
|
+
}
|
571
|
+
const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
|
572
|
+
for (const handler of handlers) {
|
573
|
+
const result = handler(...args);
|
574
|
+
if (result)
|
575
|
+
return result;
|
576
|
+
}
|
577
|
+
return null;
|
578
|
+
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrievSourceMapFromHandlers = createExecHandlers(retrieveSourceMapHandlers);
|
579
|
+
let overriden = !1;
|
867
580
|
const originalPrepare = Error.prepareStackTrace;
|
868
581
|
function resetInterceptor(runtime, options) {
|
869
|
-
|
870
|
-
if (options.retrieveFile)
|
871
|
-
retrieveFileHandlers.delete(options.retrieveFile);
|
872
|
-
if (options.retrieveSourceMap)
|
873
|
-
retrieveSourceMapHandlers.delete(options.retrieveSourceMap);
|
874
|
-
if (moduleGraphs.size === 0) {
|
875
|
-
Error.prepareStackTrace = originalPrepare;
|
876
|
-
overriden = false;
|
877
|
-
}
|
582
|
+
moduleGraphs.delete(runtime.moduleCache), options.retrieveFile && retrieveFileHandlers.delete(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.delete(options.retrieveSourceMap), moduleGraphs.size === 0 && (Error.prepareStackTrace = originalPrepare, overriden = !1);
|
878
583
|
}
|
879
584
|
function interceptStackTrace(runtime, options = {}) {
|
880
|
-
|
881
|
-
Error.prepareStackTrace = prepareStackTrace;
|
882
|
-
overriden = true;
|
883
|
-
}
|
884
|
-
moduleGraphs.add(runtime.moduleCache);
|
885
|
-
if (options.retrieveFile)
|
886
|
-
retrieveFileHandlers.add(options.retrieveFile);
|
887
|
-
if (options.retrieveSourceMap)
|
888
|
-
retrieveSourceMapHandlers.add(options.retrieveSourceMap);
|
889
|
-
return () => resetInterceptor(runtime, options);
|
585
|
+
return overriden || (Error.prepareStackTrace = prepareStackTrace, overriden = !0), moduleGraphs.add(runtime.moduleCache), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runtime, options);
|
890
586
|
}
|
891
|
-
// Support URLs relative to a directory, but be careful about a protocol prefix
|
892
587
|
function supportRelativeURL(file, url) {
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
if (protocol && /^\/\w:/.test(startPath)) {
|
900
|
-
// handle file:///C:/ paths
|
901
|
-
protocol += '/';
|
902
|
-
return (protocol +
|
903
|
-
posixResolve(dir.slice(protocol.length), url).replace(/\\/g, '/'));
|
904
|
-
}
|
905
|
-
return protocol + posixResolve(dir.slice(protocol.length), url);
|
588
|
+
if (!file)
|
589
|
+
return url;
|
590
|
+
const dir = posixDirname(file.replace(/\\/g, "/")), match = /^\w+:\/\/[^/]*/.exec(dir);
|
591
|
+
let protocol = match ? match[0] : "";
|
592
|
+
const startPath = dir.slice(protocol.length);
|
593
|
+
return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + posixResolve(dir.slice(protocol.length), url).replace(/\\/g, "/")) : protocol + posixResolve(dir.slice(protocol.length), url);
|
906
594
|
}
|
907
595
|
function getRuntimeSourceMap(position) {
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
return null;
|
596
|
+
for (const moduleCache of moduleGraphs) {
|
597
|
+
const sourceMap = moduleCache.getSourceMap(position.source);
|
598
|
+
if (sourceMap)
|
599
|
+
return {
|
600
|
+
url: position.source,
|
601
|
+
map: sourceMap,
|
602
|
+
vite: !0
|
603
|
+
};
|
604
|
+
}
|
605
|
+
return null;
|
919
606
|
}
|
920
607
|
function retrieveFile(path) {
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
fileContentsCache[path] = content;
|
926
|
-
return content;
|
927
|
-
}
|
928
|
-
return null;
|
608
|
+
if (path in fileContentsCache)
|
609
|
+
return fileContentsCache[path];
|
610
|
+
const content = retrieveFileFromHandlers(path);
|
611
|
+
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
929
612
|
}
|
930
613
|
function retrieveSourceMapURL(source) {
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
while ((match = re.exec(fileData)))
|
940
|
-
lastMatch = match;
|
941
|
-
if (!lastMatch)
|
942
|
-
return null;
|
943
|
-
return lastMatch[1];
|
614
|
+
const fileData = retrieveFile(source);
|
615
|
+
if (!fileData)
|
616
|
+
return null;
|
617
|
+
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
618
|
+
let lastMatch, match;
|
619
|
+
for (; match = re.exec(fileData); )
|
620
|
+
lastMatch = match;
|
621
|
+
return lastMatch ? lastMatch[1] : null;
|
944
622
|
}
|
945
623
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
946
624
|
function retrieveSourceMap(source) {
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
964
|
-
sourceMapData = retrieveFile(sourceMappingURL);
|
965
|
-
}
|
966
|
-
if (!sourceMapData)
|
967
|
-
return null;
|
968
|
-
return {
|
969
|
-
url: sourceMappingURL,
|
970
|
-
map: sourceMapData,
|
971
|
-
};
|
625
|
+
const urlAndMap = retrievSourceMapFromHandlers(source);
|
626
|
+
if (urlAndMap)
|
627
|
+
return urlAndMap;
|
628
|
+
let sourceMappingURL = retrieveSourceMapURL(source);
|
629
|
+
if (!sourceMappingURL)
|
630
|
+
return null;
|
631
|
+
let sourceMapData;
|
632
|
+
if (reSourceMap.test(sourceMappingURL)) {
|
633
|
+
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
634
|
+
sourceMapData = Buffer.from(rawData, "base64").toString(), sourceMappingURL = source;
|
635
|
+
} else
|
636
|
+
sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
637
|
+
return sourceMapData ? {
|
638
|
+
url: sourceMappingURL,
|
639
|
+
map: sourceMapData
|
640
|
+
} : null;
|
972
641
|
}
|
973
642
|
function mapSourcePosition(position) {
|
974
|
-
|
975
|
-
return position;
|
976
|
-
let sourceMap = getRuntimeSourceMap(position);
|
977
|
-
if (!sourceMap)
|
978
|
-
sourceMap = sourceMapCache[position.source];
|
979
|
-
if (!sourceMap) {
|
980
|
-
// Call the (overrideable) retrieveSourceMap function to get the source map.
|
981
|
-
const urlAndMap = retrieveSourceMap(position.source);
|
982
|
-
if (urlAndMap && urlAndMap.map) {
|
983
|
-
const url = urlAndMap.url;
|
984
|
-
sourceMap = sourceMapCache[position.source] = {
|
985
|
-
url,
|
986
|
-
map: new DecodedMap(typeof urlAndMap.map === 'string'
|
987
|
-
? JSON.parse(urlAndMap.map)
|
988
|
-
: urlAndMap.map, url),
|
989
|
-
};
|
990
|
-
const contents = sourceMap.map?.map.sourcesContent;
|
991
|
-
// Load all sources stored inline with the source map into the file cache
|
992
|
-
// to pretend like they are already loaded. They may not exist on disk.
|
993
|
-
if (sourceMap.map && contents) {
|
994
|
-
sourceMap.map.resolvedSources.forEach((source, i) => {
|
995
|
-
const content = contents[i];
|
996
|
-
if (content && source && url) {
|
997
|
-
const contentUrl = supportRelativeURL(url, source);
|
998
|
-
fileContentsCache[contentUrl] = content;
|
999
|
-
}
|
1000
|
-
});
|
1001
|
-
}
|
1002
|
-
}
|
1003
|
-
else {
|
1004
|
-
sourceMap = sourceMapCache[position.source] = {
|
1005
|
-
url: null,
|
1006
|
-
map: null,
|
1007
|
-
};
|
1008
|
-
}
|
1009
|
-
}
|
1010
|
-
// Resolve the source URL relative to the URL of the source map
|
1011
|
-
if (sourceMap && sourceMap.map && sourceMap.url) {
|
1012
|
-
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
1013
|
-
// Only return the original position if a matching line was found. If no
|
1014
|
-
// matching line is found then we return position instead, which will cause
|
1015
|
-
// the stack trace to print the path and line for the compiled file. It is
|
1016
|
-
// better to give a precise location in the compiled file than a vague
|
1017
|
-
// location in the original file.
|
1018
|
-
if (originalPosition && originalPosition.source != null) {
|
1019
|
-
originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
|
1020
|
-
if (sourceMap.vite) {
|
1021
|
-
// @ts-expect-error vite is not defined
|
1022
|
-
originalPosition._vite = true;
|
1023
|
-
}
|
1024
|
-
return originalPosition;
|
1025
|
-
}
|
1026
|
-
}
|
643
|
+
if (!position.source)
|
1027
644
|
return position;
|
645
|
+
let sourceMap = getRuntimeSourceMap(position);
|
646
|
+
if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
|
647
|
+
const urlAndMap = retrieveSourceMap(position.source);
|
648
|
+
if (urlAndMap && urlAndMap.map) {
|
649
|
+
const url = urlAndMap.url;
|
650
|
+
sourceMap = sourceMapCache[position.source] = {
|
651
|
+
url,
|
652
|
+
map: new DecodedMap(typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map, url)
|
653
|
+
};
|
654
|
+
const contents = sourceMap.map?.map.sourcesContent;
|
655
|
+
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
656
|
+
const content = contents[i];
|
657
|
+
if (content && source && url) {
|
658
|
+
const contentUrl = supportRelativeURL(url, source);
|
659
|
+
fileContentsCache[contentUrl] = content;
|
660
|
+
}
|
661
|
+
});
|
662
|
+
} else
|
663
|
+
sourceMap = sourceMapCache[position.source] = {
|
664
|
+
url: null,
|
665
|
+
map: null
|
666
|
+
};
|
667
|
+
}
|
668
|
+
if (sourceMap && sourceMap.map && sourceMap.url) {
|
669
|
+
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
670
|
+
if (originalPosition && originalPosition.source != null)
|
671
|
+
return originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source), sourceMap.vite && (originalPosition._vite = !0), originalPosition;
|
672
|
+
}
|
673
|
+
return position;
|
1028
674
|
}
|
1029
|
-
// Parses code generated by FormatEvalOrigin(), a function inside V8:
|
1030
|
-
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
|
1031
675
|
function mapEvalOrigin(origin) {
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
// Parse nested eval() calls using recursion
|
1044
|
-
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
1045
|
-
if (match)
|
1046
|
-
return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
1047
|
-
// Make sure we still return useful information if we didn't find anything
|
1048
|
-
return origin;
|
676
|
+
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
677
|
+
if (match) {
|
678
|
+
const position = mapSourcePosition({
|
679
|
+
name: null,
|
680
|
+
source: match[2],
|
681
|
+
line: +match[3],
|
682
|
+
column: +match[4] - 1
|
683
|
+
});
|
684
|
+
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
685
|
+
}
|
686
|
+
return match = /^eval at ([^(]+) \((.+)\)$/.exec(origin), match ? `eval at ${match[1]} (${mapEvalOrigin(match[2])})` : origin;
|
1049
687
|
}
|
1050
|
-
// This is copied almost verbatim from the V8 source code at
|
1051
|
-
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
|
1052
|
-
// implementation of wrapCallSite() used to just forward to the actual source
|
1053
|
-
// code of CallSite.prototype.toString but unfortunately a new release of V8
|
1054
|
-
// did something to the prototype chain and broke the shim. The only fix I
|
1055
|
-
// could find was copy/paste.
|
1056
688
|
function CallSiteToString() {
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
if (columnNumber)
|
1082
|
-
fileLocation += `:${columnNumber}`;
|
1083
|
-
}
|
1084
|
-
}
|
1085
|
-
let line = '';
|
1086
|
-
const functionName = this.getFunctionName();
|
1087
|
-
let addSuffix = true;
|
1088
|
-
const isConstructor = this.isConstructor();
|
1089
|
-
const isMethodCall = !(this.isToplevel() || isConstructor);
|
1090
|
-
if (isMethodCall) {
|
1091
|
-
let typeName = this.getTypeName();
|
1092
|
-
// Fixes shim to be backward compatable with Node v0 to v4
|
1093
|
-
if (typeName === '[object Object]')
|
1094
|
-
typeName = 'null';
|
1095
|
-
const methodName = this.getMethodName();
|
1096
|
-
if (functionName) {
|
1097
|
-
if (typeName && functionName.indexOf(typeName) !== 0)
|
1098
|
-
line += `${typeName}.`;
|
1099
|
-
line += functionName;
|
1100
|
-
if (methodName &&
|
1101
|
-
functionName.indexOf(`.${methodName}`) !==
|
1102
|
-
functionName.length - methodName.length - 1)
|
1103
|
-
line += ` [as ${methodName}]`;
|
1104
|
-
}
|
1105
|
-
else {
|
1106
|
-
line += `${typeName}.${methodName || '<anonymous>'}`;
|
1107
|
-
}
|
1108
|
-
}
|
1109
|
-
else if (isConstructor) {
|
1110
|
-
line += `new ${functionName || '<anonymous>'}`;
|
1111
|
-
}
|
1112
|
-
else if (functionName) {
|
1113
|
-
line += functionName;
|
1114
|
-
}
|
1115
|
-
else {
|
1116
|
-
line += fileLocation;
|
1117
|
-
addSuffix = false;
|
1118
|
-
}
|
1119
|
-
if (addSuffix)
|
1120
|
-
line += ` (${fileLocation})`;
|
1121
|
-
return line;
|
689
|
+
let fileName, fileLocation = "";
|
690
|
+
if (this.isNative())
|
691
|
+
fileLocation = "native";
|
692
|
+
else {
|
693
|
+
fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval() && (fileLocation = this.getEvalOrigin(), fileLocation += ", "), fileName ? fileLocation += fileName : fileLocation += "<anonymous>";
|
694
|
+
const lineNumber = this.getLineNumber();
|
695
|
+
if (lineNumber != null) {
|
696
|
+
fileLocation += `:${lineNumber}`;
|
697
|
+
const columnNumber = this.getColumnNumber();
|
698
|
+
columnNumber && (fileLocation += `:${columnNumber}`);
|
699
|
+
}
|
700
|
+
}
|
701
|
+
let line = "";
|
702
|
+
const functionName = this.getFunctionName();
|
703
|
+
let addSuffix = !0;
|
704
|
+
const isConstructor = this.isConstructor();
|
705
|
+
if (!(this.isToplevel() || isConstructor)) {
|
706
|
+
let typeName = this.getTypeName();
|
707
|
+
typeName === "[object Object]" && (typeName = "null");
|
708
|
+
const methodName = this.getMethodName();
|
709
|
+
functionName ? (typeName && functionName.indexOf(typeName) !== 0 && (line += `${typeName}.`), line += functionName, methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1 && (line += ` [as ${methodName}]`)) : line += `${typeName}.${methodName || "<anonymous>"}`;
|
710
|
+
} else
|
711
|
+
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
712
|
+
return addSuffix && (line += ` (${fileLocation})`), line;
|
1122
713
|
}
|
1123
714
|
function cloneCallSite(frame) {
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
}
|
1132
|
-
: frame[key];
|
1133
|
-
});
|
1134
|
-
object.toString = CallSiteToString;
|
1135
|
-
return object;
|
715
|
+
const object = {};
|
716
|
+
return Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
717
|
+
const key = name;
|
718
|
+
object[key] = /^(?:is|get)/.test(name) ? function() {
|
719
|
+
return frame[key].call(frame);
|
720
|
+
} : frame[key];
|
721
|
+
}), object.toString = CallSiteToString, object;
|
1136
722
|
}
|
1137
723
|
function wrapCallSite(frame, state) {
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
if (state.nextPosition == null)
|
1172
|
-
return originalFunctionName();
|
1173
|
-
return state.nextPosition.name || originalFunctionName();
|
1174
|
-
})();
|
1175
|
-
return name === 'eval' && '_vite' in position ? null : name;
|
1176
|
-
};
|
1177
|
-
frame.getFileName = function () {
|
1178
|
-
return position.source ?? undefined;
|
1179
|
-
};
|
1180
|
-
frame.getLineNumber = function () {
|
1181
|
-
return position.line;
|
1182
|
-
};
|
1183
|
-
frame.getColumnNumber = function () {
|
1184
|
-
return position.column + 1;
|
1185
|
-
};
|
1186
|
-
frame.getScriptNameOrSourceURL = function () {
|
1187
|
-
return position.source;
|
1188
|
-
};
|
1189
|
-
return frame;
|
1190
|
-
}
|
1191
|
-
// Code called using eval() needs special handling
|
1192
|
-
let origin = frame.isEval() && frame.getEvalOrigin();
|
1193
|
-
if (origin) {
|
1194
|
-
origin = mapEvalOrigin(origin);
|
1195
|
-
frame = cloneCallSite(frame);
|
1196
|
-
frame.getEvalOrigin = function () {
|
1197
|
-
return origin || undefined;
|
1198
|
-
};
|
1199
|
-
return frame;
|
1200
|
-
}
|
1201
|
-
// If we get here then we were unable to change the source position
|
1202
|
-
return frame;
|
724
|
+
if (state === void 0 && (state = { nextPosition: null, curPosition: null }), frame.isNative())
|
725
|
+
return state.curPosition = null, frame;
|
726
|
+
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
727
|
+
if (source) {
|
728
|
+
const line = frame.getLineNumber();
|
729
|
+
let column = frame.getColumnNumber() - 1;
|
730
|
+
const headerLength = 62;
|
731
|
+
line === 1 && column > headerLength && !frame.isEval() && (column -= headerLength);
|
732
|
+
const position = mapSourcePosition({
|
733
|
+
name: null,
|
734
|
+
source,
|
735
|
+
line,
|
736
|
+
column
|
737
|
+
});
|
738
|
+
state.curPosition = position, frame = cloneCallSite(frame);
|
739
|
+
const originalFunctionName = frame.getFunctionName;
|
740
|
+
return frame.getFunctionName = function() {
|
741
|
+
const name = (() => state.nextPosition == null ? originalFunctionName() : state.nextPosition.name || originalFunctionName())();
|
742
|
+
return name === "eval" && "_vite" in position ? null : name;
|
743
|
+
}, frame.getFileName = function() {
|
744
|
+
return position.source ?? void 0;
|
745
|
+
}, frame.getLineNumber = function() {
|
746
|
+
return position.line;
|
747
|
+
}, frame.getColumnNumber = function() {
|
748
|
+
return position.column + 1;
|
749
|
+
}, frame.getScriptNameOrSourceURL = function() {
|
750
|
+
return position.source;
|
751
|
+
}, frame;
|
752
|
+
}
|
753
|
+
let origin = frame.isEval() && frame.getEvalOrigin();
|
754
|
+
return origin && (origin = mapEvalOrigin(origin), frame = cloneCallSite(frame), frame.getEvalOrigin = function() {
|
755
|
+
return origin || void 0;
|
756
|
+
}), frame;
|
1203
757
|
}
|
1204
758
|
function prepareStackTrace(error, stack) {
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
for (let i = stack.length - 1; i >= 0; i--) {
|
1211
|
-
processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`);
|
1212
|
-
state.nextPosition = state.curPosition;
|
1213
|
-
}
|
1214
|
-
state.curPosition = state.nextPosition = null;
|
1215
|
-
return errorString + processedStack.reverse().join('');
|
759
|
+
const name = error.name || "Error", message = error.message || "", errorString = `${name}: ${message}`, state = { nextPosition: null, curPosition: null }, processedStack = [];
|
760
|
+
for (let i = stack.length - 1; i >= 0; i--)
|
761
|
+
processedStack.push(`
|
762
|
+
at ${wrapCallSite(stack[i], state)}`), state.nextPosition = state.curPosition;
|
763
|
+
return state.curPosition = state.nextPosition = null, errorString + processedStack.reverse().join("");
|
1216
764
|
}
|
1217
|
-
|
1218
765
|
function enableSourceMapSupport(runtime) {
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
return () => !isEnabledAlready && process.setSourceMapsEnabled(false);
|
1229
|
-
}
|
1230
|
-
return interceptStackTrace(runtime, typeof runtime.options.sourcemapInterceptor === 'object'
|
1231
|
-
? runtime.options.sourcemapInterceptor
|
1232
|
-
: undefined);
|
766
|
+
if (runtime.options.sourcemapInterceptor === "node") {
|
767
|
+
if (typeof process > "u")
|
768
|
+
throw new TypeError(`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`);
|
769
|
+
if (typeof process.setSourceMapsEnabled != "function")
|
770
|
+
throw new TypeError(`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`);
|
771
|
+
const isEnabledAlready = process.sourceMapsEnabled ?? !1;
|
772
|
+
return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
|
773
|
+
}
|
774
|
+
return interceptStackTrace(runtime, typeof runtime.options.sourcemapInterceptor == "object" ? runtime.options.sourcemapInterceptor : void 0);
|
1233
775
|
}
|
1234
|
-
|
1235
776
|
class ViteRuntime {
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
777
|
+
options;
|
778
|
+
runner;
|
779
|
+
debug;
|
780
|
+
/**
|
781
|
+
* Holds the cache of modules
|
782
|
+
* Keys of the map are ids
|
783
|
+
*/
|
784
|
+
moduleCache;
|
785
|
+
hmrClient;
|
786
|
+
entrypoints = /* @__PURE__ */ new Set();
|
787
|
+
idToUrlMap = /* @__PURE__ */ new Map();
|
788
|
+
fileToIdMap = /* @__PURE__ */ new Map();
|
789
|
+
envProxy = new Proxy({}, {
|
790
|
+
get(_, p) {
|
791
|
+
throw new Error(`[vite-runtime] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`);
|
792
|
+
}
|
793
|
+
});
|
794
|
+
_destroyed = !1;
|
795
|
+
_resetSourceMapSupport;
|
796
|
+
constructor(options, runner, debug) {
|
797
|
+
this.options = options, this.runner = runner, this.debug = debug, this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root), typeof options.hmr == "object" && (this.hmrClient = new HMRClient(options.hmr.logger === !1 ? silentConsole : options.hmr.logger || console, options.hmr.connection, ({ acceptedPath, ssrInvalidates }) => (this.moduleCache.invalidate(acceptedPath), ssrInvalidates && this.invalidateFiles(ssrInvalidates), this.executeUrl(acceptedPath))), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this._resetSourceMapSupport = enableSourceMapSupport(this));
|
798
|
+
}
|
799
|
+
/**
|
800
|
+
* URL to execute. Accepts file path, server path or id relative to the root.
|
801
|
+
*/
|
802
|
+
async executeUrl(url) {
|
803
|
+
url = this.normalizeEntryUrl(url);
|
804
|
+
const fetchedModule = await this.cachedModule(url);
|
805
|
+
return await this.cachedRequest(url, fetchedModule);
|
806
|
+
}
|
807
|
+
/**
|
808
|
+
* Entrypoint URL to execute. Accepts file path, server path or id relative to the root.
|
809
|
+
* In the case of a full reload triggered by HMR, this is the module that will be reloaded.
|
810
|
+
* If this method is called multiple times, all entrypoints will be reloaded one at a time.
|
811
|
+
*/
|
812
|
+
async executeEntrypoint(url) {
|
813
|
+
url = this.normalizeEntryUrl(url);
|
814
|
+
const fetchedModule = await this.cachedModule(url);
|
815
|
+
return await this.cachedRequest(url, fetchedModule, [], {
|
816
|
+
entrypoint: !0
|
1252
817
|
});
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
this.
|
1312
|
-
|
1313
|
-
|
1314
|
-
}
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
}
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
this.debug(`[vite-runtime] module ${moduleId} takes over 2s to load.\n${getStack()}`);
|
1392
|
-
}, 2000);
|
1393
|
-
}
|
1394
|
-
try {
|
1395
|
-
// cached module
|
1396
|
-
if (mod.promise)
|
1397
|
-
return this.processImport(await mod.promise, fetchedModule, metadata);
|
1398
|
-
const promise = this.directRequest(id, fetchedModule, callstack);
|
1399
|
-
mod.promise = promise;
|
1400
|
-
mod.evaluated = false;
|
1401
|
-
return this.processImport(await promise, fetchedModule, metadata);
|
1402
|
-
}
|
1403
|
-
finally {
|
1404
|
-
mod.evaluated = true;
|
1405
|
-
if (debugTimer)
|
1406
|
-
clearTimeout(debugTimer);
|
1407
|
-
}
|
1408
|
-
}
|
1409
|
-
async cachedModule(id, importer) {
|
1410
|
-
if (this._destroyed) {
|
1411
|
-
throw new Error(`[vite] Vite runtime has been destroyed.`);
|
1412
|
-
}
|
1413
|
-
const normalized = this.idToUrlMap.get(id);
|
1414
|
-
if (normalized) {
|
1415
|
-
const mod = this.moduleCache.getByModuleId(normalized);
|
1416
|
-
if (mod.meta) {
|
1417
|
-
return mod.meta;
|
1418
|
-
}
|
1419
|
-
}
|
1420
|
-
this.debug?.('[vite-runtime] fetching', id);
|
1421
|
-
// fast return for established externalized patterns
|
1422
|
-
const fetchedModule = id.startsWith('data:')
|
1423
|
-
? ({ externalize: id, type: 'builtin' })
|
1424
|
-
: await this.options.fetchModule(id, importer);
|
1425
|
-
// base moduleId on "file" and not on id
|
1426
|
-
// if `import(variable)` is called it's possible that it doesn't have an extension for example
|
1427
|
-
// if we used id for that, it's possible to have a duplicated module
|
1428
|
-
const idQuery = id.split('?')[1];
|
1429
|
-
const query = idQuery ? `?${idQuery}` : '';
|
1430
|
-
const file = 'file' in fetchedModule ? fetchedModule.file : undefined;
|
1431
|
-
const fullFile = file ? `${file}${query}` : id;
|
1432
|
-
const moduleId = this.moduleCache.normalize(fullFile);
|
1433
|
-
const mod = this.moduleCache.getByModuleId(moduleId);
|
1434
|
-
fetchedModule.id = moduleId;
|
1435
|
-
mod.meta = fetchedModule;
|
1436
|
-
if (file) {
|
1437
|
-
const fileModules = this.fileToIdMap.get(file) || [];
|
1438
|
-
fileModules.push(moduleId);
|
1439
|
-
this.fileToIdMap.set(file, fileModules);
|
1440
|
-
}
|
1441
|
-
this.idToUrlMap.set(id, moduleId);
|
1442
|
-
this.idToUrlMap.set(unwrapId(id), moduleId);
|
1443
|
-
return fetchedModule;
|
1444
|
-
}
|
1445
|
-
// override is allowed, consider this a public API
|
1446
|
-
async directRequest(id, fetchResult, _callstack) {
|
1447
|
-
const moduleId = fetchResult.id;
|
1448
|
-
const callstack = [..._callstack, moduleId];
|
1449
|
-
const mod = this.moduleCache.getByModuleId(moduleId);
|
1450
|
-
const request = async (dep, metadata) => {
|
1451
|
-
const fetchedModule = await this.cachedModule(dep, moduleId);
|
1452
|
-
const depMod = this.moduleCache.getByModuleId(fetchedModule.id);
|
1453
|
-
depMod.importers.add(moduleId);
|
1454
|
-
mod.imports.add(fetchedModule.id);
|
1455
|
-
return this.cachedRequest(dep, fetchedModule, callstack, metadata);
|
1456
|
-
};
|
1457
|
-
const dynamicRequest = async (dep) => {
|
1458
|
-
// it's possible to provide an object with toString() method inside import()
|
1459
|
-
dep = String(dep);
|
1460
|
-
if (dep[0] === '.') {
|
1461
|
-
dep = posixResolve(posixDirname(id), dep);
|
1462
|
-
}
|
1463
|
-
return request(dep, { isDynamicImport: true });
|
1464
|
-
};
|
1465
|
-
if ('externalize' in fetchResult) {
|
1466
|
-
const { externalize } = fetchResult;
|
1467
|
-
this.debug?.('[vite-runtime] externalizing', externalize);
|
1468
|
-
const exports = await this.runner.runExternalModule(externalize);
|
1469
|
-
mod.exports = exports;
|
1470
|
-
return exports;
|
1471
|
-
}
|
1472
|
-
const { code, file } = fetchResult;
|
1473
|
-
if (code == null) {
|
1474
|
-
const importer = callstack[callstack.length - 2];
|
1475
|
-
throw new Error(`[vite-runtime] Failed to load "${id}"${importer ? ` imported from ${importer}` : ''}`);
|
1476
|
-
}
|
1477
|
-
const modulePath = cleanUrl(file || moduleId);
|
1478
|
-
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
|
1479
|
-
const href = posixPathToFileHref(modulePath);
|
1480
|
-
const filename = modulePath;
|
1481
|
-
const dirname = posixDirname(modulePath);
|
1482
|
-
const meta = {
|
1483
|
-
filename: isWindows ? toWindowsPath(filename) : filename,
|
1484
|
-
dirname: isWindows ? toWindowsPath(dirname) : dirname,
|
1485
|
-
url: href,
|
1486
|
-
env: this.envProxy,
|
1487
|
-
resolve(id, parent) {
|
1488
|
-
throw new Error('[vite-runtime] "import.meta.resolve" is not supported.');
|
1489
|
-
},
|
1490
|
-
// should be replaced during transformation
|
1491
|
-
glob() {
|
1492
|
-
throw new Error('[vite-runtime] "import.meta.glob" is not supported.');
|
1493
|
-
},
|
1494
|
-
};
|
1495
|
-
const exports = Object.create(null);
|
1496
|
-
Object.defineProperty(exports, Symbol.toStringTag, {
|
1497
|
-
value: 'Module',
|
1498
|
-
enumerable: false,
|
1499
|
-
configurable: false,
|
1500
|
-
});
|
1501
|
-
mod.exports = exports;
|
1502
|
-
let hotContext;
|
1503
|
-
if (this.hmrClient) {
|
1504
|
-
Object.defineProperty(meta, 'hot', {
|
1505
|
-
enumerable: true,
|
1506
|
-
get: () => {
|
1507
|
-
if (!this.hmrClient) {
|
1508
|
-
throw new Error(`[vite-runtime] HMR client was destroyed.`);
|
1509
|
-
}
|
1510
|
-
this.debug?.('[vite-runtime] creating hmr context for', moduleId);
|
1511
|
-
hotContext ||= new HMRContext(this.hmrClient, moduleId);
|
1512
|
-
return hotContext;
|
1513
|
-
},
|
1514
|
-
set: (value) => {
|
1515
|
-
hotContext = value;
|
1516
|
-
},
|
1517
|
-
});
|
1518
|
-
}
|
1519
|
-
const context = {
|
1520
|
-
[ssrImportKey]: request,
|
1521
|
-
[ssrDynamicImportKey]: dynamicRequest,
|
1522
|
-
[ssrModuleExportsKey]: exports,
|
1523
|
-
[ssrExportAllKey]: (obj) => exportAll(exports, obj),
|
1524
|
-
[ssrImportMetaKey]: meta,
|
1525
|
-
};
|
1526
|
-
this.debug?.('[vite-runtime] executing', href);
|
1527
|
-
await this.runner.runViteModule(context, code, id);
|
1528
|
-
return exports;
|
1529
|
-
}
|
818
|
+
}
|
819
|
+
/**
|
820
|
+
* Clear all caches including HMR listeners.
|
821
|
+
*/
|
822
|
+
clearCache() {
|
823
|
+
this.moduleCache.clear(), this.idToUrlMap.clear(), this.entrypoints.clear(), this.hmrClient?.clear();
|
824
|
+
}
|
825
|
+
/**
|
826
|
+
* Clears all caches, removes all HMR listeners, and resets source map support.
|
827
|
+
* This method doesn't stop the HMR connection.
|
828
|
+
*/
|
829
|
+
async destroy() {
|
830
|
+
this._resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this._destroyed = !0;
|
831
|
+
}
|
832
|
+
/**
|
833
|
+
* Returns `true` if the runtime has been destroyed by calling `destroy()` method.
|
834
|
+
*/
|
835
|
+
isDestroyed() {
|
836
|
+
return this._destroyed;
|
837
|
+
}
|
838
|
+
invalidateFiles(files) {
|
839
|
+
files.forEach((file) => {
|
840
|
+
const ids = this.fileToIdMap.get(file);
|
841
|
+
ids && ids.forEach((id) => this.moduleCache.invalidate(id));
|
842
|
+
});
|
843
|
+
}
|
844
|
+
// we don't use moduleCache.normalize because this URL doesn't have to follow the same rules
|
845
|
+
// this URL is something that user passes down manually, and is later resolved by fetchModule
|
846
|
+
// moduleCache.normalize is used on resolved "file" property
|
847
|
+
normalizeEntryUrl(url) {
|
848
|
+
if (url[0] === ".")
|
849
|
+
return url;
|
850
|
+
url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url = url.replace(/\\/g, "/");
|
851
|
+
const _root = this.options.root, root = _root[_root.length - 1] === "/" ? _root : `${_root}/`;
|
852
|
+
return url.startsWith(root) ? url.slice(root.length - 1) : url[0] === "/" ? url : wrapId(url);
|
853
|
+
}
|
854
|
+
processImport(exports, fetchResult, metadata) {
|
855
|
+
if (!("externalize" in fetchResult))
|
856
|
+
return exports;
|
857
|
+
const { id, type } = fetchResult;
|
858
|
+
return type !== "module" && type !== "commonjs" ? exports : (analyzeImportedModDifference(exports, id, type, metadata), proxyGuardOnlyEsm(exports, id, metadata));
|
859
|
+
}
|
860
|
+
async cachedRequest(id, fetchedModule, callstack = [], metadata) {
|
861
|
+
const moduleId = fetchedModule.id;
|
862
|
+
metadata?.entrypoint && this.entrypoints.add(moduleId);
|
863
|
+
const mod = this.moduleCache.getByModuleId(moduleId), { imports, importers } = mod, importee = callstack[callstack.length - 1];
|
864
|
+
if (importee && importers.add(importee), (callstack.includes(moduleId) || Array.from(imports.values()).some((i) => importers.has(i))) && mod.exports)
|
865
|
+
return this.processImport(mod.exports, fetchedModule, metadata);
|
866
|
+
let debugTimer;
|
867
|
+
this.debug && (debugTimer = setTimeout(() => {
|
868
|
+
const getStack = () => `stack:
|
869
|
+
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(`
|
870
|
+
`)}`;
|
871
|
+
this.debug(`[vite-runtime] module ${moduleId} takes over 2s to load.
|
872
|
+
${getStack()}`);
|
873
|
+
}, 2e3));
|
874
|
+
try {
|
875
|
+
if (mod.promise)
|
876
|
+
return this.processImport(await mod.promise, fetchedModule, metadata);
|
877
|
+
const promise = this.directRequest(id, fetchedModule, callstack);
|
878
|
+
return mod.promise = promise, mod.evaluated = !1, this.processImport(await promise, fetchedModule, metadata);
|
879
|
+
} finally {
|
880
|
+
mod.evaluated = !0, debugTimer && clearTimeout(debugTimer);
|
881
|
+
}
|
882
|
+
}
|
883
|
+
async cachedModule(id, importer) {
|
884
|
+
if (this._destroyed)
|
885
|
+
throw new Error("[vite] Vite runtime has been destroyed.");
|
886
|
+
const normalized = this.idToUrlMap.get(id);
|
887
|
+
if (normalized) {
|
888
|
+
const mod2 = this.moduleCache.getByModuleId(normalized);
|
889
|
+
if (mod2.meta)
|
890
|
+
return mod2.meta;
|
891
|
+
}
|
892
|
+
this.debug?.("[vite-runtime] fetching", id);
|
893
|
+
const fetchedModule = id.startsWith("data:") ? { externalize: id, type: "builtin" } : await this.options.fetchModule(id, importer), idQuery = id.split("?")[1], query = idQuery ? `?${idQuery}` : "", file = "file" in fetchedModule ? fetchedModule.file : void 0, fullFile = file ? `${file}${query}` : id, moduleId = this.moduleCache.normalize(fullFile), mod = this.moduleCache.getByModuleId(moduleId);
|
894
|
+
if (fetchedModule.id = moduleId, mod.meta = fetchedModule, file) {
|
895
|
+
const fileModules = this.fileToIdMap.get(file) || [];
|
896
|
+
fileModules.push(moduleId), this.fileToIdMap.set(file, fileModules);
|
897
|
+
}
|
898
|
+
return this.idToUrlMap.set(id, moduleId), this.idToUrlMap.set(unwrapId(id), moduleId), fetchedModule;
|
899
|
+
}
|
900
|
+
// override is allowed, consider this a public API
|
901
|
+
async directRequest(id, fetchResult, _callstack) {
|
902
|
+
const moduleId = fetchResult.id, callstack = [..._callstack, moduleId], mod = this.moduleCache.getByModuleId(moduleId), request = async (dep, metadata) => {
|
903
|
+
const fetchedModule = await this.cachedModule(dep, moduleId);
|
904
|
+
return this.moduleCache.getByModuleId(fetchedModule.id).importers.add(moduleId), mod.imports.add(fetchedModule.id), this.cachedRequest(dep, fetchedModule, callstack, metadata);
|
905
|
+
}, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(id), dep)), request(dep, { isDynamicImport: !0 }));
|
906
|
+
if ("externalize" in fetchResult) {
|
907
|
+
const { externalize } = fetchResult;
|
908
|
+
this.debug?.("[vite-runtime] externalizing", externalize);
|
909
|
+
const exports2 = await this.runner.runExternalModule(externalize);
|
910
|
+
return mod.exports = exports2, exports2;
|
911
|
+
}
|
912
|
+
const { code, file } = fetchResult;
|
913
|
+
if (code == null) {
|
914
|
+
const importer = callstack[callstack.length - 2];
|
915
|
+
throw new Error(`[vite-runtime] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`);
|
916
|
+
}
|
917
|
+
const modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
|
918
|
+
filename: isWindows ? toWindowsPath(filename) : filename,
|
919
|
+
dirname: isWindows ? toWindowsPath(dirname2) : dirname2,
|
920
|
+
url: href,
|
921
|
+
env: this.envProxy,
|
922
|
+
resolve(id2, parent) {
|
923
|
+
throw new Error('[vite-runtime] "import.meta.resolve" is not supported.');
|
924
|
+
},
|
925
|
+
// should be replaced during transformation
|
926
|
+
glob() {
|
927
|
+
throw new Error('[vite-runtime] "import.meta.glob" is not supported.');
|
928
|
+
}
|
929
|
+
}, exports = /* @__PURE__ */ Object.create(null);
|
930
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
931
|
+
value: "Module",
|
932
|
+
enumerable: !1,
|
933
|
+
configurable: !1
|
934
|
+
}), mod.exports = exports;
|
935
|
+
let hotContext;
|
936
|
+
this.hmrClient && Object.defineProperty(meta, "hot", {
|
937
|
+
enumerable: !0,
|
938
|
+
get: () => {
|
939
|
+
if (!this.hmrClient)
|
940
|
+
throw new Error("[vite-runtime] HMR client was destroyed.");
|
941
|
+
return this.debug?.("[vite-runtime] creating hmr context for", moduleId), hotContext ||= new HMRContext(this.hmrClient, moduleId), hotContext;
|
942
|
+
},
|
943
|
+
set: (value) => {
|
944
|
+
hotContext = value;
|
945
|
+
}
|
946
|
+
});
|
947
|
+
const context = {
|
948
|
+
[ssrImportKey]: request,
|
949
|
+
[ssrDynamicImportKey]: dynamicRequest,
|
950
|
+
[ssrModuleExportsKey]: exports,
|
951
|
+
[ssrExportAllKey]: (obj) => exportAll(exports, obj),
|
952
|
+
[ssrImportMetaKey]: meta
|
953
|
+
};
|
954
|
+
return this.debug?.("[vite-runtime] executing", href), await this.runner.runViteModule(context, code, id), exports;
|
955
|
+
}
|
1530
956
|
}
|
1531
957
|
function exportAll(exports, sourceModule) {
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
try {
|
1543
|
-
Object.defineProperty(exports, key, {
|
1544
|
-
enumerable: true,
|
1545
|
-
configurable: true,
|
1546
|
-
get: () => sourceModule[key],
|
1547
|
-
});
|
1548
|
-
}
|
1549
|
-
catch (_err) { }
|
958
|
+
if (exports !== sourceModule && !(isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise)) {
|
959
|
+
for (const key in sourceModule)
|
960
|
+
if (key !== "default" && key !== "__esModule")
|
961
|
+
try {
|
962
|
+
Object.defineProperty(exports, key, {
|
963
|
+
enumerable: !0,
|
964
|
+
configurable: !0,
|
965
|
+
get: () => sourceModule[key]
|
966
|
+
});
|
967
|
+
} catch {
|
1550
968
|
}
|
1551
|
-
|
969
|
+
}
|
1552
970
|
}
|
1553
|
-
/**
|
1554
|
-
* Vite converts `import { } from 'foo'` to `const _ = __vite_ssr_import__('foo')`.
|
1555
|
-
* Top-level imports and dynamic imports work slightly differently in Node.js.
|
1556
|
-
* This function normalizes the differences so it matches prod behaviour.
|
1557
|
-
*/
|
1558
971
|
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
return;
|
1565
|
-
// For non-ESM, named imports is done via static analysis with cjs-module-lexer in Node.js.
|
1566
|
-
// If the user named imports a specifier that can't be analyzed, error.
|
1567
|
-
if (metadata?.importedNames?.length) {
|
1568
|
-
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
1569
|
-
if (missingBindings.length) {
|
1570
|
-
const lastBinding = missingBindings[missingBindings.length - 1];
|
1571
|
-
// Copied from Node.js
|
1572
|
-
throw new SyntaxError(`\
|
1573
|
-
[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
|
972
|
+
if (!metadata?.isDynamicImport && moduleType !== "module" && metadata?.importedNames?.length) {
|
973
|
+
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
974
|
+
if (missingBindings.length) {
|
975
|
+
const lastBinding = missingBindings[missingBindings.length - 1];
|
976
|
+
throw new SyntaxError(`[vite] Named export '${lastBinding}' not found. The requested module '${rawId}' is a CommonJS module, which may not support all module.exports as named exports.
|
1574
977
|
CommonJS modules can always be imported via the default export, for example using:
|
1575
978
|
|
1576
979
|
import pkg from '${rawId}';
|
1577
|
-
const {${missingBindings.join(
|
980
|
+
const {${missingBindings.join(", ")}} = pkg;
|
1578
981
|
`);
|
1579
|
-
}
|
1580
982
|
}
|
983
|
+
}
|
1581
984
|
}
|
1582
|
-
/**
|
1583
|
-
* Guard invalid named exports only, similar to how Node.js errors for top-level imports.
|
1584
|
-
* But since we transform as dynamic imports, we need to emulate the error manually.
|
1585
|
-
*/
|
1586
985
|
function proxyGuardOnlyEsm(mod, rawId, metadata) {
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
get(mod, prop) {
|
1593
|
-
if (prop !== 'then' && !(prop in mod)) {
|
1594
|
-
throw new SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${prop.toString()}'`);
|
1595
|
-
}
|
1596
|
-
return mod[prop];
|
1597
|
-
},
|
1598
|
-
});
|
1599
|
-
}
|
1600
|
-
|
1601
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
1602
|
-
const AsyncFunction = async function () { }.constructor;
|
1603
|
-
class ESModulesRunner {
|
1604
|
-
async runViteModule(context, code) {
|
1605
|
-
// use AsyncFunction instead of vm module to support broader array of environments out of the box
|
1606
|
-
const initModule = new AsyncFunction(ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey,
|
1607
|
-
// source map should already be inlined by Vite
|
1608
|
-
'"use strict";' + code);
|
1609
|
-
await initModule(context[ssrModuleExportsKey], context[ssrImportMetaKey], context[ssrImportKey], context[ssrDynamicImportKey], context[ssrExportAllKey]);
|
1610
|
-
Object.seal(context[ssrModuleExportsKey]);
|
1611
|
-
}
|
1612
|
-
runExternalModule(filepath) {
|
1613
|
-
return import(filepath);
|
986
|
+
return metadata?.importedNames?.length ? new Proxy(mod, {
|
987
|
+
get(mod2, prop) {
|
988
|
+
if (prop !== "then" && !(prop in mod2))
|
989
|
+
throw new SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${prop.toString()}'`);
|
990
|
+
return mod2[prop];
|
1614
991
|
}
|
992
|
+
}) : mod;
|
1615
993
|
}
|
1616
|
-
|
1617
|
-
|
994
|
+
const AsyncFunction = async function() {
|
995
|
+
}.constructor;
|
996
|
+
class ESModulesRunner {
|
997
|
+
async runViteModule(context, code) {
|
998
|
+
await new AsyncFunction(
|
999
|
+
ssrModuleExportsKey,
|
1000
|
+
ssrImportMetaKey,
|
1001
|
+
ssrImportKey,
|
1002
|
+
ssrDynamicImportKey,
|
1003
|
+
ssrExportAllKey,
|
1004
|
+
// source map should already be inlined by Vite
|
1005
|
+
'"use strict";' + code
|
1006
|
+
)(context[ssrModuleExportsKey], context[ssrImportMetaKey], context[ssrImportKey], context[ssrDynamicImportKey], context[ssrExportAllKey]), Object.seal(context[ssrModuleExportsKey]);
|
1007
|
+
}
|
1008
|
+
runExternalModule(filepath) {
|
1009
|
+
return import(filepath);
|
1010
|
+
}
|
1011
|
+
}
|
1012
|
+
export {
|
1013
|
+
ESModulesRunner,
|
1014
|
+
ModuleCacheMap,
|
1015
|
+
ViteRuntime,
|
1016
|
+
ssrDynamicImportKey,
|
1017
|
+
ssrExportAllKey,
|
1018
|
+
ssrImportKey,
|
1019
|
+
ssrImportMetaKey,
|
1020
|
+
ssrModuleExportsKey
|
1021
|
+
};
|