vite 6.0.0-alpha.18 → 6.0.0-alpha.19
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/client.d.ts +4 -0
- package/dist/client/client.mjs +614 -612
- package/dist/client/env.mjs +18 -24
- package/dist/node/chunks/{dep-DXWVQosX.js → dep-BWEMV5Th.js} +49165 -46447
- package/dist/node/chunks/{dep-CrWVpuYf.js → dep-D-7KCb9p.js} +32 -2
- package/dist/node/chunks/{dep-70g8Z1cd.js → dep-MbEgMyUv.js} +10 -14
- package/dist/node/chunks/{dep-DlhHXrzk.js → dep-bCS_cgqC.js} +1 -1
- package/dist/node/cli.js +253 -263
- package/dist/node/constants.js +105 -108
- package/dist/node/index.d.ts +75 -74
- package/dist/node/index.js +125 -143
- package/dist/node/module-runner.d.ts +3 -0
- package/dist/node/module-runner.js +173 -108
- package/dist/node-cjs/publicUtils.cjs +536 -606
- package/package.json +16 -17
- package/dist/client/client.mjs.map +0 -1
- package/dist/client/env.mjs.map +0 -1
@@ -75,7 +75,11 @@ const isAbsolute = function(p) {
|
|
75
75
|
}, dirname = function(p) {
|
76
76
|
const segments = normalizeWindowsPath(p).replace(/\/$/, "").split("/").slice(0, -1);
|
77
77
|
return segments.length === 1 && _DRIVE_LETTER_RE.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute(p) ? "/" : ".");
|
78
|
-
}
|
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;
|
79
83
|
function encodePathChars(filepath) {
|
80
84
|
return filepath.indexOf("%") !== -1 && (filepath = filepath.replace(percentRegEx, "%25")), !isWindows && filepath.indexOf("\\") !== -1 && (filepath = filepath.replace(backslashRegEx, "%5C")), filepath.indexOf(`
|
81
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;
|
@@ -198,7 +202,13 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
198
202
|
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
203
|
}
|
200
204
|
class DecodedMap {
|
201
|
-
map
|
205
|
+
constructor(map, from) {
|
206
|
+
this.map = map;
|
207
|
+
const { mappings, names, sources } = map;
|
208
|
+
this.version = map.version, this.names = names || [], this._encoded = mappings || "", this._decodedMemo = memoizedState(), this.url = from, this.resolvedSources = (sources || []).map(
|
209
|
+
(s) => posixResolve(s || "", from)
|
210
|
+
);
|
211
|
+
}
|
202
212
|
_encoded;
|
203
213
|
_decoded;
|
204
214
|
_decodedMemo;
|
@@ -206,11 +216,6 @@ class DecodedMap {
|
|
206
216
|
version;
|
207
217
|
names = [];
|
208
218
|
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
219
|
}
|
215
220
|
function memoizedState() {
|
216
221
|
return {
|
@@ -223,7 +228,9 @@ function getOriginalPosition(map, needle) {
|
|
223
228
|
const result = originalPositionFor(map, needle);
|
224
229
|
return result.column == null ? null : result;
|
225
230
|
}
|
226
|
-
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
231
|
+
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp(
|
232
|
+
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`
|
233
|
+
);
|
227
234
|
class ModuleCacheMap extends Map {
|
228
235
|
root;
|
229
236
|
constructor(root, entries) {
|
@@ -275,8 +282,7 @@ class ModuleCacheMap extends Map {
|
|
275
282
|
invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
276
283
|
for (const _id of ids) {
|
277
284
|
const id = this.normalize(_id);
|
278
|
-
if (invalidated.has(id))
|
279
|
-
continue;
|
285
|
+
if (invalidated.has(id)) continue;
|
280
286
|
invalidated.add(id);
|
281
287
|
const mod = super.get(id);
|
282
288
|
mod?.importers && this.invalidateDepTree(mod.importers, invalidated), this.invalidateUrl(id);
|
@@ -289,8 +295,7 @@ class ModuleCacheMap extends Map {
|
|
289
295
|
invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
|
290
296
|
for (const _id of ids) {
|
291
297
|
const id = this.normalize(_id);
|
292
|
-
if (invalidated.has(id))
|
293
|
-
continue;
|
298
|
+
if (invalidated.has(id)) continue;
|
294
299
|
invalidated.add(id);
|
295
300
|
const subIds = Array.from(super.entries()).filter(([, mod]) => mod.importers?.has(id)).map(([key]) => key);
|
296
301
|
subIds.length && this.invalidateSubDepTree(subIds, invalidated), super.delete(id);
|
@@ -299,28 +304,23 @@ class ModuleCacheMap extends Map {
|
|
299
304
|
}
|
300
305
|
getSourceMap(moduleId) {
|
301
306
|
const mod = this.get(moduleId);
|
302
|
-
if (mod.map)
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
if (!mapString)
|
308
|
-
return null;
|
307
|
+
if (mod.map) return mod.map;
|
308
|
+
if (!mod.meta || !("code" in mod.meta)) return null;
|
309
|
+
const mapString = mod.meta.code.match(
|
310
|
+
MODULE_RUNNER_SOURCEMAPPING_REGEXP
|
311
|
+
)?.[1];
|
312
|
+
if (!mapString) return null;
|
309
313
|
const baseFile = mod.meta.file || moduleId.split("?")[0];
|
310
314
|
return mod.map = new DecodedMap(JSON.parse(decodeBase64(mapString)), baseFile), mod.map;
|
311
315
|
}
|
312
316
|
}
|
313
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
317
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test", "node:sqlite"]);
|
314
318
|
function normalizeModuleId(file, root) {
|
315
|
-
if (prefixedBuiltins.has(file))
|
316
|
-
return file;
|
319
|
+
if (prefixedBuiltins.has(file)) return file;
|
317
320
|
let unixFile = slash(file).replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
318
321
|
return unixFile.startsWith(root) && (unixFile = unixFile.slice(root.length - 1)), unixFile.replace(/^file:\//, "/");
|
319
322
|
}
|
320
323
|
class HMRContext {
|
321
|
-
hmrClient;
|
322
|
-
ownerPath;
|
323
|
-
newListeners;
|
324
324
|
constructor(hmrClient, ownerPath) {
|
325
325
|
this.hmrClient = hmrClient, this.ownerPath = ownerPath, hmrClient.dataMap.has(ownerPath) || hmrClient.dataMap.set(ownerPath, {});
|
326
326
|
const mod = hmrClient.hotModulesMap.get(ownerPath);
|
@@ -329,10 +329,14 @@ class HMRContext {
|
|
329
329
|
if (staleListeners)
|
330
330
|
for (const [event, staleFns] of staleListeners) {
|
331
331
|
const listeners = hmrClient.customListenersMap.get(event);
|
332
|
-
listeners && hmrClient.customListenersMap.set(
|
332
|
+
listeners && hmrClient.customListenersMap.set(
|
333
|
+
event,
|
334
|
+
listeners.filter((l) => !staleFns.includes(l))
|
335
|
+
);
|
333
336
|
}
|
334
337
|
this.newListeners = /* @__PURE__ */ new Map(), hmrClient.ctxToListenersMap.set(ownerPath, this.newListeners);
|
335
338
|
}
|
339
|
+
newListeners;
|
336
340
|
get data() {
|
337
341
|
return this.hmrClient.dataMap.get(this.ownerPath);
|
338
342
|
}
|
@@ -368,7 +372,9 @@ class HMRContext {
|
|
368
372
|
}), this.send("vite:invalidate", {
|
369
373
|
path: this.ownerPath,
|
370
374
|
message
|
371
|
-
}), this.hmrClient.logger.debug(
|
375
|
+
}), this.hmrClient.logger.debug(
|
376
|
+
`invalidate ${this.ownerPath}${message ? `: ${message}` : ""}`
|
377
|
+
);
|
372
378
|
}
|
373
379
|
on(event, cb) {
|
374
380
|
const addToMap = (map) => {
|
@@ -392,7 +398,9 @@ class HMRContext {
|
|
392
398
|
removeFromMap(this.hmrClient.customListenersMap), removeFromMap(this.newListeners);
|
393
399
|
}
|
394
400
|
send(event, data) {
|
395
|
-
this.hmrClient.messenger.send(
|
401
|
+
this.hmrClient.messenger.send(
|
402
|
+
JSON.stringify({ type: "custom", event, data })
|
403
|
+
);
|
396
404
|
}
|
397
405
|
acceptDeps(deps, callback = () => {
|
398
406
|
}) {
|
@@ -407,7 +415,6 @@ class HMRContext {
|
|
407
415
|
}
|
408
416
|
}
|
409
417
|
class HMRMessenger {
|
410
|
-
connection;
|
411
418
|
constructor(connection) {
|
412
419
|
this.connection = connection;
|
413
420
|
}
|
@@ -420,8 +427,9 @@ class HMRMessenger {
|
|
420
427
|
}
|
421
428
|
}
|
422
429
|
class HMRClient {
|
423
|
-
logger
|
424
|
-
|
430
|
+
constructor(logger, connection, importUpdatedModule) {
|
431
|
+
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
432
|
+
}
|
425
433
|
hotModulesMap = /* @__PURE__ */ new Map();
|
426
434
|
disposeMap = /* @__PURE__ */ new Map();
|
427
435
|
pruneMap = /* @__PURE__ */ new Map();
|
@@ -429,9 +437,6 @@ class HMRClient {
|
|
429
437
|
customListenersMap = /* @__PURE__ */ new Map();
|
430
438
|
ctxToListenersMap = /* @__PURE__ */ new Map();
|
431
439
|
messenger;
|
432
|
-
constructor(logger, connection, importUpdatedModule) {
|
433
|
-
this.logger = logger, this.importUpdatedModule = importUpdatedModule, this.messenger = new HMRMessenger(connection);
|
434
|
-
}
|
435
440
|
async notifyListeners(event, data) {
|
436
441
|
const cbs = this.customListenersMap.get(event);
|
437
442
|
cbs && await Promise.allSettled(cbs.map((cb) => cb(data)));
|
@@ -443,17 +448,20 @@ class HMRClient {
|
|
443
448
|
// but they may have left behind side effects that need to be cleaned up
|
444
449
|
// (.e.g style injections)
|
445
450
|
async prunePaths(paths) {
|
446
|
-
await Promise.all(
|
447
|
-
|
448
|
-
|
449
|
-
return disposer(this.dataMap.get(path));
|
450
|
-
|
451
|
+
await Promise.all(
|
452
|
+
paths.map((path) => {
|
453
|
+
const disposer = this.disposeMap.get(path);
|
454
|
+
if (disposer) return disposer(this.dataMap.get(path));
|
455
|
+
})
|
456
|
+
), paths.forEach((path) => {
|
451
457
|
const fn = this.pruneMap.get(path);
|
452
458
|
fn && fn(this.dataMap.get(path));
|
453
459
|
});
|
454
460
|
}
|
455
461
|
warnFailedUpdate(err, path) {
|
456
|
-
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
462
|
+
err.message.includes("fetch") || this.logger.error(err), this.logger.error(
|
463
|
+
`Failed to reload ${path}. This could be due to syntax errors or importing non-existent modules. (see errors above)`
|
464
|
+
);
|
457
465
|
}
|
458
466
|
updateQueue = [];
|
459
467
|
pendingUpdateQueue = !1;
|
@@ -474,7 +482,9 @@ class HMRClient {
|
|
474
482
|
if (!mod)
|
475
483
|
return;
|
476
484
|
let fetchedModule;
|
477
|
-
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
485
|
+
const isSelfUpdate = path === acceptedPath, qualifiedCallbacks = mod.callbacks.filter(
|
486
|
+
({ deps }) => deps.includes(acceptedPath)
|
487
|
+
);
|
478
488
|
if (isSelfUpdate || qualifiedCallbacks.length > 0) {
|
479
489
|
const disposer = this.disposeMap.get(acceptedPath);
|
480
490
|
disposer && await disposer(this.dataMap.get(acceptedPath));
|
@@ -486,7 +496,9 @@ class HMRClient {
|
|
486
496
|
}
|
487
497
|
return () => {
|
488
498
|
for (const { deps, fn } of qualifiedCallbacks)
|
489
|
-
fn(
|
499
|
+
fn(
|
500
|
+
deps.map((dep) => dep === acceptedPath ? fetchedModule : void 0)
|
501
|
+
);
|
490
502
|
const loggedPath = isSelfUpdate ? path : `${acceptedPath} via ${path}`;
|
491
503
|
this.logger.debug(`hot updated: ${loggedPath}`);
|
492
504
|
};
|
@@ -497,7 +509,9 @@ function analyzeImportedModDifference(mod, rawId, moduleType, metadata) {
|
|
497
509
|
const missingBindings = metadata.importedNames.filter((s) => !(s in mod));
|
498
510
|
if (missingBindings.length) {
|
499
511
|
const lastBinding = missingBindings[missingBindings.length - 1];
|
500
|
-
throw moduleType === "module" ? new SyntaxError(
|
512
|
+
throw moduleType === "module" ? new SyntaxError(
|
513
|
+
`[vite] The requested module '${rawId}' does not provide an export named '${lastBinding}'`
|
514
|
+
) : 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.
|
501
515
|
CommonJS modules can always be imported via the default export, for example using:
|
502
516
|
|
503
517
|
import pkg from '${rawId}';
|
@@ -526,20 +540,24 @@ async function handleHotPayload(runner, payload) {
|
|
526
540
|
hmrClient.logger.debug("connected."), hmrClient.messenger.flush();
|
527
541
|
break;
|
528
542
|
case "update":
|
529
|
-
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
543
|
+
await hmrClient.notifyListeners("vite:beforeUpdate", payload), await Promise.all(
|
544
|
+
payload.updates.map(async (update) => {
|
545
|
+
if (update.type === "js-update")
|
546
|
+
return update.acceptedPath = unwrapId(update.acceptedPath), update.path = unwrapId(update.path), hmrClient.queueUpdate(update);
|
547
|
+
hmrClient.logger.error("css hmr is not supported in runner mode.");
|
548
|
+
})
|
549
|
+
), await hmrClient.notifyListeners("vite:afterUpdate", payload);
|
534
550
|
break;
|
535
551
|
case "custom": {
|
536
552
|
await hmrClient.notifyListeners(payload.event, payload.data);
|
537
553
|
break;
|
538
554
|
}
|
539
555
|
case "full-reload": {
|
540
|
-
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
541
|
-
|
542
|
-
|
556
|
+
const { triggeredBy } = payload, clearEntrypoints = triggeredBy ? getModulesEntrypoints(
|
557
|
+
runner,
|
558
|
+
getModulesByFile(runner, slash(triggeredBy))
|
559
|
+
) : findAllEntrypoints(runner);
|
560
|
+
if (!clearEntrypoints.size) break;
|
543
561
|
hmrClient.logger.debug("program reload"), await hmrClient.notifyListeners("vite:beforeFullReload", payload), runner.moduleCache.clear();
|
544
562
|
for (const id of clearEntrypoints)
|
545
563
|
await runner.import(id);
|
@@ -551,9 +569,11 @@ async function handleHotPayload(runner, payload) {
|
|
551
569
|
case "error": {
|
552
570
|
await hmrClient.notifyListeners("vite:error", payload);
|
553
571
|
const err = payload.err;
|
554
|
-
hmrClient.logger.error(
|
572
|
+
hmrClient.logger.error(
|
573
|
+
`Internal Server Error
|
555
574
|
${err.message}
|
556
|
-
${err.stack}`
|
575
|
+
${err.stack}`
|
576
|
+
);
|
557
577
|
break;
|
558
578
|
}
|
559
579
|
default:
|
@@ -589,8 +609,7 @@ function getModulesByFile(runner, file) {
|
|
589
609
|
}
|
590
610
|
function getModulesEntrypoints(runner, modules, visited = /* @__PURE__ */ new Set(), entrypoints = /* @__PURE__ */ new Set()) {
|
591
611
|
for (const moduleId of modules) {
|
592
|
-
if (visited.has(moduleId))
|
593
|
-
continue;
|
612
|
+
if (visited.has(moduleId)) continue;
|
594
613
|
visited.add(moduleId);
|
595
614
|
const module = runner.moduleCache.getByModuleId(moduleId);
|
596
615
|
if (module.importers && !module.importers.size) {
|
@@ -610,11 +629,12 @@ function findAllEntrypoints(runner, entrypoints = /* @__PURE__ */ new Set()) {
|
|
610
629
|
const sourceMapCache = {}, fileContentsCache = {}, moduleGraphs = /* @__PURE__ */ new Set(), retrieveFileHandlers = /* @__PURE__ */ new Set(), retrieveSourceMapHandlers = /* @__PURE__ */ new Set(), createExecHandlers = (handlers) => (...args) => {
|
611
630
|
for (const handler of handlers) {
|
612
631
|
const result = handler(...args);
|
613
|
-
if (result)
|
614
|
-
return result;
|
632
|
+
if (result) return result;
|
615
633
|
}
|
616
634
|
return null;
|
617
|
-
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
635
|
+
}, retrieveFileFromHandlers = createExecHandlers(retrieveFileHandlers), retrieveSourceMapFromHandlers = createExecHandlers(
|
636
|
+
retrieveSourceMapHandlers
|
637
|
+
);
|
618
638
|
let overridden = !1;
|
619
639
|
const originalPrepare = Error.prepareStackTrace;
|
620
640
|
function resetInterceptor(runner, options) {
|
@@ -624,8 +644,7 @@ function interceptStackTrace(runner, options = {}) {
|
|
624
644
|
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);
|
625
645
|
}
|
626
646
|
function supportRelativeURL(file, url) {
|
627
|
-
if (!file)
|
628
|
-
return url;
|
647
|
+
if (!file) return url;
|
629
648
|
const dir = posixDirname(slash(file)), match = /^\w+:\/\/[^/]*/.exec(dir);
|
630
649
|
let protocol = match ? match[0] : "";
|
631
650
|
const startPath = dir.slice(protocol.length);
|
@@ -644,29 +663,24 @@ function getRunnerSourceMap(position) {
|
|
644
663
|
return null;
|
645
664
|
}
|
646
665
|
function retrieveFile(path) {
|
647
|
-
if (path in fileContentsCache)
|
648
|
-
return fileContentsCache[path];
|
666
|
+
if (path in fileContentsCache) return fileContentsCache[path];
|
649
667
|
const content = retrieveFileFromHandlers(path);
|
650
668
|
return typeof content == "string" ? (fileContentsCache[path] = content, content) : null;
|
651
669
|
}
|
652
670
|
function retrieveSourceMapURL(source) {
|
653
671
|
const fileData = retrieveFile(source);
|
654
|
-
if (!fileData)
|
655
|
-
return null;
|
672
|
+
if (!fileData) return null;
|
656
673
|
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
657
674
|
let lastMatch, match;
|
658
|
-
for (; match = re.exec(fileData); )
|
659
|
-
lastMatch = match;
|
675
|
+
for (; match = re.exec(fileData); ) lastMatch = match;
|
660
676
|
return lastMatch ? lastMatch[1] : null;
|
661
677
|
}
|
662
678
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
663
679
|
function retrieveSourceMap(source) {
|
664
680
|
const urlAndMap = retrieveSourceMapFromHandlers(source);
|
665
|
-
if (urlAndMap)
|
666
|
-
return urlAndMap;
|
681
|
+
if (urlAndMap) return urlAndMap;
|
667
682
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
668
|
-
if (!sourceMappingURL)
|
669
|
-
return null;
|
683
|
+
if (!sourceMappingURL) return null;
|
670
684
|
let sourceMapData;
|
671
685
|
if (reSourceMap.test(sourceMappingURL)) {
|
672
686
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
@@ -679,8 +693,7 @@ function retrieveSourceMap(source) {
|
|
679
693
|
} : null;
|
680
694
|
}
|
681
695
|
function mapSourcePosition(position) {
|
682
|
-
if (!position.source)
|
683
|
-
return position;
|
696
|
+
if (!position.source) return position;
|
684
697
|
let sourceMap = getRunnerSourceMap(position);
|
685
698
|
if (sourceMap || (sourceMap = sourceMapCache[position.source]), !sourceMap) {
|
686
699
|
const urlAndMap = retrieveSourceMap(position.source);
|
@@ -688,7 +701,10 @@ function mapSourcePosition(position) {
|
|
688
701
|
const url = urlAndMap.url;
|
689
702
|
sourceMap = sourceMapCache[position.source] = {
|
690
703
|
url,
|
691
|
-
map: new DecodedMap(
|
704
|
+
map: new DecodedMap(
|
705
|
+
typeof urlAndMap.map == "string" ? JSON.parse(urlAndMap.map) : urlAndMap.map,
|
706
|
+
url
|
707
|
+
)
|
692
708
|
};
|
693
709
|
const contents = sourceMap.map?.map.sourcesContent;
|
694
710
|
sourceMap.map && contents && sourceMap.map.resolvedSources.forEach((source, i) => {
|
@@ -707,7 +723,10 @@ function mapSourcePosition(position) {
|
|
707
723
|
if (sourceMap && sourceMap.map && sourceMap.url) {
|
708
724
|
const originalPosition = getOriginalPosition(sourceMap.map, position);
|
709
725
|
if (originalPosition && originalPosition.source != null)
|
710
|
-
return originalPosition.source = supportRelativeURL(
|
726
|
+
return originalPosition.source = supportRelativeURL(
|
727
|
+
sourceMap.url,
|
728
|
+
originalPosition.source
|
729
|
+
), sourceMap.vite && (originalPosition._vite = !0), originalPosition;
|
711
730
|
}
|
712
731
|
return position;
|
713
732
|
}
|
@@ -741,12 +760,14 @@ function CallSiteToString() {
|
|
741
760
|
const functionName = this.getFunctionName();
|
742
761
|
let addSuffix = !0;
|
743
762
|
const isConstructor = this.isConstructor();
|
744
|
-
if (
|
763
|
+
if (this.isToplevel() || isConstructor)
|
764
|
+
isConstructor ? line += `new ${functionName || "<anonymous>"}` : functionName ? line += functionName : (line += fileLocation, addSuffix = !1);
|
765
|
+
else {
|
745
766
|
let typeName = this.getTypeName();
|
746
767
|
typeName === "[object Object]" && (typeName = "null");
|
747
768
|
const methodName = this.getMethodName();
|
748
769
|
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>"}`;
|
749
|
-
}
|
770
|
+
}
|
750
771
|
return addSuffix && (line += ` (${fileLocation})`), line;
|
751
772
|
}
|
752
773
|
function cloneCallSite(frame) {
|
@@ -803,18 +824,31 @@ function prepareStackTrace(error, stack) {
|
|
803
824
|
function enableSourceMapSupport(runner) {
|
804
825
|
if (runner.options.sourcemapInterceptor === "node") {
|
805
826
|
if (typeof process > "u")
|
806
|
-
throw new TypeError(
|
827
|
+
throw new TypeError(
|
828
|
+
`Cannot use "sourcemapInterceptor: 'node'" because global "process" variable is not available.`
|
829
|
+
);
|
807
830
|
if (typeof process.setSourceMapsEnabled != "function")
|
808
|
-
throw new TypeError(
|
831
|
+
throw new TypeError(
|
832
|
+
`Cannot use "sourcemapInterceptor: 'node'" because "process.setSourceMapsEnabled" function is not available. Please use Node >= 16.6.0.`
|
833
|
+
);
|
809
834
|
const isEnabledAlready = process.sourceMapsEnabled ?? !1;
|
810
835
|
return process.setSourceMapsEnabled(!0), () => !isEnabledAlready && process.setSourceMapsEnabled(!1);
|
811
836
|
}
|
812
|
-
return interceptStackTrace(
|
837
|
+
return interceptStackTrace(
|
838
|
+
runner,
|
839
|
+
typeof runner.options.sourcemapInterceptor == "object" ? runner.options.sourcemapInterceptor : void 0
|
840
|
+
);
|
813
841
|
}
|
814
842
|
class ModuleRunner {
|
815
|
-
options
|
816
|
-
|
817
|
-
|
843
|
+
constructor(options, evaluator, debug) {
|
844
|
+
this.options = options, this.evaluator = evaluator, this.debug = debug;
|
845
|
+
const root = this.options.root;
|
846
|
+
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(
|
847
|
+
options.hmr.logger === !1 ? silentConsole : options.hmr.logger || hmrLogger,
|
848
|
+
options.hmr.connection,
|
849
|
+
({ acceptedPath }) => this.import(acceptedPath)
|
850
|
+
), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
851
|
+
}
|
818
852
|
/**
|
819
853
|
* Holds the cache of modules
|
820
854
|
* Keys of the map are ids
|
@@ -825,15 +859,15 @@ class ModuleRunner {
|
|
825
859
|
fileToIdMap = /* @__PURE__ */ new Map();
|
826
860
|
envProxy = new Proxy({}, {
|
827
861
|
get(_, p) {
|
828
|
-
throw new Error(
|
862
|
+
throw new Error(
|
863
|
+
`[module runner] Dynamic access of "import.meta.env" is not supported. Please, use "import.meta.env.${String(p)}" instead.`
|
864
|
+
);
|
829
865
|
}
|
830
866
|
});
|
831
867
|
transport;
|
832
868
|
resetSourceMapSupport;
|
869
|
+
root;
|
833
870
|
destroyed = !1;
|
834
|
-
constructor(options, evaluator, debug) {
|
835
|
-
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 }) => this.import(acceptedPath)), options.hmr.connection.onUpdate(createHMRHandler(this))), options.sourcemapInterceptor !== !1 && (this.resetSourceMapSupport = enableSourceMapSupport(this));
|
836
|
-
}
|
837
871
|
/**
|
838
872
|
* URL to execute. Accepts file path, server path or id relative to the root.
|
839
873
|
*/
|
@@ -865,11 +899,7 @@ class ModuleRunner {
|
|
865
899
|
// this URL is something that user passes down manually, and is later resolved by fetchModule
|
866
900
|
// moduleCache.normalize is used on resolved "file" property
|
867
901
|
normalizeEntryUrl(url) {
|
868
|
-
|
869
|
-
return url;
|
870
|
-
url.startsWith("file://") && (url = url.slice(isWindows ? 8 : 7)), url = slash(url);
|
871
|
-
const _root = this.options.root, root = _root[_root.length - 1] === "/" ? _root : `${_root}/`;
|
872
|
-
return url.startsWith(root) ? url.slice(root.length - 1) : url[0] === "/" ? url : wrapId(url);
|
902
|
+
return url[0] === "." ? url : (url = normalizeAbsoluteUrl(url, this.root), url[0] === "/" ? url : wrapId(url));
|
873
903
|
}
|
874
904
|
processImport(exports, fetchResult, metadata) {
|
875
905
|
if (!("externalize" in fetchResult))
|
@@ -877,17 +907,39 @@ class ModuleRunner {
|
|
877
907
|
const { id, type } = fetchResult;
|
878
908
|
return type !== "module" && type !== "commonjs" || analyzeImportedModDifference(exports, id, type, metadata), exports;
|
879
909
|
}
|
880
|
-
|
881
|
-
const
|
882
|
-
|
910
|
+
isCircularModule(mod) {
|
911
|
+
for (const importedFile of mod.imports)
|
912
|
+
if (mod.importers.has(importedFile))
|
913
|
+
return !0;
|
914
|
+
return !1;
|
915
|
+
}
|
916
|
+
isCircularImport(importers, moduleId, visited = /* @__PURE__ */ new Set()) {
|
917
|
+
for (const importer of importers) {
|
918
|
+
if (visited.has(importer))
|
919
|
+
continue;
|
920
|
+
if (visited.add(importer), importer === moduleId)
|
921
|
+
return !0;
|
922
|
+
const mod = this.moduleCache.getByModuleId(
|
923
|
+
importer
|
924
|
+
);
|
925
|
+
if (mod.importers.size && this.isCircularImport(mod.importers, moduleId, visited))
|
926
|
+
return !0;
|
927
|
+
}
|
928
|
+
return !1;
|
929
|
+
}
|
930
|
+
async cachedRequest(id, mod_, callstack = [], metadata) {
|
931
|
+
const mod = mod_, meta = mod.meta, moduleId = meta.id, { importers } = mod, importee = callstack[callstack.length - 1];
|
932
|
+
if (importee && importers.add(importee), (callstack.includes(moduleId) || this.isCircularModule(mod) || this.isCircularImport(importers, moduleId)) && mod.exports)
|
883
933
|
return this.processImport(mod.exports, meta, metadata);
|
884
934
|
let debugTimer;
|
885
935
|
this.debug && (debugTimer = setTimeout(() => {
|
886
936
|
const getStack = () => `stack:
|
887
937
|
${[...callstack, moduleId].reverse().map((p) => ` - ${p}`).join(`
|
888
938
|
`)}`;
|
889
|
-
this.debug(
|
890
|
-
${
|
939
|
+
this.debug(
|
940
|
+
`[module runner] module ${moduleId} takes over 2s to load.
|
941
|
+
${getStack()}`
|
942
|
+
);
|
891
943
|
}, 2e3));
|
892
944
|
try {
|
893
945
|
if (mod.promise)
|
@@ -901,7 +953,7 @@ ${getStack()}`);
|
|
901
953
|
async cachedModule(url, importer) {
|
902
954
|
if (this.destroyed)
|
903
955
|
throw new Error("Vite module runner has been destroyed.");
|
904
|
-
this.debug?.("[module runner] fetching", url);
|
956
|
+
this.debug?.("[module runner] fetching", url), url = normalizeAbsoluteUrl(url, this.root);
|
905
957
|
const normalized = this.urlToIdMap.get(url);
|
906
958
|
let cachedModule = normalized && this.moduleCache.getByModuleId(normalized);
|
907
959
|
cachedModule || (cachedModule = this.moduleCache.getByModuleId(url));
|
@@ -913,7 +965,9 @@ ${getStack()}`);
|
|
913
965
|
);
|
914
966
|
if ("cache" in fetchedModule) {
|
915
967
|
if (!cachedModule || !cachedModule.meta)
|
916
|
-
throw new Error(
|
968
|
+
throw new Error(
|
969
|
+
`Module "${url}" was mistakenly invalidated during fetch phase.`
|
970
|
+
);
|
917
971
|
return cachedModule;
|
918
972
|
}
|
919
973
|
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);
|
@@ -938,7 +992,9 @@ ${getStack()}`);
|
|
938
992
|
const { code, file } = fetchResult;
|
939
993
|
if (code == null) {
|
940
994
|
const importer = callstack[callstack.length - 2];
|
941
|
-
throw new Error(
|
995
|
+
throw new Error(
|
996
|
+
`[module runner] Failed to load "${id}"${importer ? ` imported from ${importer}` : ""}`
|
997
|
+
);
|
942
998
|
}
|
943
999
|
const modulePath = cleanUrl(file || moduleId), href = posixPathToFileHref(modulePath), filename = modulePath, dirname2 = posixDirname(modulePath), meta = {
|
944
1000
|
filename: isWindows ? toWindowsPath(filename) : filename,
|
@@ -946,7 +1002,9 @@ ${getStack()}`);
|
|
946
1002
|
url: href,
|
947
1003
|
env: this.envProxy,
|
948
1004
|
resolve(id2, parent) {
|
949
|
-
throw new Error(
|
1005
|
+
throw new Error(
|
1006
|
+
'[module runner] "import.meta.resolve" is not supported.'
|
1007
|
+
);
|
950
1008
|
},
|
951
1009
|
// should be replaced during transformation
|
952
1010
|
glob() {
|
@@ -1004,23 +1062,27 @@ class ESModulesEvaluator {
|
|
1004
1062
|
ssrExportAllKey,
|
1005
1063
|
// source map should already be inlined by Vite
|
1006
1064
|
'"use strict";' + code
|
1007
|
-
)(
|
1065
|
+
)(
|
1066
|
+
context[ssrModuleExportsKey],
|
1067
|
+
context[ssrImportMetaKey],
|
1068
|
+
context[ssrImportKey],
|
1069
|
+
context[ssrDynamicImportKey],
|
1070
|
+
context[ssrExportAllKey]
|
1071
|
+
), Object.seal(context[ssrModuleExportsKey]);
|
1008
1072
|
}
|
1009
1073
|
runExternalModule(filepath) {
|
1010
1074
|
return import(filepath);
|
1011
1075
|
}
|
1012
1076
|
}
|
1013
1077
|
class RemoteRunnerTransport {
|
1014
|
-
options;
|
1015
|
-
rpcPromises = /* @__PURE__ */ new Map();
|
1016
1078
|
constructor(options) {
|
1017
1079
|
this.options = options, this.options.onMessage(async (data) => {
|
1018
|
-
if (typeof data != "object" || !data || !data.__v)
|
1019
|
-
return;
|
1080
|
+
if (typeof data != "object" || !data || !data.__v) return;
|
1020
1081
|
const promise = this.rpcPromises.get(data.i);
|
1021
1082
|
promise && (promise.timeoutId && clearTimeout(promise.timeoutId), this.rpcPromises.delete(data.i), data.e ? promise.reject(data.e) : promise.resolve(data.r));
|
1022
1083
|
});
|
1023
1084
|
}
|
1085
|
+
rpcPromises = /* @__PURE__ */ new Map();
|
1024
1086
|
resolve(method, ...args) {
|
1025
1087
|
const promiseId = nanoid();
|
1026
1088
|
return this.options.send({
|
@@ -1032,7 +1094,11 @@ class RemoteRunnerTransport {
|
|
1032
1094
|
const timeout = this.options.timeout ?? 6e4;
|
1033
1095
|
let timeoutId;
|
1034
1096
|
timeout > 0 && (timeoutId = setTimeout(() => {
|
1035
|
-
this.rpcPromises.delete(promiseId), reject(
|
1097
|
+
this.rpcPromises.delete(promiseId), reject(
|
1098
|
+
new Error(
|
1099
|
+
`${method}(${args.map((arg) => JSON.stringify(arg)).join(", ")}) timed out after ${timeout}ms`
|
1100
|
+
)
|
1101
|
+
);
|
1036
1102
|
}, timeout), timeoutId?.unref?.()), this.rpcPromises.set(promiseId, { resolve: resolve2, reject, timeoutId });
|
1037
1103
|
});
|
1038
1104
|
}
|
@@ -1043,8 +1109,7 @@ class RemoteRunnerTransport {
|
|
1043
1109
|
const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
1044
1110
|
function nanoid(size = 21) {
|
1045
1111
|
let id = "", i = size;
|
1046
|
-
for (; i--; )
|
1047
|
-
id += urlAlphabet[Math.random() * 64 | 0];
|
1112
|
+
for (; i--; ) id += urlAlphabet[Math.random() * 64 | 0];
|
1048
1113
|
return id;
|
1049
1114
|
}
|
1050
1115
|
export {
|