vite 5.3.0-beta.0 → 5.3.0-beta.2
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 +111 -144
- package/dist/client/client.mjs +608 -606
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep-CTAUzmEN.js → dep-CkqaOKeN.js} +1 -1
- package/dist/node/chunks/{dep-BBErwUJM.js → dep-DxsHXWQ1.js} +23862 -20690
- package/dist/node/chunks/{dep-BPjeYeh_.js → dep-E0jGEM7W.js} +1 -1
- package/dist/node/cli.js +235 -244
- package/dist/node/constants.js +79 -83
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +186 -198
- package/dist/node/runtime.js +139 -99
- package/dist/node-cjs/publicUtils.cjs +514 -575
- package/package.json +11 -12
- package/dist/client/client.mjs.map +0 -1
- package/dist/client/env.mjs.map +0 -1
package/dist/node/runtime.js
CHANGED
@@ -198,7 +198,13 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
198
198
|
return found ? index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index) : bias === LEAST_UPPER_BOUND && index++, index === -1 || index === segments.length ? -1 : index;
|
199
199
|
}
|
200
200
|
class DecodedMap {
|
201
|
-
map
|
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(
|
205
|
+
(s) => posixResolve(s || "", from)
|
206
|
+
);
|
207
|
+
}
|
202
208
|
_encoded;
|
203
209
|
_decoded;
|
204
210
|
_decodedMemo;
|
@@ -206,11 +212,6 @@ class DecodedMap {
|
|
206
212
|
version;
|
207
213
|
names = [];
|
208
214
|
resolvedSources;
|
209
|
-
constructor(map, from) {
|
210
|
-
this.map = map;
|
211
|
-
const { mappings, names, sources } = map;
|
212
|
-
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map((s) => posixResolve(s || "", from));
|
213
|
-
}
|
214
215
|
}
|
215
216
|
function memoizedState() {
|
216
217
|
return {
|
@@ -223,7 +224,9 @@ function getOriginalPosition(map, needle) {
|
|
223
224
|
const result = originalPositionFor(map, needle);
|
224
225
|
return result.column == null ? null : result;
|
225
226
|
}
|
226
|
-
const VITE_RUNTIME_SOURCEMAPPING_REGEXP = new RegExp(
|
227
|
+
const VITE_RUNTIME_SOURCEMAPPING_REGEXP = new RegExp(
|
228
|
+
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`
|
229
|
+
);
|
227
230
|
class ModuleCacheMap extends Map {
|
228
231
|
root;
|
229
232
|
constructor(root, entries) {
|
@@ -265,17 +268,16 @@ class ModuleCacheMap extends Map {
|
|
265
268
|
const module = this.get(id);
|
266
269
|
module.evaluated = !1, module.meta = void 0, module.map = void 0, module.promise = void 0, module.exports = void 0, module.imports?.clear();
|
267
270
|
}
|
268
|
-
isImported({
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
271
|
+
isImported({
|
272
|
+
importedId,
|
273
|
+
importedBy
|
274
|
+
}, seen = /* @__PURE__ */ new Set()) {
|
275
|
+
if (importedId = this.normalize(importedId), importedBy = this.normalize(importedBy), importedBy === importedId) return !0;
|
276
|
+
if (seen.has(importedId)) return !1;
|
273
277
|
seen.add(importedId);
|
274
278
|
const importers = this.getByModuleId(importedId)?.importers;
|
275
|
-
if (!importers)
|
276
|
-
|
277
|
-
if (importers.has(importedBy))
|
278
|
-
return !0;
|
279
|
+
if (!importers) return !1;
|
280
|
+
if (importers.has(importedBy)) return !0;
|
279
281
|
for (const importer of importers)
|
280
282
|
if (this.isImported({
|
281
283
|
importedBy,
|
@@ -290,8 +292,7 @@ class ModuleCacheMap extends Map {
|
|
290
292
|
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
291
293
|
for (const _id of ids) {
|
292
294
|
const id = this.normalize(_id);
|
293
|
-
if (invalidated.has(id))
|
294
|
-
continue;
|
295
|
+
if (invalidated.has(id)) continue;
|
295
296
|
invalidated.add(id);
|
296
297
|
const mod = super.get(id);
|
297
298
|
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), super.delete(id);
|
@@ -304,8 +305,7 @@ class ModuleCacheMap extends Map {
|
|
304
305
|
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
305
306
|
for (const _id of ids) {
|
306
307
|
const id = this.normalize(_id);
|
307
|
-
if (invalidated.has(id))
|
308
|
-
continue;
|
308
|
+
if (invalidated.has(id)) continue;
|
309
309
|
invalidated.add(id);
|
310
310
|
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
311
311
|
subIds.length && this.invalidateSubDepTree(subIds, invalidated), super.delete(id);
|
@@ -314,28 +314,23 @@ class ModuleCacheMap extends Map {
|
|
314
314
|
}
|
315
315
|
getSourceMap(moduleId) {
|
316
316
|
const mod = this.get(moduleId);
|
317
|
-
if (mod.map)
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
if (!mapString)
|
323
|
-
return null;
|
317
|
+
if (mod.map) return mod.map;
|
318
|
+
if (!mod.meta || !("code" in mod.meta)) return null;
|
319
|
+
const mapString = mod.meta.code.match(
|
320
|
+
VITE_RUNTIME_SOURCEMAPPING_REGEXP
|
321
|
+
)?.[1];
|
322
|
+
if (!mapString) return null;
|
324
323
|
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
325
324
|
return mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile), mod.map;
|
326
325
|
}
|
327
326
|
}
|
328
327
|
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
329
328
|
function normalizeModuleId(file, root) {
|
330
|
-
if (prefixedBuiltins.has(file))
|
331
|
-
return file;
|
329
|
+
if (prefixedBuiltins.has(file)) return file;
|
332
330
|
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
333
331
|
return unixFile.startsWith(root) && (unixFile = unixFile.slice(root.length - 1)), unixFile.replace(/^file:\//, "/");
|
334
332
|
}
|
335
333
|
class HMRContext {
|
336
|
-
hmrClient;
|
337
|
-
ownerPath;
|
338
|
-
newListeners;
|
339
334
|
constructor(hmrClient, ownerPath) {
|
340
335
|
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
341
336
|
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
@@ -344,10 +339,14 @@ class HMRContext {
|
|
344
339
|
if (staleListeners)
|
345
340
|
for (const [event, staleFns] of staleListeners) {
|
346
341
|
const listeners = hmrClient.customListenersMap.get(event);
|
347
|
-
listeners && hmrClient.customListenersMap.set(
|
342
|
+
listeners && hmrClient.customListenersMap.set(
|
343
|
+
event,
|
344
|
+
listeners.filter((l) => !staleFns.includes(l))
|
345
|
+
);
|
348
346
|
}
|
349
347
|
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
350
348
|
}
|
349
|
+
newListeners;
|
351
350
|
get data() {
|
352
351
|
return this.hmrClient.dataMap.get(this.ownerPath);
|
353
352
|
}
|
@@ -380,7 +379,9 @@ class HMRContext {
|
|
380
379
|
this.hmrClient.notifyListeners("vite:invalidate", {
|
381
380
|
path: this.ownerPath,
|
382
381
|
message
|
383
|
-
}), this.send("vite:invalidate", { path: this.ownerPath, message }), this.hmrClient.logger.debug(
|
382
|
+
}), this.send("vite:invalidate", { path: this.ownerPath, message }), this.hmrClient.logger.debug(
|
383
|
+
`[vite] invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
384
|
+
);
|
384
385
|
}
|
385
386
|
on(event, cb) {
|
386
387
|
const addToMap = (map) => {
|
@@ -404,7 +405,9 @@ class HMRContext {
|
|
404
405
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
405
406
|
}
|
406
407
|
send(event, data) {
|
407
|
-
this.hmrClient.messenger.send(
|
408
|
+
this.hmrClient.messenger.send(
|
409
|
+
JSON.stringify({ type: "custom", event, data })
|
410
|
+
);
|
408
411
|
}
|
409
412
|
acceptDeps(deps, callback = () => {
|
410
413
|
}) {
|
@@ -419,7 +422,6 @@ class HMRContext {
|
|
419
422
|
}
|
420
423
|
}
|
421
424
|
class HMRMessenger {
|
422
|
-
connection;
|
423
425
|
constructor(connection) {
|
424
426
|
this.connection = connection;
|
425
427
|
}
|
@@ -432,8 +434,9 @@ class HMRMessenger {
|
|
432
434
|
}
|
433
435
|
}
|
434
436
|
class HMRClient {
|
435
|
-
logger
|
436
|
-
|
437
|
+
constructor(logger, connection, importUpdatedModule) {
|
438
|
+
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
439
|
+
}
|
437
440
|
hotModulesMap = /* @__PURE__ */ new Map();
|
438
441
|
disposeMap = /* @__PURE__ */ new Map();
|
439
442
|
pruneMap = /* @__PURE__ */ new Map();
|
@@ -441,9 +444,6 @@ class HMRClient {
|
|
441
444
|
customListenersMap = /* @__PURE__ */ new Map();
|
442
445
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
443
446
|
messenger;
|
444
|
-
constructor(logger, connection, importUpdatedModule) {
|
445
|
-
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
446
|
-
}
|
447
447
|
async notifyListeners(event, data) {
|
448
448
|
const cbs = this.customListenersMap.get(event);
|
449
449
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
@@ -455,17 +455,20 @@ class HMRClient {
|
|
455
455
|
// but they may have left behind side effects that need to be cleaned up
|
456
456
|
// (.e.g style injections)
|
457
457
|
async prunePaths(paths) {
|
458
|
-
await Promise.all(
|
459
|
-
|
460
|
-
|
461
|
-
return disposer(this.dataMap.get(path));
|
462
|
-
|
458
|
+
await Promise.all(
|
459
|
+
paths.map((path) => {
|
460
|
+
const disposer = this.disposeMap.get(path);
|
461
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
462
|
+
})
|
463
|
+
), paths.forEach((path) => {
|
463
464
|
const fn = this.pruneMap.get(path);
|
464
465
|
fn && fn(this.dataMap.get(path));
|
465
466
|
});
|
466
467
|
}
|
467
468
|
warnFailedUpdate(err, path) {
|
468
|
-
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
469
|
+
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
470
|
+
`[hmr] Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
471
|
+
);
|
469
472
|
}
|
470
473
|
updateQueue = [];
|
471
474
|
pendingUpdateQueue = !1;
|
@@ -486,7 +489,9 @@ class HMRClient {
|
|
486
489
|
if (!mod)
|
487
490
|
return;
|
488
491
|
let fetchedModule;
|
489
|
-
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
492
|
+
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
493
|
+
({ deps }) => deps.includes(acceptedPath)
|
494
|
+
);
|
490
495
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
491
496
|
const disposer = this.disposeMap.get(acceptedPath);
|
492
497
|
disposer && await disposer(this.dataMap.get(acceptedPath));
|
@@ -498,7 +503,9 @@ class HMRClient {
|
|
498
503
|
}
|
499
504
|
return () => {
|
500
505
|
for (const { deps, fn } of qualifiedCallbacks)
|
501
|
-
fn(
|
506
|
+
fn(
|
507
|
+
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
508
|
+
);
|
502
509
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
503
510
|
this.logger.debug(`[vite] hot updated: ${loggedPath}`);
|
504
511
|
};
|
@@ -509,7 +516,9 @@ function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
509
516
|
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
510
517
|
if (missingBindings.length) {
|
511
518
|
const lastBinding = missingBindings[missingBindings.length - 1];
|
512
|
-
throw moduleType === "module" ? new SyntaxError(
|
519
|
+
throw moduleType === "module" ? new SyntaxError(
|
520
|
+
`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`
|
521
|
+
) : 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.
|
513
522
|
CommonJS modules can always be imported via the default export, for example using:
|
514
523
|
|
515
524
|
import pkg from '${rawId}';
|
@@ -535,23 +544,28 @@ async function handleHMRPayload(runtime, payload) {
|
|
535
544
|
hmrClient.logger.debug("[vite] connected."), hmrClient.messenger.flush();
|
536
545
|
break;
|
537
546
|
case "update":
|
538
|
-
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
547
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
548
|
+
payload.updates.map(async (update) => {
|
549
|
+
if (update.type === "js-update")
|
550
|
+
return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
551
|
+
hmrClient.logger.error(
|
552
|
+
"[vite] css hmr is not supported in runtime mode."
|
553
|
+
);
|
554
|
+
})
|
555
|
+
), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
543
556
|
break;
|
544
557
|
case "custom": {
|
545
558
|
await hmrClient.notifyListeners(payload.event, payload.data);
|
546
559
|
break;
|
547
560
|
}
|
548
561
|
case "full-reload": {
|
549
|
-
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? [...runtime.entrypoints].filter(
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
562
|
+
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? [...runtime.entrypoints].filter(
|
563
|
+
(entrypoint) => runtime.moduleCache.isImported({
|
564
|
+
importedId: triggeredBy,
|
565
|
+
importedBy: entrypoint
|
566
|
+
})
|
567
|
+
) : [...runtime.entrypoints];
|
568
|
+
if (!clearEntrypoints.length) break;
|
555
569
|
hmrClient.logger.debug("[vite] program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runtime.moduleCache.clear();
|
556
570
|
for (const id of clearEntrypoints)
|
557
571
|
await runtime.executeUrl(id);
|
@@ -563,9 +577,11 @@ async function handleHMRPayload(runtime, payload) {
|
|
563
577
|
case "error": {
|
564
578
|
await hmrClient.notifyListeners("vite:error", payload);
|
565
579
|
const err = payload.err;
|
566
|
-
hmrClient.logger.error(
|
580
|
+
hmrClient.logger.error(
|
581
|
+
`[vite] Internal Server Error
|
567
582
|
${err.message}
|
568
|
-
${err.stack}`
|
583
|
+
${err.stack}`
|
584
|
+
);
|
569
585
|
break;
|
570
586
|
}
|
571
587
|
default:
|
@@ -596,11 +612,12 @@ class Queue {
|
|
596
612
|
const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
|
597
613
|
for (const handler of handlers) {
|
598
614
|
const result = handler(...args);
|
599
|
-
if (result)
|
600
|
-
return result;
|
615
|
+
if (result) return result;
|
601
616
|
}
|
602
617
|
return null;
|
603
|
-
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
618
|
+
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
619
|
+
retrieveSourceMapHandlers
|
620
|
+
);
|
604
621
|
let overridden = !1;
|
605
622
|
const originalPrepare = Error.prepareStackTrace;
|
606
623
|
function resetInterceptor(runtime, options) {
|
@@ -610,8 +627,7 @@ function interceptStackTrace(runtime, options = {}) {
|
|
610
627
|
return overridden || (Error.prepareStackTrace = prepareStackTrace, overridden = !0), moduleGraphs.add(runtime.moduleCache), options.retrieveFile && retrieveFileHandlers.add(options.retrieveFile), options.retrieveSourceMap && retrieveSourceMapHandlers.add(options.retrieveSourceMap), () => resetInterceptor(runtime, options);
|
611
628
|
}
|
612
629
|
function supportRelativeURL(file, url) {
|
613
|
-
if (!file)
|
614
|
-
return url;
|
630
|
+
if (!file) return url;
|
615
631
|
const dir = posixDirname(slash(file)), match = /^\w+:\/\/[^/]*/.exec(dir);
|
616
632
|
let protocol = match ? match[0] : "";
|
617
633
|
const startPath = dir.slice(protocol.length);
|
@@ -630,29 +646,24 @@ function getRuntimeSourceMap(position) {
|
|
630
646
|
return null;
|
631
647
|
}
|
632
648
|
function retrieveFile(path) {
|
633
|
-
if (path in fileContentsCache)
|
634
|
-
return fileContentsCache[path];
|
649
|
+
if (path in fileContentsCache) return fileContentsCache[path];
|
635
650
|
const content = retrieveFileFromHandlers(path);
|
636
651
|
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
637
652
|
}
|
638
653
|
function retrieveSourceMapURL(source) {
|
639
654
|
const fileData = retrieveFile(source);
|
640
|
-
if (!fileData)
|
641
|
-
return null;
|
655
|
+
if (!fileData) return null;
|
642
656
|
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
643
657
|
let lastMatch, match;
|
644
|
-
for (; match = re.exec(fileData); )
|
645
|
-
lastMatch = match;
|
658
|
+
for (; match = re.exec(fileData); ) lastMatch = match;
|
646
659
|
return lastMatch ? lastMatch[1] : null;
|
647
660
|
}
|
648
661
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
649
662
|
function retrieveSourceMap(source) {
|
650
663
|
const urlAndMap = retrieveSourceMapFromHandlers(source);
|
651
|
-
if (urlAndMap)
|
652
|
-
return urlAndMap;
|
664
|
+
if (urlAndMap) return urlAndMap;
|
653
665
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
654
|
-
if (!sourceMappingURL)
|
655
|
-
return null;
|
666
|
+
if (!sourceMappingURL) return null;
|
656
667
|
let sourceMapData;
|
657
668
|
if (reSourceMap.test(sourceMappingURL)) {
|
658
669
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
@@ -665,8 +676,7 @@ function retrieveSourceMap(source) {
|
|
665
676
|
} : null;
|
666
677
|
}
|
667
678
|
function mapSourcePosition(position) {
|
668
|
-
if (!position.source)
|
669
|
-
return position;
|
679
|
+
if (!position.source) return position;
|
670
680
|
let sourceMap = getRuntimeSourceMap(position);
|
671
681
|
if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
|
672
682
|
const urlAndMap = retrieveSourceMap(position.source);
|
@@ -674,7 +684,10 @@ function mapSourcePosition(position) {
|
|
674
684
|
const url = urlAndMap.url;
|
675
685
|
sourceMap = sourceMapCache[position.source] = {
|
676
686
|
url,
|
677
|
-
map: new DecodedMap(
|
687
|
+
map: new DecodedMap(
|
688
|
+
typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map,
|
689
|
+
url
|
690
|
+
)
|
678
691
|
};
|
679
692
|
const contents = sourceMap.map?.map.sourcesContent;
|
680
693
|
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
@@ -693,7 +706,10 @@ function mapSourcePosition(position) {
|
|
693
706
|
if (sourceMap && sourceMap.map && sourceMap.url) {
|
694
707
|
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
695
708
|
if (originalPosition && originalPosition.source != null)
|
696
|
-
return originalPosition.source = supportRelativeURL(
|
709
|
+
return originalPosition.source = supportRelativeURL(
|
710
|
+
sourceMap.url,
|
711
|
+
originalPosition.source
|
712
|
+
), sourceMap.vite && (originalPosition._vite = !0), originalPosition;
|
697
713
|
}
|
698
714
|
return position;
|
699
715
|
}
|
@@ -727,12 +743,14 @@ function CallSiteToString() {
|
|
727
743
|
const functionName = this.getFunctionName();
|
728
744
|
let addSuffix = !0;
|
729
745
|
const isConstructor = this.isConstructor();
|
730
|
-
if (
|
746
|
+
if (this.isToplevel() || isConstructor)
|
747
|
+
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
748
|
+
else {
|
731
749
|
let typeName = this.getTypeName();
|
732
750
|
typeName === "[object Object]" && (typeName = "null");
|
733
751
|
const methodName = this.getMethodName();
|
734
752
|
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>"}`;
|
735
|
-
}
|
753
|
+
}
|
736
754
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
737
755
|
}
|
738
756
|
function cloneCallSite(frame) {
|
@@ -789,18 +807,29 @@ function prepareStackTrace(error, stack) {
|
|
789
807
|
function enableSourceMapSupport(runtime) {
|
790
808
|
if (runtime.options.sourcemapInterceptor === "node") {
|
791
809
|
if (typeof process > "u")
|
792
|
-
throw new TypeError(
|
810
|
+
throw new TypeError(
|
811
|
+
`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`
|
812
|
+
);
|
793
813
|
if (typeof process.setSourceMapsEnabled != "function")
|
794
|
-
throw new TypeError(
|
814
|
+
throw new TypeError(
|
815
|
+
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`
|
816
|
+
);
|
795
817
|
const isEnabledAlready = process.sourceMapsEnabled ?? !1;
|
796
818
|
return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
|
797
819
|
}
|
798
|
-
return interceptStackTrace(
|
820
|
+
return interceptStackTrace(
|
821
|
+
runtime,
|
822
|
+
typeof runtime.options.sourcemapInterceptor == "object" ? runtime.options.sourcemapInterceptor : void 0
|
823
|
+
);
|
799
824
|
}
|
800
825
|
class ViteRuntime {
|
801
|
-
options
|
802
|
-
|
803
|
-
|
826
|
+
constructor(options, runner, debug) {
|
827
|
+
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(
|
828
|
+
options.hmr.logger === !1 ? silentConsole : options.hmr.logger || console,
|
829
|
+
options.hmr.connection,
|
830
|
+
({ acceptedPath, ssrInvalidates }) => (this.moduleCache.invalidate(acceptedPath), ssrInvalidates && this.invalidateFiles(ssrInvalidates), this.executeUrl(acceptedPath))
|
831
|
+
), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this._resetSourceMapSupport = enableSourceMapSupport(this));
|
832
|
+
}
|
804
833
|
/**
|
805
834
|
* Holds the cache of modules
|
806
835
|
* Keys of the map are ids
|
@@ -812,14 +841,13 @@ class ViteRuntime {
|
|
812
841
|
fileToIdMap = /* @__PURE__ */ new Map();
|
813
842
|
envProxy = new Proxy({}, {
|
814
843
|
get(_, p) {
|
815
|
-
throw new Error(
|
844
|
+
throw new Error(
|
845
|
+
`[vite-runtime] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`
|
846
|
+
);
|
816
847
|
}
|
817
848
|
});
|
818
849
|
_destroyed = !1;
|
819
850
|
_resetSourceMapSupport;
|
820
|
-
constructor(options, runner, debug) {
|
821
|
-
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));
|
822
|
-
}
|
823
851
|
/**
|
824
852
|
* URL to execute. Accepts file path, server path or id relative to the root.
|
825
853
|
*/
|
@@ -892,8 +920,10 @@ class ViteRuntime {
|
|
892
920
|
const getStack = () => `stack:
|
893
921
|
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(`
|
894
922
|
`)}`;
|
895
|
-
this.debug(
|
896
|
-
${
|
923
|
+
this.debug(
|
924
|
+
`[vite-runtime] module ${moduleId} takes over 2s to load.
|
925
|
+
${getStack()}`
|
926
|
+
);
|
897
927
|
}, 2e3));
|
898
928
|
try {
|
899
929
|
if (mod.promise)
|
@@ -936,7 +966,9 @@ ${getStack()}`);
|
|
936
966
|
const { code, file } = fetchResult;
|
937
967
|
if (code == null) {
|
938
968
|
const importer = callstack[callstack.length - 2];
|
939
|
-
throw new Error(
|
969
|
+
throw new Error(
|
970
|
+
`[vite-runtime] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`
|
971
|
+
);
|
940
972
|
}
|
941
973
|
const modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
|
942
974
|
filename: isWindows ? toWindowsPath(filename) : filename,
|
@@ -944,7 +976,9 @@ ${getStack()}`);
|
|
944
976
|
url: href,
|
945
977
|
env: this.envProxy,
|
946
978
|
resolve(id2, parent) {
|
947
|
-
throw new Error(
|
979
|
+
throw new Error(
|
980
|
+
'[vite-runtime] "import.meta.resolve" is not supported.'
|
981
|
+
);
|
948
982
|
},
|
949
983
|
// should be replaced during transformation
|
950
984
|
glob() {
|
@@ -1002,7 +1036,13 @@ class ESModulesRunner {
|
|
1002
1036
|
ssrExportAllKey,
|
1003
1037
|
// source map should already be inlined by Vite
|
1004
1038
|
'"use strict";' + code
|
1005
|
-
)(
|
1039
|
+
)(
|
1040
|
+
context[ssrModuleExportsKey],
|
1041
|
+
context[ssrImportMetaKey],
|
1042
|
+
context[ssrImportKey],
|
1043
|
+
context[ssrDynamicImportKey],
|
1044
|
+
context[ssrExportAllKey]
|
1045
|
+
), Object.seal(context[ssrModuleExportsKey]);
|
1006
1046
|
}
|
1007
1047
|
runExternalModule(filepath) {
|
1008
1048
|
return import(filepath);
|