vite 6.0.0-alpha.9 → 6.0.0-beta.1
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/LICENSE.md +115 -206
- package/bin/vite.js +1 -1
- package/client.d.ts +12 -0
- package/dist/client/client.mjs +614 -612
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep--Oy4lQ4n.js → dep-BZ_CwQkz.js} +43095 -44742
- package/dist/node/chunks/{dep-BJOLgJFH.js → dep-BZeeNeMJ.js} +165 -968
- package/dist/node/chunks/{dep-CrWVpuYf.js → dep-D-7KCb9p.js} +32 -2
- package/dist/node/chunks/{dep-m9gtlanK.js → dep-DiM5uMHt.js} +1 -1
- package/dist/node/cli.js +282 -257
- package/dist/node/constants.js +108 -84
- package/dist/node/index.d.ts +2010 -1956
- package/dist/node/index.js +237 -148
- package/dist/node/module-runner.d.ts +31 -12
- package/dist/node/module-runner.js +262 -204
- package/dist/node-cjs/publicUtils.cjs +679 -717
- package/index.cjs +27 -4
- package/package.json +34 -31
- package/types/customEvent.d.ts +1 -0
- package/types/hmrPayload.d.ts +3 -1
- package/dist/client/client.mjs.map +0 -1
- package/dist/client/env.mjs.map +0 -1
- package/dist/node/chunks/dep-C7zR1Rh8.js +0 -233
@@ -2,9 +2,6 @@ const VALID_ID_PREFIX = "/@id/", NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
2
2
|
let SOURCEMAPPING_URL = "sourceMa";
|
3
3
|
SOURCEMAPPING_URL += "ppingURL";
|
4
4
|
const isWindows = typeof process < "u" && process.platform === "win32";
|
5
|
-
function wrapId(id) {
|
6
|
-
return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);
|
7
|
-
}
|
8
5
|
function unwrapId(id) {
|
9
6
|
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;
|
10
7
|
}
|
@@ -51,24 +48,22 @@ function normalizeString(path, allowAboveRoot) {
|
|
51
48
|
char = "/";
|
52
49
|
}
|
53
50
|
if (char === "/") {
|
54
|
-
if (!(lastSlash === index - 1 || dots === 1))
|
55
|
-
if (
|
56
|
-
if (res.length
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
continue;
|
64
|
-
}
|
51
|
+
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
52
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
53
|
+
if (res.length > 2) {
|
54
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
55
|
+
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
56
|
+
continue;
|
57
|
+
} else if (res.length > 0) {
|
58
|
+
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
59
|
+
continue;
|
65
60
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
}
|
62
|
+
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
63
|
+
} else
|
64
|
+
res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
69
65
|
lastSlash = index, dots = 0;
|
70
|
-
} else
|
71
|
-
char === "." && dots !== -1 ? ++dots : dots = -1;
|
66
|
+
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
72
67
|
}
|
73
68
|
return res;
|
74
69
|
}
|
@@ -77,15 +72,11 @@ const isAbsolute = function(p) {
|
|
77
72
|
}, dirname = function(p) {
|
78
73
|
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
79
74
|
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
80
|
-
}
|
81
|
-
function
|
82
|
-
|
83
|
-
let timestamp = 0;
|
84
|
-
return {
|
85
|
-
query: idQuery ? ("?" + idQuery).replace(timestampRegex, (substring, tsString, nextItem) => (timestamp = Number(tsString), substring[0] === "?" && nextItem === "&" ? "?" : "")) : "",
|
86
|
-
timestamp
|
87
|
-
};
|
75
|
+
};
|
76
|
+
function normalizeAbsoluteUrl(url, root) {
|
77
|
+
return url = slash(url), url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url.startsWith(root) && (url = url.slice(root.length - 1)), url;
|
88
78
|
}
|
79
|
+
const 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;
|
89
80
|
function encodePathChars(filepath) {
|
90
81
|
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(`
|
91
82
|
`) !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
@@ -104,38 +95,46 @@ for (let i = 0; i < chars.length; i++) {
|
|
104
95
|
const c = chars.charCodeAt(i);
|
105
96
|
intToChar[i] = c, charToInt[c] = i;
|
106
97
|
}
|
107
|
-
function
|
108
|
-
const state = new Int32Array(5), decoded = [];
|
109
|
-
let index = 0;
|
110
|
-
do {
|
111
|
-
const semi = indexOf(mappings, index), line = [];
|
112
|
-
let sorted = !0, lastCol = 0;
|
113
|
-
state[0] = 0;
|
114
|
-
for (let i = index; i < semi; i++) {
|
115
|
-
let seg;
|
116
|
-
i = decodeInteger(mappings, i, state, 0);
|
117
|
-
const col = state[0];
|
118
|
-
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);
|
119
|
-
}
|
120
|
-
sorted || sort(line), decoded.push(line), index = semi + 1;
|
121
|
-
} while (index <= mappings.length);
|
122
|
-
return decoded;
|
123
|
-
}
|
124
|
-
function indexOf(mappings, index) {
|
125
|
-
const idx = mappings.indexOf(";", index);
|
126
|
-
return idx === -1 ? mappings.length : idx;
|
127
|
-
}
|
128
|
-
function decodeInteger(mappings, pos, state, j) {
|
98
|
+
function decodeInteger(reader, relative) {
|
129
99
|
let value = 0, shift = 0, integer = 0;
|
130
100
|
do {
|
131
|
-
const c =
|
101
|
+
const c = reader.next();
|
132
102
|
integer = charToInt[c], value |= (integer & 31) << shift, shift += 5;
|
133
103
|
} while (integer & 32);
|
134
104
|
const shouldNegate = value & 1;
|
135
|
-
return value >>>= 1, shouldNegate && (value = -2147483648 | -value),
|
105
|
+
return value >>>= 1, shouldNegate && (value = -2147483648 | -value), relative + value;
|
106
|
+
}
|
107
|
+
function hasMoreVlq(reader, max) {
|
108
|
+
return reader.pos >= max ? !1 : reader.peek() !== comma;
|
109
|
+
}
|
110
|
+
class StringReader {
|
111
|
+
constructor(buffer) {
|
112
|
+
this.pos = 0, this.buffer = buffer;
|
113
|
+
}
|
114
|
+
next() {
|
115
|
+
return this.buffer.charCodeAt(this.pos++);
|
116
|
+
}
|
117
|
+
peek() {
|
118
|
+
return this.buffer.charCodeAt(this.pos);
|
119
|
+
}
|
120
|
+
indexOf(char) {
|
121
|
+
const { buffer, pos } = this, idx = buffer.indexOf(char, pos);
|
122
|
+
return idx === -1 ? buffer.length : idx;
|
123
|
+
}
|
136
124
|
}
|
137
|
-
function
|
138
|
-
|
125
|
+
function decode(mappings) {
|
126
|
+
const { length } = mappings, reader = new StringReader(mappings), decoded = [];
|
127
|
+
let genColumn = 0, sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
|
128
|
+
do {
|
129
|
+
const semi = reader.indexOf(";"), line = [];
|
130
|
+
let sorted = !0, lastCol = 0;
|
131
|
+
for (genColumn = 0; reader.pos < semi; ) {
|
132
|
+
let seg;
|
133
|
+
genColumn = decodeInteger(reader, genColumn), genColumn < lastCol && (sorted = !1), lastCol = genColumn, hasMoreVlq(reader, semi) ? (sourcesIndex = decodeInteger(reader, sourcesIndex), sourceLine = decodeInteger(reader, sourceLine), sourceColumn = decodeInteger(reader, sourceColumn), hasMoreVlq(reader, semi) ? (namesIndex = decodeInteger(reader, namesIndex), seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]) : seg = [genColumn, sourcesIndex, sourceLine, sourceColumn]) : seg = [genColumn], line.push(seg), reader.pos++;
|
134
|
+
}
|
135
|
+
sorted || sort(line), decoded.push(line), reader.pos = semi + 1;
|
136
|
+
} while (reader.pos <= length);
|
137
|
+
return decoded;
|
139
138
|
}
|
140
139
|
function sort(line) {
|
141
140
|
line.sort(sortComparator);
|
@@ -208,7 +207,13 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
208
207
|
return found ? index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index) : bias === LEAST_UPPER_BOUND && index++, index === -1 || index === segments.length ? -1 : index;
|
209
208
|
}
|
210
209
|
class DecodedMap {
|
211
|
-
map
|
210
|
+
constructor(map, from) {
|
211
|
+
this.map = map;
|
212
|
+
const { mappings, names, sources } = map;
|
213
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map(
|
214
|
+
(s) => posixResolve(s || "", from)
|
215
|
+
);
|
216
|
+
}
|
212
217
|
_encoded;
|
213
218
|
_decoded;
|
214
219
|
_decodedMemo;
|
@@ -216,11 +221,6 @@ class DecodedMap {
|
|
216
221
|
version;
|
217
222
|
names = [];
|
218
223
|
resolvedSources;
|
219
|
-
constructor(map, from) {
|
220
|
-
this.map = map;
|
221
|
-
const { mappings, names, sources } = map;
|
222
|
-
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
223
|
-
}
|
224
224
|
}
|
225
225
|
function memoizedState() {
|
226
226
|
return {
|
@@ -233,7 +233,9 @@ function getOriginalPosition(map, needle) {
|
|
233
233
|
const result = originalPositionFor(map, needle);
|
234
234
|
return result.column == null ? null : result;
|
235
235
|
}
|
236
|
-
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
236
|
+
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
237
|
+
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`
|
238
|
+
);
|
237
239
|
class ModuleCacheMap extends Map {
|
238
240
|
root;
|
239
241
|
constructor(root, entries) {
|
@@ -285,8 +287,7 @@ class ModuleCacheMap extends Map {
|
|
285
287
|
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
286
288
|
for (const _id of ids) {
|
287
289
|
const id = this.normalize(_id);
|
288
|
-
if (invalidated.has(id))
|
289
|
-
continue;
|
290
|
+
if (invalidated.has(id)) continue;
|
290
291
|
invalidated.add(id);
|
291
292
|
const mod = super.get(id);
|
292
293
|
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidateUrl(id);
|
@@ -299,8 +300,7 @@ class ModuleCacheMap extends Map {
|
|
299
300
|
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
300
301
|
for (const _id of ids) {
|
301
302
|
const id = this.normalize(_id);
|
302
|
-
if (invalidated.has(id))
|
303
|
-
continue;
|
303
|
+
if (invalidated.has(id)) continue;
|
304
304
|
invalidated.add(id);
|
305
305
|
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
306
306
|
subIds.length && this.invalidateSubDepTree(subIds, invalidated), super.delete(id);
|
@@ -309,28 +309,23 @@ class ModuleCacheMap extends Map {
|
|
309
309
|
}
|
310
310
|
getSourceMap(moduleId) {
|
311
311
|
const mod = this.get(moduleId);
|
312
|
-
if (mod.map)
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
if (!mapString)
|
318
|
-
return null;
|
312
|
+
if (mod.map) return mod.map;
|
313
|
+
if (!mod.meta || !("code" in mod.meta)) return null;
|
314
|
+
const mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(
|
315
|
+
mod.meta.code
|
316
|
+
)?.[1];
|
317
|
+
if (!mapString) return null;
|
319
318
|
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
320
319
|
return mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile), mod.map;
|
321
320
|
}
|
322
321
|
}
|
323
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
322
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test", "node:sqlite"]);
|
324
323
|
function normalizeModuleId(file, root) {
|
325
|
-
if (prefixedBuiltins.has(file))
|
326
|
-
return file;
|
324
|
+
if (prefixedBuiltins.has(file)) return file;
|
327
325
|
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
328
326
|
return unixFile.startsWith(root) && (unixFile = unixFile.slice(root.length - 1)), unixFile.replace(/^file:\//, "/");
|
329
327
|
}
|
330
328
|
class HMRContext {
|
331
|
-
hmrClient;
|
332
|
-
ownerPath;
|
333
|
-
newListeners;
|
334
329
|
constructor(hmrClient, ownerPath) {
|
335
330
|
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
336
331
|
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
@@ -339,10 +334,14 @@ class HMRContext {
|
|
339
334
|
if (staleListeners)
|
340
335
|
for (const [event, staleFns] of staleListeners) {
|
341
336
|
const listeners = hmrClient.customListenersMap.get(event);
|
342
|
-
listeners && hmrClient.customListenersMap.set(
|
337
|
+
listeners && hmrClient.customListenersMap.set(
|
338
|
+
event,
|
339
|
+
listeners.filter((l) => !staleFns.includes(l))
|
340
|
+
);
|
343
341
|
}
|
344
342
|
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
345
343
|
}
|
344
|
+
newListeners;
|
346
345
|
get data() {
|
347
346
|
return this.hmrClient.dataMap.get(this.ownerPath);
|
348
347
|
}
|
@@ -378,7 +377,9 @@ class HMRContext {
|
|
378
377
|
}), this.send("vite:invalidate", {
|
379
378
|
path: this.ownerPath,
|
380
379
|
message
|
381
|
-
}), this.hmrClient.logger.debug(
|
380
|
+
}), this.hmrClient.logger.debug(
|
381
|
+
`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
382
|
+
);
|
382
383
|
}
|
383
384
|
on(event, cb) {
|
384
385
|
const addToMap = (map) => {
|
@@ -402,7 +403,9 @@ class HMRContext {
|
|
402
403
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
403
404
|
}
|
404
405
|
send(event, data) {
|
405
|
-
this.hmrClient.messenger.send(
|
406
|
+
this.hmrClient.messenger.send(
|
407
|
+
JSON.stringify({ type: "custom", event, data })
|
408
|
+
);
|
406
409
|
}
|
407
410
|
acceptDeps(deps, callback = () => {
|
408
411
|
}) {
|
@@ -417,7 +420,6 @@ class HMRContext {
|
|
417
420
|
}
|
418
421
|
}
|
419
422
|
class HMRMessenger {
|
420
|
-
connection;
|
421
423
|
constructor(connection) {
|
422
424
|
this.connection = connection;
|
423
425
|
}
|
@@ -430,8 +432,9 @@ class HMRMessenger {
|
|
430
432
|
}
|
431
433
|
}
|
432
434
|
class HMRClient {
|
433
|
-
logger
|
434
|
-
|
435
|
+
constructor(logger, connection, importUpdatedModule) {
|
436
|
+
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
437
|
+
}
|
435
438
|
hotModulesMap = /* @__PURE__ */ new Map();
|
436
439
|
disposeMap = /* @__PURE__ */ new Map();
|
437
440
|
pruneMap = /* @__PURE__ */ new Map();
|
@@ -439,9 +442,6 @@ class HMRClient {
|
|
439
442
|
customListenersMap = /* @__PURE__ */ new Map();
|
440
443
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
441
444
|
messenger;
|
442
|
-
constructor(logger, connection, importUpdatedModule) {
|
443
|
-
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
444
|
-
}
|
445
445
|
async notifyListeners(event, data) {
|
446
446
|
const cbs = this.customListenersMap.get(event);
|
447
447
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
@@ -453,17 +453,20 @@ class HMRClient {
|
|
453
453
|
// but they may have left behind side effects that need to be cleaned up
|
454
454
|
// (.e.g style injections)
|
455
455
|
async prunePaths(paths) {
|
456
|
-
await Promise.all(
|
457
|
-
|
458
|
-
|
459
|
-
return disposer(this.dataMap.get(path));
|
460
|
-
|
456
|
+
await Promise.all(
|
457
|
+
paths.map((path) => {
|
458
|
+
const disposer = this.disposeMap.get(path);
|
459
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
460
|
+
})
|
461
|
+
), paths.forEach((path) => {
|
461
462
|
const fn = this.pruneMap.get(path);
|
462
463
|
fn && fn(this.dataMap.get(path));
|
463
464
|
});
|
464
465
|
}
|
465
466
|
warnFailedUpdate(err, path) {
|
466
|
-
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
467
|
+
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
468
|
+
`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
469
|
+
);
|
467
470
|
}
|
468
471
|
updateQueue = [];
|
469
472
|
pendingUpdateQueue = !1;
|
@@ -484,7 +487,9 @@ class HMRClient {
|
|
484
487
|
if (!mod)
|
485
488
|
return;
|
486
489
|
let fetchedModule;
|
487
|
-
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
490
|
+
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
491
|
+
({ deps }) => deps.includes(acceptedPath)
|
492
|
+
);
|
488
493
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
489
494
|
const disposer = this.disposeMap.get(acceptedPath);
|
490
495
|
disposer && await disposer(this.dataMap.get(acceptedPath));
|
@@ -496,18 +501,22 @@ class HMRClient {
|
|
496
501
|
}
|
497
502
|
return () => {
|
498
503
|
for (const { deps, fn } of qualifiedCallbacks)
|
499
|
-
fn(
|
504
|
+
fn(
|
505
|
+
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
506
|
+
);
|
500
507
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
501
508
|
this.logger.debug(`hot updated: ${loggedPath}`);
|
502
509
|
};
|
503
510
|
}
|
504
511
|
}
|
505
512
|
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
506
|
-
if (!metadata?.isDynamicImport &&
|
513
|
+
if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
|
507
514
|
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
508
515
|
if (missingBindings.length) {
|
509
516
|
const lastBinding = missingBindings[missingBindings.length - 1];
|
510
|
-
throw
|
517
|
+
throw moduleType === "module" ? new SyntaxError(
|
518
|
+
`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`
|
519
|
+
) : 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.
|
511
520
|
CommonJS modules can always be imported via the default export, for example using:
|
512
521
|
|
513
522
|
import pkg from '${rawId}';
|
@@ -516,15 +525,6 @@ const {${missingBindings.join(", ")}} = pkg;
|
|
516
525
|
}
|
517
526
|
}
|
518
527
|
}
|
519
|
-
function proxyGuardOnlyEsm(mod, rawId, metadata) {
|
520
|
-
return metadata?.importedNames?.length ? new Proxy(mod, {
|
521
|
-
get(mod2, prop) {
|
522
|
-
if (prop !== "then" && !(prop in mod2))
|
523
|
-
throw new SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${prop.toString()}'`);
|
524
|
-
return mod2[prop];
|
525
|
-
}
|
526
|
-
}) : mod;
|
527
|
-
}
|
528
528
|
const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
|
529
529
|
}, silentConsole = {
|
530
530
|
debug: noop,
|
@@ -535,9 +535,9 @@ const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_i
|
|
535
535
|
};
|
536
536
|
function createHMRHandler(runner) {
|
537
537
|
const queue = new Queue();
|
538
|
-
return (payload) => queue.enqueue(() =>
|
538
|
+
return (payload) => queue.enqueue(() => handleHotPayload(runner, payload));
|
539
539
|
}
|
540
|
-
async function
|
540
|
+
async function handleHotPayload(runner, payload) {
|
541
541
|
const hmrClient = runner.hmrClient;
|
542
542
|
if (!(!hmrClient || runner.isDestroyed()))
|
543
543
|
switch (payload.type) {
|
@@ -545,20 +545,24 @@ async function handleHMRPayload(runner, payload) {
|
|
545
545
|
hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
|
546
546
|
break;
|
547
547
|
case "update":
|
548
|
-
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
548
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
549
|
+
payload.updates.map(async (update) => {
|
550
|
+
if (update.type === "js-update")
|
551
|
+
return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
552
|
+
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
553
|
+
})
|
554
|
+
), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
553
555
|
break;
|
554
556
|
case "custom": {
|
555
557
|
await hmrClient.notifyListeners(payload.event, payload.data);
|
556
558
|
break;
|
557
559
|
}
|
558
560
|
case "full-reload": {
|
559
|
-
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
560
|
-
|
561
|
-
|
561
|
+
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
562
|
+
runner,
|
563
|
+
getModulesByFile(runner, slash(triggeredBy))
|
564
|
+
) : findAllEntrypoints(runner);
|
565
|
+
if (!clearEntrypoints.size) break;
|
562
566
|
hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
|
563
567
|
for (const id of clearEntrypoints)
|
564
568
|
await runner.import(id);
|
@@ -570,9 +574,11 @@ async function handleHMRPayload(runner, payload) {
|
|
570
574
|
case "error": {
|
571
575
|
await hmrClient.notifyListeners("vite:error", payload);
|
572
576
|
const err = payload.err;
|
573
|
-
hmrClient.logger.error(
|
577
|
+
hmrClient.logger.error(
|
578
|
+
`Internal Server Error
|
574
579
|
${err.message}
|
575
|
-
${err.stack}`
|
580
|
+
${err.stack}`
|
581
|
+
);
|
576
582
|
break;
|
577
583
|
}
|
578
584
|
default:
|
@@ -608,8 +614,7 @@ function getModulesByFile(runner, file) {
|
|
608
614
|
}
|
609
615
|
function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Set(), entrypoints = /* @__PURE__ */ new Set()) {
|
610
616
|
for (const moduleId of modules) {
|
611
|
-
if (visited.has(moduleId))
|
612
|
-
continue;
|
617
|
+
if (visited.has(moduleId)) continue;
|
613
618
|
visited.add(moduleId);
|
614
619
|
const module = runner.moduleCache.getByModuleId(moduleId);
|
615
620
|
if (module.importers && !module.importers.size) {
|
@@ -629,11 +634,12 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
|
|
629
634
|
const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
|
630
635
|
for (const handler of handlers) {
|
631
636
|
const result = handler(...args);
|
632
|
-
if (result)
|
633
|
-
return result;
|
637
|
+
if (result) return result;
|
634
638
|
}
|
635
639
|
return null;
|
636
|
-
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
640
|
+
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
641
|
+
retrieveSourceMapHandlers
|
642
|
+
);
|
637
643
|
let overridden = !1;
|
638
644
|
const originalPrepare = Error.prepareStackTrace;
|
639
645
|
function resetInterceptor(runner, options) {
|
@@ -643,8 +649,7 @@ function interceptStackTrace(runner, options = {}) {
|
|
643
649
|
return overridden || (Error.prepareStackTrace = prepareStackTrace, overridden = !0), moduleGraphs.add(runner.moduleCache), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runner, options);
|
644
650
|
}
|
645
651
|
function supportRelativeURL(file, url) {
|
646
|
-
if (!file)
|
647
|
-
return url;
|
652
|
+
if (!file) return url;
|
648
653
|
const dir = posixDirname(slash(file)), match = /^\w+:\/\/[^/]*/.exec(dir);
|
649
654
|
let protocol = match ? match[0] : "";
|
650
655
|
const startPath = dir.slice(protocol.length);
|
@@ -663,29 +668,24 @@ function getRunnerSourceMap(position) {
|
|
663
668
|
return null;
|
664
669
|
}
|
665
670
|
function retrieveFile(path) {
|
666
|
-
if (path in fileContentsCache)
|
667
|
-
return fileContentsCache[path];
|
671
|
+
if (path in fileContentsCache) return fileContentsCache[path];
|
668
672
|
const content = retrieveFileFromHandlers(path);
|
669
673
|
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
670
674
|
}
|
671
675
|
function retrieveSourceMapURL(source) {
|
672
676
|
const fileData = retrieveFile(source);
|
673
|
-
if (!fileData)
|
674
|
-
return null;
|
677
|
+
if (!fileData) return null;
|
675
678
|
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
676
679
|
let lastMatch, match;
|
677
|
-
for (; match = re.exec(fileData); )
|
678
|
-
lastMatch = match;
|
680
|
+
for (; match = re.exec(fileData); ) lastMatch = match;
|
679
681
|
return lastMatch ? lastMatch[1] : null;
|
680
682
|
}
|
681
683
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
682
684
|
function retrieveSourceMap(source) {
|
683
685
|
const urlAndMap = retrieveSourceMapFromHandlers(source);
|
684
|
-
if (urlAndMap)
|
685
|
-
return urlAndMap;
|
686
|
+
if (urlAndMap) return urlAndMap;
|
686
687
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
687
|
-
if (!sourceMappingURL)
|
688
|
-
return null;
|
688
|
+
if (!sourceMappingURL) return null;
|
689
689
|
let sourceMapData;
|
690
690
|
if (reSourceMap.test(sourceMappingURL)) {
|
691
691
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
@@ -698,8 +698,7 @@ function retrieveSourceMap(source) {
|
|
698
698
|
} : null;
|
699
699
|
}
|
700
700
|
function mapSourcePosition(position) {
|
701
|
-
if (!position.source)
|
702
|
-
return position;
|
701
|
+
if (!position.source) return position;
|
703
702
|
let sourceMap = getRunnerSourceMap(position);
|
704
703
|
if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
|
705
704
|
const urlAndMap = retrieveSourceMap(position.source);
|
@@ -707,7 +706,10 @@ function mapSourcePosition(position) {
|
|
707
706
|
const url = urlAndMap.url;
|
708
707
|
sourceMap = sourceMapCache[position.source] = {
|
709
708
|
url,
|
710
|
-
map: new DecodedMap(
|
709
|
+
map: new DecodedMap(
|
710
|
+
typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map,
|
711
|
+
url
|
712
|
+
)
|
711
713
|
};
|
712
714
|
const contents = sourceMap.map?.map.sourcesContent;
|
713
715
|
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
@@ -726,7 +728,10 @@ function mapSourcePosition(position) {
|
|
726
728
|
if (sourceMap && sourceMap.map && sourceMap.url) {
|
727
729
|
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
728
730
|
if (originalPosition && originalPosition.source != null)
|
729
|
-
return originalPosition.source = supportRelativeURL(
|
731
|
+
return originalPosition.source = supportRelativeURL(
|
732
|
+
sourceMap.url,
|
733
|
+
originalPosition.source
|
734
|
+
), sourceMap.vite && (originalPosition._vite = !0), originalPosition;
|
730
735
|
}
|
731
736
|
return position;
|
732
737
|
}
|
@@ -760,13 +765,14 @@ function CallSiteToString() {
|
|
760
765
|
const functionName = this.getFunctionName();
|
761
766
|
let addSuffix = !0;
|
762
767
|
const isConstructor = this.isConstructor();
|
763
|
-
if (
|
768
|
+
if (this.isToplevel() || isConstructor)
|
769
|
+
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
770
|
+
else {
|
764
771
|
let typeName = this.getTypeName();
|
765
772
|
typeName === "[object Object]" && (typeName = "null");
|
766
773
|
const methodName = this.getMethodName();
|
767
774
|
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>"}`;
|
768
|
-
}
|
769
|
-
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
775
|
+
}
|
770
776
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
771
777
|
}
|
772
778
|
function cloneCallSite(frame) {
|
@@ -823,18 +829,31 @@ function prepareStackTrace(error, stack) {
|
|
823
829
|
function enableSourceMapSupport(runner) {
|
824
830
|
if (runner.options.sourcemapInterceptor === "node") {
|
825
831
|
if (typeof process > "u")
|
826
|
-
throw new TypeError(
|
832
|
+
throw new TypeError(
|
833
|
+
`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`
|
834
|
+
);
|
827
835
|
if (typeof process.setSourceMapsEnabled != "function")
|
828
|
-
throw new TypeError(
|
836
|
+
throw new TypeError(
|
837
|
+
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`
|
838
|
+
);
|
829
839
|
const isEnabledAlready = process.sourceMapsEnabled ?? !1;
|
830
840
|
return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
|
831
841
|
}
|
832
|
-
return interceptStackTrace(
|
842
|
+
return interceptStackTrace(
|
843
|
+
runner,
|
844
|
+
typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
|
845
|
+
);
|
833
846
|
}
|
834
847
|
class ModuleRunner {
|
835
|
-
options
|
836
|
-
|
837
|
-
|
848
|
+
constructor(options, evaluator, debug) {
|
849
|
+
this.options = options, this.evaluator = evaluator, this.debug = debug;
|
850
|
+
const root = this.options.root;
|
851
|
+
this.root = root[root.length - 1] === "/" ? root : `${root}/`, this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root), this.transport = options.transport, typeof options.hmr == "object" && (this.hmrClient = new HMRClient(
|
852
|
+
options.hmr.logger === !1 ? silentConsole : options.hmr.logger || hmrLogger,
|
853
|
+
options.hmr.connection,
|
854
|
+
({ acceptedPath }) => this.import(acceptedPath)
|
855
|
+
), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
856
|
+
}
|
838
857
|
/**
|
839
858
|
* Holds the cache of modules
|
840
859
|
* Keys of the map are ids
|
@@ -845,23 +864,20 @@ class ModuleRunner {
|
|
845
864
|
fileToIdMap = /* @__PURE__ */ new Map();
|
846
865
|
envProxy = new Proxy({}, {
|
847
866
|
get(_, p) {
|
848
|
-
throw new Error(
|
867
|
+
throw new Error(
|
868
|
+
`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`
|
869
|
+
);
|
849
870
|
}
|
850
871
|
});
|
851
872
|
transport;
|
852
873
|
resetSourceMapSupport;
|
874
|
+
root;
|
875
|
+
moduleInfoCache = /* @__PURE__ */ new Map();
|
853
876
|
destroyed = !1;
|
854
|
-
constructor(options, evaluator, debug) {
|
855
|
-
this.options = options, this.evaluator = evaluator, this.debug = debug, this.moduleCache = options.moduleCache ?? new ModuleCacheMap(options.root), this.transport = options.transport, typeof options.hmr == "object" && (this.hmrClient = new HMRClient(options.hmr.logger === !1 ? silentConsole : options.hmr.logger || hmrLogger, options.hmr.connection, ({ acceptedPath, explicitImportRequired, timestamp }) => {
|
856
|
-
const [acceptedPathWithoutQuery, query] = acceptedPath.split("?"), url = acceptedPathWithoutQuery + `?${explicitImportRequired ? "import&" : ""}t=${timestamp}${query ? `&${query}` : ""}`;
|
857
|
-
return this.import(url);
|
858
|
-
}), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
859
|
-
}
|
860
877
|
/**
|
861
878
|
* URL to execute. Accepts file path, server path or id relative to the root.
|
862
879
|
*/
|
863
880
|
async import(url) {
|
864
|
-
url = this.normalizeEntryUrl(url);
|
865
881
|
const fetchedModule = await this.cachedModule(url);
|
866
882
|
return await this.cachedRequest(url, fetchedModule);
|
867
883
|
}
|
@@ -884,33 +900,45 @@ class ModuleRunner {
|
|
884
900
|
isDestroyed() {
|
885
901
|
return this.destroyed;
|
886
902
|
}
|
887
|
-
// we don't use moduleCache.normalize because this URL doesn't have to follow the same rules
|
888
|
-
// this URL is something that user passes down manually, and is later resolved by fetchModule
|
889
|
-
// moduleCache.normalize is used on resolved "file" property
|
890
|
-
normalizeEntryUrl(url) {
|
891
|
-
if (url[0] === ".")
|
892
|
-
return url;
|
893
|
-
url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url = slash(url);
|
894
|
-
const _root = this.options.root, root = _root[_root.length - 1] === "/" ? _root : `${_root}/`;
|
895
|
-
return url.startsWith(root) ? url.slice(root.length - 1) : url[0] === "/" ? url : wrapId(url);
|
896
|
-
}
|
897
903
|
processImport(exports, fetchResult, metadata) {
|
898
904
|
if (!("externalize" in fetchResult))
|
899
905
|
return exports;
|
900
|
-
const { id, type } = fetchResult;
|
901
|
-
return type !== "module" && type !== "commonjs"
|
906
|
+
const { url: id, type } = fetchResult;
|
907
|
+
return type !== "module" && type !== "commonjs" || analyzeImportedModDifference(exports, id, type, metadata), exports;
|
908
|
+
}
|
909
|
+
isCircularModule(mod) {
|
910
|
+
for (const importedFile of mod.imports)
|
911
|
+
if (mod.importers.has(importedFile))
|
912
|
+
return !0;
|
913
|
+
return !1;
|
914
|
+
}
|
915
|
+
isCircularImport(importers, moduleUrl, visited = /* @__PURE__ */ new Set()) {
|
916
|
+
for (const importer of importers) {
|
917
|
+
if (visited.has(importer))
|
918
|
+
continue;
|
919
|
+
if (visited.add(importer), importer === moduleUrl)
|
920
|
+
return !0;
|
921
|
+
const mod = this.moduleCache.getByModuleId(
|
922
|
+
importer
|
923
|
+
);
|
924
|
+
if (mod.importers.size && this.isCircularImport(mod.importers, moduleUrl, visited))
|
925
|
+
return !0;
|
926
|
+
}
|
927
|
+
return !1;
|
902
928
|
}
|
903
|
-
async cachedRequest(id,
|
904
|
-
const meta = mod.meta,
|
905
|
-
if (importee && importers.add(importee), (callstack.includes(
|
929
|
+
async cachedRequest(id, mod_, callstack = [], metadata) {
|
930
|
+
const mod = mod_, meta = mod.meta, moduleUrl = meta.url, { importers } = mod, importee = callstack[callstack.length - 1];
|
931
|
+
if (importee && importers.add(importee), (callstack.includes(moduleUrl) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleUrl)) && mod.exports)
|
906
932
|
return this.processImport(mod.exports, meta, metadata);
|
907
933
|
let debugTimer;
|
908
934
|
this.debug && (debugTimer = setTimeout(() => {
|
909
935
|
const getStack = () => `stack:
|
910
|
-
${[...callstack,
|
936
|
+
${[...callstack, moduleUrl].reverse().map((p) => ` - ${p}`).join(`
|
911
937
|
`)}`;
|
912
|
-
this.debug(
|
913
|
-
${
|
938
|
+
this.debug(
|
939
|
+
`[module runner] module ${moduleUrl} takes over 2s to load.
|
940
|
+
${getStack()}`
|
941
|
+
);
|
914
942
|
}, 2e3));
|
915
943
|
try {
|
916
944
|
if (mod.promise)
|
@@ -922,27 +950,46 @@ ${getStack()}`);
|
|
922
950
|
}
|
923
951
|
}
|
924
952
|
async cachedModule(url, importer) {
|
953
|
+
url = normalizeAbsoluteUrl(url, this.root);
|
954
|
+
const normalized = this.urlToIdMap.get(url);
|
955
|
+
let cachedModule = normalized && this.moduleCache.getByModuleId(normalized);
|
956
|
+
cachedModule || (cachedModule = this.moduleCache.getByModuleId(url));
|
957
|
+
let cached = this.moduleInfoCache.get(url);
|
958
|
+
return cached ? this.debug?.("[module runner] using cached module info for", url) : (cached = this.getModuleInformation(url, importer, cachedModule).finally(
|
959
|
+
() => {
|
960
|
+
this.moduleInfoCache.delete(url);
|
961
|
+
}
|
962
|
+
), this.moduleInfoCache.set(url, cached)), cached;
|
963
|
+
}
|
964
|
+
async getModuleInformation(url, importer, cachedModule) {
|
925
965
|
if (this.destroyed)
|
926
966
|
throw new Error("Vite module runner has been destroyed.");
|
927
|
-
const normalized = this.urlToIdMap.get(url);
|
928
|
-
if (normalized) {
|
929
|
-
const mod2 = this.moduleCache.getByModuleId(normalized);
|
930
|
-
if (mod2.meta)
|
931
|
-
return mod2;
|
932
|
-
}
|
933
967
|
this.debug?.("[module runner] fetching", url);
|
934
|
-
const
|
935
|
-
|
968
|
+
const isCached = !!(typeof cachedModule == "object" && cachedModule.meta), fetchedModule = (
|
969
|
+
// fast return for established externalized pattern
|
970
|
+
url.startsWith("data:") ? { externalize: url, type: "builtin" } : await this.transport.fetchModule(url, importer, {
|
971
|
+
cached: isCached
|
972
|
+
})
|
973
|
+
);
|
974
|
+
if ("cache" in fetchedModule) {
|
975
|
+
if (!cachedModule || !cachedModule.meta)
|
976
|
+
throw new Error(
|
977
|
+
`Module "${url}" was mistakenly invalidated during fetch phase.`
|
978
|
+
);
|
979
|
+
return cachedModule;
|
980
|
+
}
|
981
|
+
const idQuery = url.split("?")[1], query = idQuery ? `?${idQuery}` : "", file = "file" in fetchedModule ? fetchedModule.file : void 0, fileId = file ? `${file}${query}` : url, moduleUrl = this.moduleCache.normalize(fileId), mod = this.moduleCache.getByModuleId(moduleUrl);
|
982
|
+
if ("invalidate" in fetchedModule && fetchedModule.invalidate && this.moduleCache.invalidateModule(mod), fetchedModule.url = moduleUrl, mod.meta = fetchedModule, file) {
|
936
983
|
const fileModules = this.fileToIdMap.get(file) || [];
|
937
|
-
fileModules.push(
|
984
|
+
fileModules.push(moduleUrl), this.fileToIdMap.set(file, fileModules);
|
938
985
|
}
|
939
|
-
return this.urlToIdMap.set(url,
|
986
|
+
return this.urlToIdMap.set(url, moduleUrl), this.urlToIdMap.set(unwrapId(url), moduleUrl), mod;
|
940
987
|
}
|
941
988
|
// override is allowed, consider this a public API
|
942
989
|
async directRequest(id, mod, _callstack) {
|
943
|
-
const fetchResult = mod.meta,
|
944
|
-
const importer = "file" in fetchResult && fetchResult.file ||
|
945
|
-
return this.moduleCache.getByModuleId(resolvedId).importers.add(
|
990
|
+
const fetchResult = mod.meta, moduleUrl = fetchResult.url, callstack = [..._callstack, moduleUrl], request = async (dep, metadata) => {
|
991
|
+
const importer = "file" in fetchResult && fetchResult.file || moduleUrl, fetchedModule = await this.cachedModule(dep, importer), resolvedId = fetchedModule.meta.url;
|
992
|
+
return this.moduleCache.getByModuleId(resolvedId).importers.add(moduleUrl), mod.imports.add(resolvedId), this.cachedRequest(dep, fetchedModule, callstack, metadata);
|
946
993
|
}, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(id), dep)), request(dep, { isDynamicImport: !0 }));
|
947
994
|
if ("externalize" in fetchResult) {
|
948
995
|
const { externalize } = fetchResult;
|
@@ -953,15 +1000,19 @@ ${getStack()}`);
|
|
953
1000
|
const { code, file } = fetchResult;
|
954
1001
|
if (code == null) {
|
955
1002
|
const importer = callstack[callstack.length - 2];
|
956
|
-
throw new Error(
|
1003
|
+
throw new Error(
|
1004
|
+
`[module runner] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`
|
1005
|
+
);
|
957
1006
|
}
|
958
|
-
const modulePath = cleanUrl(file ||
|
1007
|
+
const modulePath = cleanUrl(file || moduleUrl), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
|
959
1008
|
filename: isWindows ? toWindowsPath(filename) : filename,
|
960
1009
|
dirname: isWindows ? toWindowsPath(dirname2) : dirname2,
|
961
1010
|
url: href,
|
962
1011
|
env: this.envProxy,
|
963
|
-
resolve(
|
964
|
-
throw new Error(
|
1012
|
+
resolve(_id, _parent) {
|
1013
|
+
throw new Error(
|
1014
|
+
'[module runner] "import.meta.resolve" is not supported.'
|
1015
|
+
);
|
965
1016
|
},
|
966
1017
|
// should be replaced during transformation
|
967
1018
|
glob() {
|
@@ -979,7 +1030,7 @@ ${getStack()}`);
|
|
979
1030
|
get: () => {
|
980
1031
|
if (!this.hmrClient)
|
981
1032
|
throw new Error("[module runner] HMR client was destroyed.");
|
982
|
-
return this.debug?.("[module runner] creating hmr context for",
|
1033
|
+
return this.debug?.("[module runner] creating hmr context for", moduleUrl), hotContext ||= new HMRContext(this.hmrClient, moduleUrl), hotContext;
|
983
1034
|
},
|
984
1035
|
set: (value) => {
|
985
1036
|
hotContext = value;
|
@@ -1019,23 +1070,33 @@ class ESModulesEvaluator {
|
|
1019
1070
|
ssrExportAllKey,
|
1020
1071
|
// source map should already be inlined by Vite
|
1021
1072
|
'"use strict";' + code
|
1022
|
-
)(
|
1073
|
+
)(
|
1074
|
+
context[ssrModuleExportsKey],
|
1075
|
+
context[ssrImportMetaKey],
|
1076
|
+
context[ssrImportKey],
|
1077
|
+
context[ssrDynamicImportKey],
|
1078
|
+
context[ssrExportAllKey]
|
1079
|
+
), Object.seal(context[ssrModuleExportsKey]);
|
1023
1080
|
}
|
1024
1081
|
runExternalModule(filepath) {
|
1025
1082
|
return import(filepath);
|
1026
1083
|
}
|
1027
1084
|
}
|
1085
|
+
let urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", nanoid = (size = 21) => {
|
1086
|
+
let id = "", i = size;
|
1087
|
+
for (; i--; )
|
1088
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
1089
|
+
return id;
|
1090
|
+
};
|
1028
1091
|
class RemoteRunnerTransport {
|
1029
|
-
options;
|
1030
|
-
rpcPromises = /* @__PURE__ */ new Map();
|
1031
1092
|
constructor(options) {
|
1032
1093
|
this.options = options, this.options.onMessage(async (data) => {
|
1033
|
-
if (typeof data != "object" || !data || !data.__v)
|
1034
|
-
return;
|
1094
|
+
if (typeof data != "object" || !data || !data.__v) return;
|
1035
1095
|
const promise = this.rpcPromises.get(data.i);
|
1036
1096
|
promise && (promise.timeoutId && clearTimeout(promise.timeoutId), this.rpcPromises.delete(data.i), data.e ? promise.reject(data.e) : promise.resolve(data.r));
|
1037
1097
|
});
|
1038
1098
|
}
|
1099
|
+
rpcPromises = /* @__PURE__ */ new Map();
|
1039
1100
|
resolve(method, ...args) {
|
1040
1101
|
const promiseId = nanoid();
|
1041
1102
|
return this.options.send({
|
@@ -1047,7 +1108,11 @@ class RemoteRunnerTransport {
|
|
1047
1108
|
const timeout = this.options.timeout ?? 6e4;
|
1048
1109
|
let timeoutId;
|
1049
1110
|
timeout > 0 && (timeoutId = setTimeout(() => {
|
1050
|
-
this.rpcPromises.delete(promiseId), reject(
|
1111
|
+
this.rpcPromises.delete(promiseId), reject(
|
1112
|
+
new Error(
|
1113
|
+
`${method}(${args.map((arg) => JSON.stringify(arg)).join(", ")}) timed out after ${timeout}ms`
|
1114
|
+
)
|
1115
|
+
);
|
1051
1116
|
}, timeout), timeoutId?.unref?.()), this.rpcPromises.set(promiseId, { resolve: resolve2, reject, timeoutId });
|
1052
1117
|
});
|
1053
1118
|
}
|
@@ -1055,13 +1120,6 @@ class RemoteRunnerTransport {
|
|
1055
1120
|
return this.resolve("fetchModule", id, importer);
|
1056
1121
|
}
|
1057
1122
|
}
|
1058
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
1059
|
-
function nanoid(size = 21) {
|
1060
|
-
let id = "", i = size;
|
1061
|
-
for (; i--; )
|
1062
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
1063
|
-
return id;
|
1064
|
-
}
|
1065
1123
|
export {
|
1066
1124
|
ESModulesEvaluator,
|
1067
1125
|
ModuleCacheMap,
|