vite 6.0.0-alpha.2 → 6.0.0-alpha.21
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 +112 -203
- package/client.d.ts +12 -0
- package/dist/client/client.mjs +614 -611
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep-DK04Q0H9.js → dep-B35KR9PC.js} +1 -1
- package/dist/node/chunks/{dep-DKZVy3_n.js → dep-BAOcN7N1.js} +165 -968
- package/dist/node/chunks/{dep-CrWVpuYf.js → dep-D-7KCb9p.js} +32 -2
- package/dist/node/chunks/{dep-E4cF1RpV.js → dep-D2vSWyBt.js} +37449 -39030
- package/dist/node/cli.js +260 -265
- package/dist/node/constants.js +108 -84
- package/dist/node/index.d.ts +2167 -2017
- package/dist/node/index.js +128 -258
- package/dist/node/module-runner.d.ts +33 -18
- package/dist/node/module-runner.js +275 -206
- package/dist/node-cjs/publicUtils.cjs +637 -657
- package/index.cjs +0 -2
- package/package.json +32 -29
- 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
@@ -51,24 +51,22 @@ function normalizeString(path, allowAboveRoot) {
|
|
51
51
|
char = "/";
|
52
52
|
}
|
53
53
|
if (char === "/") {
|
54
|
-
if (!(lastSlash === index - 1 || dots === 1))
|
55
|
-
if (
|
56
|
-
if (res.length
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
continue;
|
64
|
-
}
|
54
|
+
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
55
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
56
|
+
if (res.length > 2) {
|
57
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
58
|
+
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
59
|
+
continue;
|
60
|
+
} else if (res.length > 0) {
|
61
|
+
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
62
|
+
continue;
|
65
63
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
}
|
65
|
+
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
66
|
+
} else
|
67
|
+
res.length > 0 ? res += `/${path.slice(lastSlash + 1, index)}` : res = path.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
69
68
|
lastSlash = index, dots = 0;
|
70
|
-
} else
|
71
|
-
char === "." && dots !== -1 ? ++dots : dots = -1;
|
69
|
+
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
72
70
|
}
|
73
71
|
return res;
|
74
72
|
}
|
@@ -77,7 +75,11 @@ const isAbsolute = function(p) {
|
|
77
75
|
}, dirname = function(p) {
|
78
76
|
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
79
77
|
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
80
|
-
}
|
78
|
+
};
|
79
|
+
function normalizeAbsoluteUrl(url, root) {
|
80
|
+
return url = slash(url), url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url.startsWith(root) && (url = url.slice(root.length - 1)), url;
|
81
|
+
}
|
82
|
+
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;
|
81
83
|
function encodePathChars(filepath) {
|
82
84
|
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(`
|
83
85
|
`) !== -1 && (filepath = filepath.replace(newlineRegEx, "%0A")), filepath.indexOf("\r") !== -1 && (filepath = filepath.replace(carriageReturnRegEx, "%0D")), filepath.indexOf(" ") !== -1 && (filepath = filepath.replace(tabRegEx, "%09")), filepath;
|
@@ -96,38 +98,46 @@ for (let i = 0; i < chars.length; i++) {
|
|
96
98
|
const c = chars.charCodeAt(i);
|
97
99
|
intToChar[i] = c, charToInt[c] = i;
|
98
100
|
}
|
99
|
-
function
|
100
|
-
const state = new Int32Array(5), decoded = [];
|
101
|
-
let index = 0;
|
102
|
-
do {
|
103
|
-
const semi = indexOf(mappings, index), line = [];
|
104
|
-
let sorted = !0, lastCol = 0;
|
105
|
-
state[0] = 0;
|
106
|
-
for (let i = index; i < semi; i++) {
|
107
|
-
let seg;
|
108
|
-
i = decodeInteger(mappings, i, state, 0);
|
109
|
-
const col = state[0];
|
110
|
-
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);
|
111
|
-
}
|
112
|
-
sorted || sort(line), decoded.push(line), index = semi + 1;
|
113
|
-
} while (index <= mappings.length);
|
114
|
-
return decoded;
|
115
|
-
}
|
116
|
-
function indexOf(mappings, index) {
|
117
|
-
const idx = mappings.indexOf(";", index);
|
118
|
-
return idx === -1 ? mappings.length : idx;
|
119
|
-
}
|
120
|
-
function decodeInteger(mappings, pos, state, j) {
|
101
|
+
function decodeInteger(reader, relative) {
|
121
102
|
let value = 0, shift = 0, integer = 0;
|
122
103
|
do {
|
123
|
-
const c =
|
104
|
+
const c = reader.next();
|
124
105
|
integer = charToInt[c], value |= (integer & 31) << shift, shift += 5;
|
125
106
|
} while (integer & 32);
|
126
107
|
const shouldNegate = value & 1;
|
127
|
-
return value >>>= 1, shouldNegate && (value = -2147483648 | -value),
|
108
|
+
return value >>>= 1, shouldNegate && (value = -2147483648 | -value), relative + value;
|
109
|
+
}
|
110
|
+
function hasMoreVlq(reader, max) {
|
111
|
+
return reader.pos >= max ? !1 : reader.peek() !== comma;
|
128
112
|
}
|
129
|
-
|
130
|
-
|
113
|
+
class StringReader {
|
114
|
+
constructor(buffer) {
|
115
|
+
this.pos = 0, this.buffer = buffer;
|
116
|
+
}
|
117
|
+
next() {
|
118
|
+
return this.buffer.charCodeAt(this.pos++);
|
119
|
+
}
|
120
|
+
peek() {
|
121
|
+
return this.buffer.charCodeAt(this.pos);
|
122
|
+
}
|
123
|
+
indexOf(char) {
|
124
|
+
const { buffer, pos } = this, idx = buffer.indexOf(char, pos);
|
125
|
+
return idx === -1 ? buffer.length : idx;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
function decode(mappings) {
|
129
|
+
const { length } = mappings, reader = new StringReader(mappings), decoded = [];
|
130
|
+
let genColumn = 0, sourcesIndex = 0, sourceLine = 0, sourceColumn = 0, namesIndex = 0;
|
131
|
+
do {
|
132
|
+
const semi = reader.indexOf(";"), line = [];
|
133
|
+
let sorted = !0, lastCol = 0;
|
134
|
+
for (genColumn = 0; reader.pos < semi; ) {
|
135
|
+
let seg;
|
136
|
+
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++;
|
137
|
+
}
|
138
|
+
sorted || sort(line), decoded.push(line), reader.pos = semi + 1;
|
139
|
+
} while (reader.pos <= length);
|
140
|
+
return decoded;
|
131
141
|
}
|
132
142
|
function sort(line) {
|
133
143
|
line.sort(sortComparator);
|
@@ -200,7 +210,13 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
200
210
|
return found ? index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index) : bias === LEAST_UPPER_BOUND && index++, index === -1 || index === segments.length ? -1 : index;
|
201
211
|
}
|
202
212
|
class DecodedMap {
|
203
|
-
map
|
213
|
+
constructor(map, from) {
|
214
|
+
this.map = map;
|
215
|
+
const { mappings, names, sources } = map;
|
216
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map(
|
217
|
+
(s) => posixResolve(s || "", from)
|
218
|
+
);
|
219
|
+
}
|
204
220
|
_encoded;
|
205
221
|
_decoded;
|
206
222
|
_decodedMemo;
|
@@ -208,11 +224,6 @@ class DecodedMap {
|
|
208
224
|
version;
|
209
225
|
names = [];
|
210
226
|
resolvedSources;
|
211
|
-
constructor(map, from) {
|
212
|
-
this.map = map;
|
213
|
-
const { mappings, names, sources } = map;
|
214
|
-
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
215
|
-
}
|
216
227
|
}
|
217
228
|
function memoizedState() {
|
218
229
|
return {
|
@@ -225,7 +236,9 @@ function getOriginalPosition(map, needle) {
|
|
225
236
|
const result = originalPositionFor(map, needle);
|
226
237
|
return result.column == null ? null : result;
|
227
238
|
}
|
228
|
-
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
239
|
+
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
240
|
+
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`
|
241
|
+
);
|
229
242
|
class ModuleCacheMap extends Map {
|
230
243
|
root;
|
231
244
|
constructor(root, entries) {
|
@@ -251,7 +264,8 @@ class ModuleCacheMap extends Map {
|
|
251
264
|
const mod = super.get(modulePath);
|
252
265
|
return mod.imports || Object.assign(mod, {
|
253
266
|
imports: /* @__PURE__ */ new Set(),
|
254
|
-
importers: /* @__PURE__ */ new Set()
|
267
|
+
importers: /* @__PURE__ */ new Set(),
|
268
|
+
timestamp: 0
|
255
269
|
}), mod;
|
256
270
|
}
|
257
271
|
get(fsPath) {
|
@@ -263,8 +277,11 @@ class ModuleCacheMap extends Map {
|
|
263
277
|
delete(fsPath) {
|
264
278
|
return this.deleteByModuleId(this.normalize(fsPath));
|
265
279
|
}
|
266
|
-
|
280
|
+
invalidateUrl(id) {
|
267
281
|
const module = this.get(id);
|
282
|
+
this.invalidateModule(module);
|
283
|
+
}
|
284
|
+
invalidateModule(module) {
|
268
285
|
module.evaluated = !1, module.meta = void 0, module.map = void 0, module.promise = void 0, module.exports = void 0, module.imports?.clear();
|
269
286
|
}
|
270
287
|
/**
|
@@ -273,11 +290,10 @@ class ModuleCacheMap extends Map {
|
|
273
290
|
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
274
291
|
for (const _id of ids) {
|
275
292
|
const id = this.normalize(_id);
|
276
|
-
if (invalidated.has(id))
|
277
|
-
continue;
|
293
|
+
if (invalidated.has(id)) continue;
|
278
294
|
invalidated.add(id);
|
279
295
|
const mod = super.get(id);
|
280
|
-
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.
|
296
|
+
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidateUrl(id);
|
281
297
|
}
|
282
298
|
return invalidated;
|
283
299
|
}
|
@@ -287,8 +303,7 @@ class ModuleCacheMap extends Map {
|
|
287
303
|
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
288
304
|
for (const _id of ids) {
|
289
305
|
const id = this.normalize(_id);
|
290
|
-
if (invalidated.has(id))
|
291
|
-
continue;
|
306
|
+
if (invalidated.has(id)) continue;
|
292
307
|
invalidated.add(id);
|
293
308
|
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
294
309
|
subIds.length && this.invalidateSubDepTree(subIds, invalidated), super.delete(id);
|
@@ -297,28 +312,23 @@ class ModuleCacheMap extends Map {
|
|
297
312
|
}
|
298
313
|
getSourceMap(moduleId) {
|
299
314
|
const mod = this.get(moduleId);
|
300
|
-
if (mod.map)
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
if (!mapString)
|
306
|
-
return null;
|
315
|
+
if (mod.map) return mod.map;
|
316
|
+
if (!mod.meta || !("code" in mod.meta)) return null;
|
317
|
+
const mapString = MODULE_RUNNER_SOURCEMAPPING_REGEXP.exec(
|
318
|
+
mod.meta.code
|
319
|
+
)?.[1];
|
320
|
+
if (!mapString) return null;
|
307
321
|
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
308
322
|
return mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile), mod.map;
|
309
323
|
}
|
310
324
|
}
|
311
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
325
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test", "node:sqlite"]);
|
312
326
|
function normalizeModuleId(file, root) {
|
313
|
-
if (prefixedBuiltins.has(file))
|
314
|
-
return file;
|
327
|
+
if (prefixedBuiltins.has(file)) return file;
|
315
328
|
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
316
329
|
return unixFile.startsWith(root) && (unixFile = unixFile.slice(root.length - 1)), unixFile.replace(/^file:\//, "/");
|
317
330
|
}
|
318
331
|
class HMRContext {
|
319
|
-
hmrClient;
|
320
|
-
ownerPath;
|
321
|
-
newListeners;
|
322
332
|
constructor(hmrClient, ownerPath) {
|
323
333
|
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
324
334
|
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
@@ -327,10 +337,14 @@ class HMRContext {
|
|
327
337
|
if (staleListeners)
|
328
338
|
for (const [event, staleFns] of staleListeners) {
|
329
339
|
const listeners = hmrClient.customListenersMap.get(event);
|
330
|
-
listeners && hmrClient.customListenersMap.set(
|
340
|
+
listeners && hmrClient.customListenersMap.set(
|
341
|
+
event,
|
342
|
+
listeners.filter((l) => !staleFns.includes(l))
|
343
|
+
);
|
331
344
|
}
|
332
345
|
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
333
346
|
}
|
347
|
+
newListeners;
|
334
348
|
get data() {
|
335
349
|
return this.hmrClient.dataMap.get(this.ownerPath);
|
336
350
|
}
|
@@ -366,7 +380,9 @@ class HMRContext {
|
|
366
380
|
}), this.send("vite:invalidate", {
|
367
381
|
path: this.ownerPath,
|
368
382
|
message
|
369
|
-
}), this.hmrClient.logger.debug(
|
383
|
+
}), this.hmrClient.logger.debug(
|
384
|
+
`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
385
|
+
);
|
370
386
|
}
|
371
387
|
on(event, cb) {
|
372
388
|
const addToMap = (map) => {
|
@@ -390,7 +406,9 @@ class HMRContext {
|
|
390
406
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
391
407
|
}
|
392
408
|
send(event, data) {
|
393
|
-
this.hmrClient.messenger.send(
|
409
|
+
this.hmrClient.messenger.send(
|
410
|
+
JSON.stringify({ type: "custom", event, data })
|
411
|
+
);
|
394
412
|
}
|
395
413
|
acceptDeps(deps, callback = () => {
|
396
414
|
}) {
|
@@ -405,7 +423,6 @@ class HMRContext {
|
|
405
423
|
}
|
406
424
|
}
|
407
425
|
class HMRMessenger {
|
408
|
-
connection;
|
409
426
|
constructor(connection) {
|
410
427
|
this.connection = connection;
|
411
428
|
}
|
@@ -418,8 +435,9 @@ class HMRMessenger {
|
|
418
435
|
}
|
419
436
|
}
|
420
437
|
class HMRClient {
|
421
|
-
logger
|
422
|
-
|
438
|
+
constructor(logger, connection, importUpdatedModule) {
|
439
|
+
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
440
|
+
}
|
423
441
|
hotModulesMap = /* @__PURE__ */ new Map();
|
424
442
|
disposeMap = /* @__PURE__ */ new Map();
|
425
443
|
pruneMap = /* @__PURE__ */ new Map();
|
@@ -427,9 +445,6 @@ class HMRClient {
|
|
427
445
|
customListenersMap = /* @__PURE__ */ new Map();
|
428
446
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
429
447
|
messenger;
|
430
|
-
constructor(logger, connection, importUpdatedModule) {
|
431
|
-
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
432
|
-
}
|
433
448
|
async notifyListeners(event, data) {
|
434
449
|
const cbs = this.customListenersMap.get(event);
|
435
450
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
@@ -441,17 +456,20 @@ class HMRClient {
|
|
441
456
|
// but they may have left behind side effects that need to be cleaned up
|
442
457
|
// (.e.g style injections)
|
443
458
|
async prunePaths(paths) {
|
444
|
-
await Promise.all(
|
445
|
-
|
446
|
-
|
447
|
-
return disposer(this.dataMap.get(path));
|
448
|
-
|
459
|
+
await Promise.all(
|
460
|
+
paths.map((path) => {
|
461
|
+
const disposer = this.disposeMap.get(path);
|
462
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
463
|
+
})
|
464
|
+
), paths.forEach((path) => {
|
449
465
|
const fn = this.pruneMap.get(path);
|
450
466
|
fn && fn(this.dataMap.get(path));
|
451
467
|
});
|
452
468
|
}
|
453
469
|
warnFailedUpdate(err, path) {
|
454
|
-
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
470
|
+
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
471
|
+
`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
472
|
+
);
|
455
473
|
}
|
456
474
|
updateQueue = [];
|
457
475
|
pendingUpdateQueue = !1;
|
@@ -472,7 +490,9 @@ class HMRClient {
|
|
472
490
|
if (!mod)
|
473
491
|
return;
|
474
492
|
let fetchedModule;
|
475
|
-
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
493
|
+
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
494
|
+
({ deps }) => deps.includes(acceptedPath)
|
495
|
+
);
|
476
496
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
477
497
|
const disposer = this.disposeMap.get(acceptedPath);
|
478
498
|
disposer && await disposer(this.dataMap.get(acceptedPath));
|
@@ -484,18 +504,22 @@ class HMRClient {
|
|
484
504
|
}
|
485
505
|
return () => {
|
486
506
|
for (const { deps, fn } of qualifiedCallbacks)
|
487
|
-
fn(
|
507
|
+
fn(
|
508
|
+
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
509
|
+
);
|
488
510
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
489
|
-
this.logger.debug(`
|
511
|
+
this.logger.debug(`hot updated: ${loggedPath}`);
|
490
512
|
};
|
491
513
|
}
|
492
514
|
}
|
493
515
|
function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
494
|
-
if (!metadata?.isDynamicImport &&
|
516
|
+
if (!metadata?.isDynamicImport && metadata?.importedNames?.length) {
|
495
517
|
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
496
518
|
if (missingBindings.length) {
|
497
519
|
const lastBinding = missingBindings[missingBindings.length - 1];
|
498
|
-
throw
|
520
|
+
throw moduleType === "module" ? new SyntaxError(
|
521
|
+
`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`
|
522
|
+
) : 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.
|
499
523
|
CommonJS modules can always be imported via the default export, for example using:
|
500
524
|
|
501
525
|
import pkg from '${rawId}';
|
@@ -504,47 +528,45 @@ const {${missingBindings.join(", ")}} = pkg;
|
|
504
528
|
}
|
505
529
|
}
|
506
530
|
}
|
507
|
-
function proxyGuardOnlyEsm(mod, rawId, metadata) {
|
508
|
-
return metadata?.importedNames?.length ? new Proxy(mod, {
|
509
|
-
get(mod2, prop) {
|
510
|
-
if (prop !== "then" && !(prop in mod2))
|
511
|
-
throw new SyntaxError(`[vite] The requested module '${rawId}' does not provide an export named '${prop.toString()}'`);
|
512
|
-
return mod2[prop];
|
513
|
-
}
|
514
|
-
}) : mod;
|
515
|
-
}
|
516
531
|
const ssrModuleExportsKey = "__vite_ssr_exports__", ssrImportKey = "__vite_ssr_import__", ssrDynamicImportKey = "__vite_ssr_dynamic_import__", ssrExportAllKey = "__vite_ssr_exportAll__", ssrImportMetaKey = "__vite_ssr_import_meta__", noop = () => {
|
517
532
|
}, silentConsole = {
|
518
533
|
debug: noop,
|
519
534
|
error: noop
|
535
|
+
}, hmrLogger = {
|
536
|
+
debug: (...msg) => console.log("[vite]", ...msg),
|
537
|
+
error: (error) => console.log("[vite]", error)
|
520
538
|
};
|
521
539
|
function createHMRHandler(runner) {
|
522
540
|
const queue = new Queue();
|
523
|
-
return (payload) => queue.enqueue(() =>
|
541
|
+
return (payload) => queue.enqueue(() => handleHotPayload(runner, payload));
|
524
542
|
}
|
525
|
-
async function
|
543
|
+
async function handleHotPayload(runner, payload) {
|
526
544
|
const hmrClient = runner.hmrClient;
|
527
545
|
if (!(!hmrClient || runner.isDestroyed()))
|
528
546
|
switch (payload.type) {
|
529
547
|
case "connected":
|
530
|
-
hmrClient.logger.debug("
|
548
|
+
hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
|
531
549
|
break;
|
532
550
|
case "update":
|
533
|
-
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
551
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
552
|
+
payload.updates.map(async (update) => {
|
553
|
+
if (update.type === "js-update")
|
554
|
+
return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
555
|
+
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
556
|
+
})
|
557
|
+
), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
538
558
|
break;
|
539
559
|
case "custom": {
|
540
560
|
await hmrClient.notifyListeners(payload.event, payload.data);
|
541
561
|
break;
|
542
562
|
}
|
543
563
|
case "full-reload": {
|
544
|
-
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
545
|
-
|
546
|
-
|
547
|
-
|
564
|
+
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
565
|
+
runner,
|
566
|
+
getModulesByFile(runner, slash(triggeredBy))
|
567
|
+
) : findAllEntrypoints(runner);
|
568
|
+
if (!clearEntrypoints.size) break;
|
569
|
+
hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
|
548
570
|
for (const id of clearEntrypoints)
|
549
571
|
await runner.import(id);
|
550
572
|
break;
|
@@ -555,9 +577,11 @@ async function handleHMRPayload(runner, payload) {
|
|
555
577
|
case "error": {
|
556
578
|
await hmrClient.notifyListeners("vite:error", payload);
|
557
579
|
const err = payload.err;
|
558
|
-
hmrClient.logger.error(
|
580
|
+
hmrClient.logger.error(
|
581
|
+
`Internal Server Error
|
559
582
|
${err.message}
|
560
|
-
${err.stack}`
|
583
|
+
${err.stack}`
|
584
|
+
);
|
561
585
|
break;
|
562
586
|
}
|
563
587
|
default:
|
@@ -593,8 +617,7 @@ function getModulesByFile(runner, file) {
|
|
593
617
|
}
|
594
618
|
function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Set(), entrypoints = /* @__PURE__ */ new Set()) {
|
595
619
|
for (const moduleId of modules) {
|
596
|
-
if (visited.has(moduleId))
|
597
|
-
continue;
|
620
|
+
if (visited.has(moduleId)) continue;
|
598
621
|
visited.add(moduleId);
|
599
622
|
const module = runner.moduleCache.getByModuleId(moduleId);
|
600
623
|
if (module.importers && !module.importers.size) {
|
@@ -614,11 +637,12 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
|
|
614
637
|
const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
|
615
638
|
for (const handler of handlers) {
|
616
639
|
const result = handler(...args);
|
617
|
-
if (result)
|
618
|
-
return result;
|
640
|
+
if (result) return result;
|
619
641
|
}
|
620
642
|
return null;
|
621
|
-
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
643
|
+
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
644
|
+
retrieveSourceMapHandlers
|
645
|
+
);
|
622
646
|
let overridden = !1;
|
623
647
|
const originalPrepare = Error.prepareStackTrace;
|
624
648
|
function resetInterceptor(runner, options) {
|
@@ -628,8 +652,7 @@ function interceptStackTrace(runner, options = {}) {
|
|
628
652
|
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);
|
629
653
|
}
|
630
654
|
function supportRelativeURL(file, url) {
|
631
|
-
if (!file)
|
632
|
-
return url;
|
655
|
+
if (!file) return url;
|
633
656
|
const dir = posixDirname(slash(file)), match = /^\w+:\/\/[^/]*/.exec(dir);
|
634
657
|
let protocol = match ? match[0] : "";
|
635
658
|
const startPath = dir.slice(protocol.length);
|
@@ -648,29 +671,24 @@ function getRunnerSourceMap(position) {
|
|
648
671
|
return null;
|
649
672
|
}
|
650
673
|
function retrieveFile(path) {
|
651
|
-
if (path in fileContentsCache)
|
652
|
-
return fileContentsCache[path];
|
674
|
+
if (path in fileContentsCache) return fileContentsCache[path];
|
653
675
|
const content = retrieveFileFromHandlers(path);
|
654
676
|
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
655
677
|
}
|
656
678
|
function retrieveSourceMapURL(source) {
|
657
679
|
const fileData = retrieveFile(source);
|
658
|
-
if (!fileData)
|
659
|
-
return null;
|
680
|
+
if (!fileData) return null;
|
660
681
|
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
661
682
|
let lastMatch, match;
|
662
|
-
for (; match = re.exec(fileData); )
|
663
|
-
lastMatch = match;
|
683
|
+
for (; match = re.exec(fileData); ) lastMatch = match;
|
664
684
|
return lastMatch ? lastMatch[1] : null;
|
665
685
|
}
|
666
686
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
667
687
|
function retrieveSourceMap(source) {
|
668
688
|
const urlAndMap = retrieveSourceMapFromHandlers(source);
|
669
|
-
if (urlAndMap)
|
670
|
-
return urlAndMap;
|
689
|
+
if (urlAndMap) return urlAndMap;
|
671
690
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
672
|
-
if (!sourceMappingURL)
|
673
|
-
return null;
|
691
|
+
if (!sourceMappingURL) return null;
|
674
692
|
let sourceMapData;
|
675
693
|
if (reSourceMap.test(sourceMappingURL)) {
|
676
694
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
@@ -683,8 +701,7 @@ function retrieveSourceMap(source) {
|
|
683
701
|
} : null;
|
684
702
|
}
|
685
703
|
function mapSourcePosition(position) {
|
686
|
-
if (!position.source)
|
687
|
-
return position;
|
704
|
+
if (!position.source) return position;
|
688
705
|
let sourceMap = getRunnerSourceMap(position);
|
689
706
|
if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
|
690
707
|
const urlAndMap = retrieveSourceMap(position.source);
|
@@ -692,7 +709,10 @@ function mapSourcePosition(position) {
|
|
692
709
|
const url = urlAndMap.url;
|
693
710
|
sourceMap = sourceMapCache[position.source] = {
|
694
711
|
url,
|
695
|
-
map: new DecodedMap(
|
712
|
+
map: new DecodedMap(
|
713
|
+
typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map,
|
714
|
+
url
|
715
|
+
)
|
696
716
|
};
|
697
717
|
const contents = sourceMap.map?.map.sourcesContent;
|
698
718
|
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
@@ -711,7 +731,10 @@ function mapSourcePosition(position) {
|
|
711
731
|
if (sourceMap && sourceMap.map && sourceMap.url) {
|
712
732
|
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
713
733
|
if (originalPosition && originalPosition.source != null)
|
714
|
-
return originalPosition.source = supportRelativeURL(
|
734
|
+
return originalPosition.source = supportRelativeURL(
|
735
|
+
sourceMap.url,
|
736
|
+
originalPosition.source
|
737
|
+
), sourceMap.vite && (originalPosition._vite = !0), originalPosition;
|
715
738
|
}
|
716
739
|
return position;
|
717
740
|
}
|
@@ -745,13 +768,14 @@ function CallSiteToString() {
|
|
745
768
|
const functionName = this.getFunctionName();
|
746
769
|
let addSuffix = !0;
|
747
770
|
const isConstructor = this.isConstructor();
|
748
|
-
if (
|
771
|
+
if (this.isToplevel() || isConstructor)
|
772
|
+
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
773
|
+
else {
|
749
774
|
let typeName = this.getTypeName();
|
750
775
|
typeName === "[object Object]" && (typeName = "null");
|
751
776
|
const methodName = this.getMethodName();
|
752
777
|
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>"}`;
|
753
|
-
}
|
754
|
-
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
778
|
+
}
|
755
779
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
756
780
|
}
|
757
781
|
function cloneCallSite(frame) {
|
@@ -808,37 +832,50 @@ function prepareStackTrace(error, stack) {
|
|
808
832
|
function enableSourceMapSupport(runner) {
|
809
833
|
if (runner.options.sourcemapInterceptor === "node") {
|
810
834
|
if (typeof process > "u")
|
811
|
-
throw new TypeError(
|
835
|
+
throw new TypeError(
|
836
|
+
`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`
|
837
|
+
);
|
812
838
|
if (typeof process.setSourceMapsEnabled != "function")
|
813
|
-
throw new TypeError(
|
839
|
+
throw new TypeError(
|
840
|
+
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`
|
841
|
+
);
|
814
842
|
const isEnabledAlready = process.sourceMapsEnabled ?? !1;
|
815
843
|
return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
|
816
844
|
}
|
817
|
-
return interceptStackTrace(
|
845
|
+
return interceptStackTrace(
|
846
|
+
runner,
|
847
|
+
typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
|
848
|
+
);
|
818
849
|
}
|
819
850
|
class ModuleRunner {
|
820
|
-
options
|
821
|
-
|
822
|
-
|
851
|
+
constructor(options, evaluator, debug) {
|
852
|
+
this.options = options, this.evaluator = evaluator, this.debug = debug;
|
853
|
+
const root = this.options.root;
|
854
|
+
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(
|
855
|
+
options.hmr.logger === !1 ? silentConsole : options.hmr.logger || hmrLogger,
|
856
|
+
options.hmr.connection,
|
857
|
+
({ acceptedPath }) => this.import(acceptedPath)
|
858
|
+
), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
859
|
+
}
|
823
860
|
/**
|
824
861
|
* Holds the cache of modules
|
825
862
|
* Keys of the map are ids
|
826
863
|
*/
|
827
864
|
moduleCache;
|
828
865
|
hmrClient;
|
829
|
-
|
866
|
+
urlToIdMap = /* @__PURE__ */ new Map();
|
830
867
|
fileToIdMap = /* @__PURE__ */ new Map();
|
831
868
|
envProxy = new Proxy({}, {
|
832
869
|
get(_, p) {
|
833
|
-
throw new Error(
|
870
|
+
throw new Error(
|
871
|
+
`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`
|
872
|
+
);
|
834
873
|
}
|
835
874
|
});
|
836
875
|
transport;
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
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 || console, options.hmr.connection, ({ acceptedPath, invalidates }) => (this.moduleCache.invalidate(acceptedPath), invalidates && this.invalidateFiles(invalidates), this.import(acceptedPath))), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this._resetSourceMapSupport = enableSourceMapSupport(this));
|
841
|
-
}
|
876
|
+
resetSourceMapSupport;
|
877
|
+
root;
|
878
|
+
destroyed = !1;
|
842
879
|
/**
|
843
880
|
* URL to execute. Accepts file path, server path or id relative to the root.
|
844
881
|
*/
|
@@ -851,87 +888,108 @@ class ModuleRunner {
|
|
851
888
|
* Clear all caches including HMR listeners.
|
852
889
|
*/
|
853
890
|
clearCache() {
|
854
|
-
this.moduleCache.clear(), this.
|
891
|
+
this.moduleCache.clear(), this.urlToIdMap.clear(), this.hmrClient?.clear();
|
855
892
|
}
|
856
893
|
/**
|
857
894
|
* Clears all caches, removes all HMR listeners, and resets source map support.
|
858
895
|
* This method doesn't stop the HMR connection.
|
859
896
|
*/
|
860
897
|
async destroy() {
|
861
|
-
this.
|
898
|
+
this.resetSourceMapSupport?.(), this.clearCache(), this.hmrClient = void 0, this.destroyed = !0;
|
862
899
|
}
|
863
900
|
/**
|
864
901
|
* Returns `true` if the runtime has been destroyed by calling `destroy()` method.
|
865
902
|
*/
|
866
903
|
isDestroyed() {
|
867
|
-
return this.
|
868
|
-
}
|
869
|
-
// map files to modules and invalidate them
|
870
|
-
invalidateFiles(files) {
|
871
|
-
files.forEach((file) => {
|
872
|
-
const ids = this.fileToIdMap.get(file);
|
873
|
-
ids && ids.forEach((id) => this.moduleCache.invalidate(id));
|
874
|
-
});
|
904
|
+
return this.destroyed;
|
875
905
|
}
|
876
906
|
// we don't use moduleCache.normalize because this URL doesn't have to follow the same rules
|
877
907
|
// this URL is something that user passes down manually, and is later resolved by fetchModule
|
878
908
|
// moduleCache.normalize is used on resolved "file" property
|
879
909
|
normalizeEntryUrl(url) {
|
880
|
-
|
881
|
-
return url;
|
882
|
-
url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url = slash(url);
|
883
|
-
const _root = this.options.root, root = _root[_root.length - 1] === "/" ? _root : `${_root}/`;
|
884
|
-
return url.startsWith(root) ? url.slice(root.length - 1) : url[0] === "/" ? url : wrapId(url);
|
910
|
+
return url[0] === "." ? url : (url = normalizeAbsoluteUrl(url, this.root), url[0] === "/" ? url : wrapId(url));
|
885
911
|
}
|
886
912
|
processImport(exports, fetchResult, metadata) {
|
887
913
|
if (!("externalize" in fetchResult))
|
888
914
|
return exports;
|
889
915
|
const { id, type } = fetchResult;
|
890
|
-
return type !== "module" && type !== "commonjs"
|
916
|
+
return type !== "module" && type !== "commonjs" || analyzeImportedModDifference(exports, id, type, metadata), exports;
|
917
|
+
}
|
918
|
+
isCircularModule(mod) {
|
919
|
+
for (const importedFile of mod.imports)
|
920
|
+
if (mod.importers.has(importedFile))
|
921
|
+
return !0;
|
922
|
+
return !1;
|
923
|
+
}
|
924
|
+
isCircularImport(importers, moduleId, visited = /* @__PURE__ */ new Set()) {
|
925
|
+
for (const importer of importers) {
|
926
|
+
if (visited.has(importer))
|
927
|
+
continue;
|
928
|
+
if (visited.add(importer), importer === moduleId)
|
929
|
+
return !0;
|
930
|
+
const mod = this.moduleCache.getByModuleId(
|
931
|
+
importer
|
932
|
+
);
|
933
|
+
if (mod.importers.size && this.isCircularImport(mod.importers, moduleId, visited))
|
934
|
+
return !0;
|
935
|
+
}
|
936
|
+
return !1;
|
891
937
|
}
|
892
|
-
async cachedRequest(id,
|
893
|
-
const
|
894
|
-
if (importee && importers.add(importee), (callstack.includes(moduleId) ||
|
895
|
-
return this.processImport(mod.exports,
|
938
|
+
async cachedRequest(id, mod_, callstack = [], metadata) {
|
939
|
+
const mod = mod_, meta = mod.meta, moduleId = meta.id, { importers } = mod, importee = callstack[callstack.length - 1];
|
940
|
+
if (importee && importers.add(importee), (callstack.includes(moduleId) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleId)) && mod.exports)
|
941
|
+
return this.processImport(mod.exports, meta, metadata);
|
896
942
|
let debugTimer;
|
897
943
|
this.debug && (debugTimer = setTimeout(() => {
|
898
944
|
const getStack = () => `stack:
|
899
945
|
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(`
|
900
946
|
`)}`;
|
901
|
-
this.debug(
|
902
|
-
${
|
947
|
+
this.debug(
|
948
|
+
`[module runner] module ${moduleId} takes over 2s to load.
|
949
|
+
${getStack()}`
|
950
|
+
);
|
903
951
|
}, 2e3));
|
904
952
|
try {
|
905
953
|
if (mod.promise)
|
906
|
-
return this.processImport(await mod.promise,
|
907
|
-
const promise = this.directRequest(id,
|
908
|
-
return mod.promise = promise, mod.evaluated = !1, this.processImport(await promise,
|
954
|
+
return this.processImport(await mod.promise, meta, metadata);
|
955
|
+
const promise = this.directRequest(id, mod, callstack);
|
956
|
+
return mod.promise = promise, mod.evaluated = !1, this.processImport(await promise, meta, metadata);
|
909
957
|
} finally {
|
910
958
|
mod.evaluated = !0, debugTimer && clearTimeout(debugTimer);
|
911
959
|
}
|
912
960
|
}
|
913
|
-
async cachedModule(
|
914
|
-
if (this.
|
915
|
-
throw new Error("
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
961
|
+
async cachedModule(url, importer) {
|
962
|
+
if (this.destroyed)
|
963
|
+
throw new Error("Vite module runner has been destroyed.");
|
964
|
+
this.debug?.("[module runner] fetching", url), url = normalizeAbsoluteUrl(url, this.root);
|
965
|
+
const normalized = this.urlToIdMap.get(url);
|
966
|
+
let cachedModule = normalized && this.moduleCache.getByModuleId(normalized);
|
967
|
+
cachedModule || (cachedModule = this.moduleCache.getByModuleId(url));
|
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;
|
921
980
|
}
|
922
|
-
|
923
|
-
|
924
|
-
if (fetchedModule.id = moduleId, mod.meta = fetchedModule, file) {
|
981
|
+
const idQuery = url.split("?")[1], query = idQuery ? `?${idQuery}` : "", file = "file" in fetchedModule ? fetchedModule.file : void 0, fileId = file ? `${file}${query}` : url, moduleId = this.moduleCache.normalize(fileId), mod = this.moduleCache.getByModuleId(moduleId);
|
982
|
+
if ("invalidate" in fetchedModule && fetchedModule.invalidate && this.moduleCache.invalidateModule(mod), fetchedModule.id = moduleId, mod.meta = fetchedModule, file) {
|
925
983
|
const fileModules = this.fileToIdMap.get(file) || [];
|
926
984
|
fileModules.push(moduleId), this.fileToIdMap.set(file, fileModules);
|
927
985
|
}
|
928
|
-
return this.
|
986
|
+
return this.urlToIdMap.set(url, moduleId), this.urlToIdMap.set(unwrapId(url), moduleId), mod;
|
929
987
|
}
|
930
988
|
// override is allowed, consider this a public API
|
931
|
-
async directRequest(id,
|
932
|
-
const moduleId = fetchResult.id, callstack = [..._callstack, moduleId],
|
933
|
-
const fetchedModule = await this.cachedModule(dep,
|
934
|
-
return this.moduleCache.getByModuleId(
|
989
|
+
async directRequest(id, mod, _callstack) {
|
990
|
+
const fetchResult = mod.meta, moduleId = fetchResult.id, callstack = [..._callstack, moduleId], request = async (dep, metadata) => {
|
991
|
+
const importer = "file" in fetchResult && fetchResult.file || moduleId, fetchedModule = await this.cachedModule(dep, importer), resolvedId = fetchedModule.meta.id;
|
992
|
+
return this.moduleCache.getByModuleId(resolvedId).importers.add(moduleId), mod.imports.add(resolvedId), this.cachedRequest(dep, fetchedModule, callstack, metadata);
|
935
993
|
}, dynamicRequest = async (dep) => (dep = String(dep), dep[0] === "." && (dep = posixResolve(posixDirname(id), dep)), request(dep, { isDynamicImport: !0 }));
|
936
994
|
if ("externalize" in fetchResult) {
|
937
995
|
const { externalize } = fetchResult;
|
@@ -942,7 +1000,9 @@ ${getStack()}`);
|
|
942
1000
|
const { code, file } = fetchResult;
|
943
1001
|
if (code == null) {
|
944
1002
|
const importer = callstack[callstack.length - 2];
|
945
|
-
throw new Error(
|
1003
|
+
throw new Error(
|
1004
|
+
`[module runner] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`
|
1005
|
+
);
|
946
1006
|
}
|
947
1007
|
const modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
|
948
1008
|
filename: isWindows ? toWindowsPath(filename) : filename,
|
@@ -950,7 +1010,9 @@ ${getStack()}`);
|
|
950
1010
|
url: href,
|
951
1011
|
env: this.envProxy,
|
952
1012
|
resolve(id2, parent) {
|
953
|
-
throw new Error(
|
1013
|
+
throw new Error(
|
1014
|
+
'[module runner] "import.meta.resolve" is not supported.'
|
1015
|
+
);
|
954
1016
|
},
|
955
1017
|
// should be replaced during transformation
|
956
1018
|
glob() {
|
@@ -1008,23 +1070,33 @@ class ESModulesEvaluator {
|
|
1008
1070
|
ssrExportAllKey,
|
1009
1071
|
// source map should already be inlined by Vite
|
1010
1072
|
'"use strict";' + code
|
1011
|
-
)(
|
1073
|
+
)(
|
1074
|
+
context[ssrModuleExportsKey],
|
1075
|
+
context[ssrImportMetaKey],
|
1076
|
+
context[ssrImportKey],
|
1077
|
+
context[ssrDynamicImportKey],
|
1078
|
+
context[ssrExportAllKey]
|
1079
|
+
), Object.seal(context[ssrModuleExportsKey]);
|
1012
1080
|
}
|
1013
1081
|
runExternalModule(filepath) {
|
1014
1082
|
return import(filepath);
|
1015
1083
|
}
|
1016
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
|
+
};
|
1017
1091
|
class RemoteRunnerTransport {
|
1018
|
-
options;
|
1019
|
-
rpcPromises = /* @__PURE__ */ new Map();
|
1020
1092
|
constructor(options) {
|
1021
1093
|
this.options = options, this.options.onMessage(async (data) => {
|
1022
|
-
if (typeof data != "object" || !data || !data.__v)
|
1023
|
-
return;
|
1094
|
+
if (typeof data != "object" || !data || !data.__v) return;
|
1024
1095
|
const promise = this.rpcPromises.get(data.i);
|
1025
1096
|
promise && (promise.timeoutId && clearTimeout(promise.timeoutId), this.rpcPromises.delete(data.i), data.e ? promise.reject(data.e) : promise.resolve(data.r));
|
1026
1097
|
});
|
1027
1098
|
}
|
1099
|
+
rpcPromises = /* @__PURE__ */ new Map();
|
1028
1100
|
resolve(method, ...args) {
|
1029
1101
|
const promiseId = nanoid();
|
1030
1102
|
return this.options.send({
|
@@ -1036,7 +1108,11 @@ class RemoteRunnerTransport {
|
|
1036
1108
|
const timeout = this.options.timeout ?? 6e4;
|
1037
1109
|
let timeoutId;
|
1038
1110
|
timeout > 0 && (timeoutId = setTimeout(() => {
|
1039
|
-
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
|
+
);
|
1040
1116
|
}, timeout), timeoutId?.unref?.()), this.rpcPromises.set(promiseId, { resolve: resolve2, reject, timeoutId });
|
1041
1117
|
});
|
1042
1118
|
}
|
@@ -1044,13 +1120,6 @@ class RemoteRunnerTransport {
|
|
1044
1120
|
return this.resolve("fetchModule", id, importer);
|
1045
1121
|
}
|
1046
1122
|
}
|
1047
|
-
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
1048
|
-
function nanoid(size = 21) {
|
1049
|
-
let id = "", i = size;
|
1050
|
-
for (; i--; )
|
1051
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
1052
|
-
return id;
|
1053
|
-
}
|
1054
1123
|
export {
|
1055
1124
|
ESModulesEvaluator,
|
1056
1125
|
ModuleCacheMap,
|