vite-node 3.2.4 → 4.0.0-beta.10
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 +1 -1
- package/README.md +4 -2
- package/dist/chunk-hmr.cjs +25 -53
- package/dist/chunk-hmr.mjs +25 -53
- package/dist/cli.cjs +15 -36
- package/dist/cli.d.ts +2 -2
- package/dist/cli.mjs +15 -36
- package/dist/client.cjs +43 -107
- package/dist/client.d.ts +2 -2
- package/dist/client.mjs +43 -107
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/hmr.d.ts +4 -7
- package/dist/{index.d-DGmxD2U7.d.ts → index.d-uN06xifv.d.ts} +6 -7
- package/dist/index.d.ts +2 -2
- package/dist/server.cjs +42 -100
- package/dist/server.d.ts +3 -3
- package/dist/server.mjs +42 -100
- package/dist/source-map.cjs +209 -319
- package/dist/source-map.d.ts +4 -4
- package/dist/source-map.mjs +211 -321
- package/dist/{trace-mapping.d-DLVdEqOp.d.ts → trace-mapping.d-BWFx6tPc.d.ts} +6 -1
- package/dist/types.d.ts +2 -2
- package/dist/utils.cjs +13 -33
- package/dist/utils.d.ts +5 -5
- package/dist/utils.mjs +13 -33
- package/package.json +2 -2
package/dist/source-map.cjs
CHANGED
|
@@ -289,7 +289,7 @@ function normalizePath(url, type) {
|
|
|
289
289
|
/**
|
|
290
290
|
* Attempts to resolve `input` URL/path relative to `base`.
|
|
291
291
|
*/
|
|
292
|
-
function resolve
|
|
292
|
+
function resolve(input, base) {
|
|
293
293
|
if (!input && !base)
|
|
294
294
|
return '';
|
|
295
295
|
const url = parseUrl(input);
|
|
@@ -349,254 +349,214 @@ function resolve$1(input, base) {
|
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
351
|
|
|
352
|
-
|
|
353
|
-
// The base is always treated as a directory, if it's not empty.
|
|
354
|
-
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
|
355
|
-
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
|
356
|
-
if (base && !base.endsWith('/'))
|
|
357
|
-
base += '/';
|
|
358
|
-
return resolve$1(input, base);
|
|
359
|
-
}
|
|
352
|
+
// src/trace-mapping.ts
|
|
360
353
|
|
|
361
|
-
|
|
362
|
-
* Removes everything after the last "/", but leaves the slash.
|
|
363
|
-
*/
|
|
354
|
+
// src/strip-filename.ts
|
|
364
355
|
function stripFilename(path) {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return path.slice(0, index + 1);
|
|
356
|
+
if (!path) return "";
|
|
357
|
+
const index = path.lastIndexOf("/");
|
|
358
|
+
return path.slice(0, index + 1);
|
|
369
359
|
}
|
|
370
360
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
|
|
361
|
+
// src/resolve.ts
|
|
362
|
+
function resolver(mapUrl, sourceRoot) {
|
|
363
|
+
const from = stripFilename(mapUrl);
|
|
364
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
365
|
+
return (source) => resolve(prefix + (source || ""), from);
|
|
366
|
+
}
|
|
376
367
|
|
|
368
|
+
// src/sourcemap-segment.ts
|
|
369
|
+
var COLUMN = 0;
|
|
370
|
+
var SOURCES_INDEX = 1;
|
|
371
|
+
var SOURCE_LINE = 2;
|
|
372
|
+
var SOURCE_COLUMN = 3;
|
|
373
|
+
var NAMES_INDEX = 4;
|
|
374
|
+
|
|
375
|
+
// src/sort.ts
|
|
377
376
|
function maybeSort(mappings, owned) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
386
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
387
|
-
}
|
|
388
|
-
return mappings;
|
|
377
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
378
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
379
|
+
if (!owned) mappings = mappings.slice();
|
|
380
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
381
|
+
mappings[i] = sortSegments(mappings[i], owned);
|
|
382
|
+
}
|
|
383
|
+
return mappings;
|
|
389
384
|
}
|
|
390
385
|
function nextUnsortedSegmentLine(mappings, start) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
return mappings.length;
|
|
386
|
+
for (let i = start; i < mappings.length; i++) {
|
|
387
|
+
if (!isSorted(mappings[i])) return i;
|
|
388
|
+
}
|
|
389
|
+
return mappings.length;
|
|
396
390
|
}
|
|
397
391
|
function isSorted(line) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
392
|
+
for (let j = 1; j < line.length; j++) {
|
|
393
|
+
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
394
|
+
return false;
|
|
402
395
|
}
|
|
403
|
-
|
|
396
|
+
}
|
|
397
|
+
return true;
|
|
404
398
|
}
|
|
405
399
|
function sortSegments(line, owned) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return line.sort(sortComparator);
|
|
400
|
+
if (!owned) line = line.slice();
|
|
401
|
+
return line.sort(sortComparator);
|
|
409
402
|
}
|
|
410
403
|
function sortComparator(a, b) {
|
|
411
|
-
|
|
404
|
+
return a[COLUMN] - b[COLUMN];
|
|
412
405
|
}
|
|
413
406
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
* A binary search implementation that returns the index if a match is found.
|
|
417
|
-
* If no match is found, then the left-index (the index associated with the item that comes just
|
|
418
|
-
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
|
419
|
-
* the next index:
|
|
420
|
-
*
|
|
421
|
-
* ```js
|
|
422
|
-
* const array = [1, 3];
|
|
423
|
-
* const needle = 2;
|
|
424
|
-
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
|
425
|
-
*
|
|
426
|
-
* assert.equal(index, 0);
|
|
427
|
-
* array.splice(index + 1, 0, needle);
|
|
428
|
-
* assert.deepEqual(array, [1, 2, 3]);
|
|
429
|
-
* ```
|
|
430
|
-
*/
|
|
407
|
+
// src/binary-search.ts
|
|
408
|
+
var found = false;
|
|
431
409
|
function binarySearch(haystack, needle, low, high) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
if (cmp < 0) {
|
|
440
|
-
low = mid + 1;
|
|
441
|
-
}
|
|
442
|
-
else {
|
|
443
|
-
high = mid - 1;
|
|
444
|
-
}
|
|
410
|
+
while (low <= high) {
|
|
411
|
+
const mid = low + (high - low >> 1);
|
|
412
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
413
|
+
if (cmp === 0) {
|
|
414
|
+
found = true;
|
|
415
|
+
return mid;
|
|
445
416
|
}
|
|
446
|
-
|
|
447
|
-
|
|
417
|
+
if (cmp < 0) {
|
|
418
|
+
low = mid + 1;
|
|
419
|
+
} else {
|
|
420
|
+
high = mid - 1;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
found = false;
|
|
424
|
+
return low - 1;
|
|
448
425
|
}
|
|
449
426
|
function upperBound(haystack, needle, index) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return index;
|
|
427
|
+
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
428
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
429
|
+
}
|
|
430
|
+
return index;
|
|
455
431
|
}
|
|
456
432
|
function lowerBound(haystack, needle, index) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
return index;
|
|
433
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
434
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
435
|
+
}
|
|
436
|
+
return index;
|
|
462
437
|
}
|
|
463
438
|
function memoizedState() {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
439
|
+
return {
|
|
440
|
+
lastKey: -1,
|
|
441
|
+
lastNeedle: -1,
|
|
442
|
+
lastIndex: -1
|
|
443
|
+
};
|
|
469
444
|
}
|
|
470
|
-
/**
|
|
471
|
-
* This overly complicated beast is just to record the last tested line/column and the resulting
|
|
472
|
-
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
|
473
|
-
*/
|
|
474
445
|
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
if (needle >= lastNeedle) {
|
|
484
|
-
// lastIndex may be -1 if the previous needle was not found.
|
|
485
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
high = lastIndex;
|
|
489
|
-
}
|
|
446
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
447
|
+
let low = 0;
|
|
448
|
+
let high = haystack.length - 1;
|
|
449
|
+
if (key === lastKey) {
|
|
450
|
+
if (needle === lastNeedle) {
|
|
451
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
452
|
+
return lastIndex;
|
|
490
453
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
454
|
+
if (needle >= lastNeedle) {
|
|
455
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
456
|
+
} else {
|
|
457
|
+
high = lastIndex;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
state.lastKey = key;
|
|
461
|
+
state.lastNeedle = needle;
|
|
462
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
494
463
|
}
|
|
495
464
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const GREATEST_LOWER_BOUND = 1;
|
|
500
|
-
class TraceMap {
|
|
501
|
-
constructor(map, mapUrl) {
|
|
502
|
-
const isString = typeof map === 'string';
|
|
503
|
-
if (!isString && map._decodedMemo)
|
|
504
|
-
return map;
|
|
505
|
-
const parsed = (isString ? JSON.parse(map) : map);
|
|
506
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
507
|
-
this.version = version;
|
|
508
|
-
this.file = file;
|
|
509
|
-
this.names = names || [];
|
|
510
|
-
this.sourceRoot = sourceRoot;
|
|
511
|
-
this.sources = sources;
|
|
512
|
-
this.sourcesContent = sourcesContent;
|
|
513
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
|
|
514
|
-
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
|
515
|
-
this.resolvedSources = sources.map((s) => resolve(s || '', from));
|
|
516
|
-
const { mappings } = parsed;
|
|
517
|
-
if (typeof mappings === 'string') {
|
|
518
|
-
this._encoded = mappings;
|
|
519
|
-
this._decoded = undefined;
|
|
520
|
-
}
|
|
521
|
-
else {
|
|
522
|
-
this._encoded = undefined;
|
|
523
|
-
this._decoded = maybeSort(mappings, isString);
|
|
524
|
-
}
|
|
525
|
-
this._decodedMemo = memoizedState();
|
|
526
|
-
this._bySources = undefined;
|
|
527
|
-
this._bySourceMemos = undefined;
|
|
528
|
-
}
|
|
465
|
+
// src/types.ts
|
|
466
|
+
function parse(map) {
|
|
467
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
529
468
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
469
|
+
|
|
470
|
+
// src/trace-mapping.ts
|
|
471
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
472
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
473
|
+
var LEAST_UPPER_BOUND = -1;
|
|
474
|
+
var GREATEST_LOWER_BOUND = 1;
|
|
475
|
+
var TraceMap = class {
|
|
476
|
+
constructor(map, mapUrl) {
|
|
477
|
+
const isString = typeof map === "string";
|
|
478
|
+
if (!isString && map._decodedMemo) return map;
|
|
479
|
+
const parsed = parse(map);
|
|
480
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
481
|
+
this.version = version;
|
|
482
|
+
this.file = file;
|
|
483
|
+
this.names = names || [];
|
|
484
|
+
this.sourceRoot = sourceRoot;
|
|
485
|
+
this.sources = sources;
|
|
486
|
+
this.sourcesContent = sourcesContent;
|
|
487
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
488
|
+
const resolve = resolver(mapUrl, sourceRoot);
|
|
489
|
+
this.resolvedSources = sources.map(resolve);
|
|
490
|
+
const { mappings } = parsed;
|
|
491
|
+
if (typeof mappings === "string") {
|
|
492
|
+
this._encoded = mappings;
|
|
493
|
+
this._decoded = void 0;
|
|
494
|
+
} else if (Array.isArray(mappings)) {
|
|
495
|
+
this._encoded = void 0;
|
|
496
|
+
this._decoded = maybeSort(mappings, isString);
|
|
497
|
+
} else if (parsed.sections) {
|
|
498
|
+
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
499
|
+
} else {
|
|
500
|
+
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
501
|
+
}
|
|
502
|
+
this._decodedMemo = memoizedState();
|
|
503
|
+
this._bySources = void 0;
|
|
504
|
+
this._bySourceMemos = void 0;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
534
507
|
function cast(map) {
|
|
535
|
-
|
|
508
|
+
return map;
|
|
536
509
|
}
|
|
537
|
-
/**
|
|
538
|
-
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
|
539
|
-
*/
|
|
540
510
|
function decodedMappings(map) {
|
|
541
|
-
|
|
542
|
-
|
|
511
|
+
var _a;
|
|
512
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
543
513
|
}
|
|
544
|
-
/**
|
|
545
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
546
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
547
|
-
* `source-map` library.
|
|
548
|
-
*/
|
|
549
514
|
function originalPositionFor(map, needle) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
515
|
+
let { line, column, bias } = needle;
|
|
516
|
+
line--;
|
|
517
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
518
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
519
|
+
const decoded = decodedMappings(map);
|
|
520
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
521
|
+
const segments = decoded[line];
|
|
522
|
+
const index = traceSegmentInternal(
|
|
523
|
+
segments,
|
|
524
|
+
cast(map)._decodedMemo,
|
|
525
|
+
line,
|
|
526
|
+
column,
|
|
527
|
+
bias || GREATEST_LOWER_BOUND
|
|
528
|
+
);
|
|
529
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
530
|
+
const segment = segments[index];
|
|
531
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
532
|
+
const { names, resolvedSources } = map;
|
|
533
|
+
return OMapping(
|
|
534
|
+
resolvedSources[segment[SOURCES_INDEX]],
|
|
535
|
+
segment[SOURCE_LINE] + 1,
|
|
536
|
+
segment[SOURCE_COLUMN],
|
|
537
|
+
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
538
|
+
);
|
|
570
539
|
}
|
|
571
540
|
function OMapping(source, line, column, name) {
|
|
572
|
-
|
|
541
|
+
return { source, line, column, name };
|
|
573
542
|
}
|
|
574
543
|
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
if (index === -1 || index === segments.length)
|
|
582
|
-
return -1;
|
|
583
|
-
return index;
|
|
544
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
545
|
+
if (found) {
|
|
546
|
+
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
547
|
+
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
548
|
+
if (index === -1 || index === segments.length) return -1;
|
|
549
|
+
return index;
|
|
584
550
|
}
|
|
585
551
|
|
|
586
552
|
// Only install once if called multiple times
|
|
587
553
|
let errorFormatterInstalled = false;
|
|
588
554
|
// Maps a file path to a string containing the file contents
|
|
589
|
-
const fileContentsCache = {}
|
|
590
|
-
// Maps a file path to a source map for that file
|
|
591
|
-
const sourceMapCache = {};
|
|
592
|
-
// Regex for detecting source maps
|
|
593
|
-
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
555
|
+
const fileContentsCache = {}, sourceMapCache = {}, reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
594
556
|
// Priority list of retrieve handlers
|
|
595
|
-
let retrieveFileHandlers = [];
|
|
596
|
-
let retrieveMapHandlers = [];
|
|
557
|
+
let retrieveFileHandlers = [], retrieveMapHandlers = [];
|
|
597
558
|
function globalProcessVersion() {
|
|
598
|
-
|
|
599
|
-
else return "";
|
|
559
|
+
return typeof process === "object" && process !== null ? process.version : "";
|
|
600
560
|
}
|
|
601
561
|
function handlerExec(list) {
|
|
602
562
|
return function(arg) {
|
|
@@ -609,9 +569,7 @@ function handlerExec(list) {
|
|
|
609
569
|
}
|
|
610
570
|
let retrieveFile = handlerExec(retrieveFileHandlers);
|
|
611
571
|
retrieveFileHandlers.push((path) => {
|
|
612
|
-
|
|
613
|
-
path = path.trim();
|
|
614
|
-
if (path.startsWith("file:"))
|
|
572
|
+
if (path = path.trim(), path.startsWith("file:"))
|
|
615
573
|
// existsSync/readFileSync can't handle file protocol, but once stripped, it works
|
|
616
574
|
path = path.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
|
|
617
575
|
return drive ? "" : "/";
|
|
@@ -626,16 +584,10 @@ retrieveFileHandlers.push((path) => {
|
|
|
626
584
|
// Support URLs relative to a directory, but be careful about a protocol prefix
|
|
627
585
|
function supportRelativeURL(file, url) {
|
|
628
586
|
if (!file) return url;
|
|
629
|
-
const dir = path.dirname(file);
|
|
630
|
-
const match = /^\w+:\/\/[^/]*/.exec(dir);
|
|
587
|
+
const dir = path.dirname(file), match = /^\w+:\/\/[^/]*/.exec(dir);
|
|
631
588
|
let protocol = match ? match[0] : "";
|
|
632
589
|
const startPath = dir.slice(protocol.length);
|
|
633
|
-
|
|
634
|
-
// handle file:///C:/ paths
|
|
635
|
-
protocol += "/";
|
|
636
|
-
return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
|
|
637
|
-
}
|
|
638
|
-
return protocol + path.resolve(dir.slice(protocol.length), url);
|
|
590
|
+
return protocol && /^\/\w:/.test(startPath) ? (protocol += "/", protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/")) : protocol + path.resolve(dir.slice(protocol.length), url);
|
|
639
591
|
}
|
|
640
592
|
function retrieveSourceMapURL(source) {
|
|
641
593
|
// Get the URL of the source map
|
|
@@ -647,8 +599,7 @@ function retrieveSourceMapURL(source) {
|
|
|
647
599
|
let lastMatch, match;
|
|
648
600
|
// eslint-disable-next-line no-cond-assign
|
|
649
601
|
while (match = re.exec(fileData)) lastMatch = match;
|
|
650
|
-
|
|
651
|
-
return lastMatch[1];
|
|
602
|
+
return lastMatch ? lastMatch[1] : null;
|
|
652
603
|
}
|
|
653
604
|
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
|
654
605
|
// generated source filename; returns a {map, optional url} object, or null if
|
|
@@ -664,18 +615,12 @@ retrieveMapHandlers.push((source) => {
|
|
|
664
615
|
if (reSourceMap.test(sourceMappingURL)) {
|
|
665
616
|
// Support source map URL as a data url
|
|
666
617
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
667
|
-
sourceMapData = Buffer.from(rawData, "base64").toString();
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
// Support source map URLs relative to the source URL
|
|
671
|
-
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
|
672
|
-
sourceMapData = retrieveFile(sourceMappingURL);
|
|
673
|
-
}
|
|
674
|
-
if (!sourceMapData) return null;
|
|
675
|
-
return {
|
|
618
|
+
sourceMapData = Buffer.from(rawData, "base64").toString(), sourceMappingURL = source;
|
|
619
|
+
} else sourceMappingURL = supportRelativeURL(source, sourceMappingURL), sourceMapData = retrieveFile(sourceMappingURL);
|
|
620
|
+
return sourceMapData ? {
|
|
676
621
|
url: sourceMappingURL,
|
|
677
622
|
map: sourceMapData
|
|
678
|
-
};
|
|
623
|
+
} : null;
|
|
679
624
|
});
|
|
680
625
|
// interface Position {
|
|
681
626
|
// source: string
|
|
@@ -687,17 +632,15 @@ function mapSourcePosition(position) {
|
|
|
687
632
|
let sourceMap = sourceMapCache[position.source];
|
|
688
633
|
if (!sourceMap) {
|
|
689
634
|
// Call the (overridable) retrieveSourceMap function to get the source map.
|
|
690
|
-
const urlAndMap = retrieveSourceMap(position.source);
|
|
691
|
-
const map = urlAndMap && urlAndMap.map;
|
|
635
|
+
const urlAndMap = retrieveSourceMap(position.source), map = urlAndMap && urlAndMap.map;
|
|
692
636
|
if (map && !(typeof map === "object" && "mappings" in map && map.mappings === "")) {
|
|
693
637
|
var _sourceMap$map;
|
|
694
|
-
sourceMap = sourceMapCache[position.source] = {
|
|
695
|
-
url: urlAndMap.url,
|
|
696
|
-
map: new TraceMap(map)
|
|
697
|
-
};
|
|
698
638
|
// Load all sources stored inline with the source map into the file cache
|
|
699
639
|
// to pretend like they are already loaded. They may not exist on disk.
|
|
700
|
-
if (
|
|
640
|
+
if (sourceMap = sourceMapCache[position.source] = {
|
|
641
|
+
url: urlAndMap.url,
|
|
642
|
+
map: new TraceMap(map)
|
|
643
|
+
}, (_sourceMap$map = sourceMap.map) === null || _sourceMap$map === void 0 ? void 0 : _sourceMap$map.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
|
|
701
644
|
var _sourceMap$map2;
|
|
702
645
|
const contents = (_sourceMap$map2 = sourceMap.map) === null || _sourceMap$map2 === void 0 || (_sourceMap$map2 = _sourceMap$map2.sourcesContent) === null || _sourceMap$map2 === void 0 ? void 0 : _sourceMap$map2[i];
|
|
703
646
|
if (contents && source && sourceMap.url) {
|
|
@@ -718,10 +661,7 @@ function mapSourcePosition(position) {
|
|
|
718
661
|
// the stack trace to print the path and line for the compiled file. It is
|
|
719
662
|
// better to give a precise location in the compiled file than a vague
|
|
720
663
|
// location in the original file.
|
|
721
|
-
if (originalPosition.source !== null)
|
|
722
|
-
originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
|
|
723
|
-
return originalPosition;
|
|
724
|
-
}
|
|
664
|
+
if (originalPosition.source !== null) return originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source), originalPosition;
|
|
725
665
|
}
|
|
726
666
|
return position;
|
|
727
667
|
}
|
|
@@ -739,11 +679,8 @@ function mapEvalOrigin(origin) {
|
|
|
739
679
|
});
|
|
740
680
|
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
741
681
|
}
|
|
742
|
-
// Parse nested eval() calls using recursion
|
|
743
|
-
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
744
|
-
if (match) return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
|
745
682
|
// Make sure we still return useful information if we didn't find anything
|
|
746
|
-
return origin;
|
|
683
|
+
return match = /^eval at ([^(]+) \((.+)\)$/.exec(origin), match ? `eval at ${match[1]} (${mapEvalOrigin(match[2])})` : origin;
|
|
747
684
|
}
|
|
748
685
|
// This is copied almost verbatim from the V8 source code at
|
|
749
686
|
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
|
|
@@ -752,15 +689,10 @@ function mapEvalOrigin(origin) {
|
|
|
752
689
|
// did something to the prototype chain and broke the shim. The only fix I
|
|
753
690
|
// could find was copy/paste.
|
|
754
691
|
function CallSiteToString() {
|
|
755
|
-
let fileName;
|
|
756
|
-
let fileLocation = "";
|
|
692
|
+
let fileName, fileLocation = "";
|
|
757
693
|
if (this.isNative()) fileLocation = "native";
|
|
758
694
|
else {
|
|
759
|
-
fileName = this.getScriptNameOrSourceURL();
|
|
760
|
-
if (!fileName && this.isEval()) {
|
|
761
|
-
fileLocation = this.getEvalOrigin();
|
|
762
|
-
fileLocation += ", ";
|
|
763
|
-
}
|
|
695
|
+
if (fileName = this.getScriptNameOrSourceURL(), !fileName && this.isEval()) fileLocation = this.getEvalOrigin(), fileLocation += ", ";
|
|
764
696
|
if (fileName) fileLocation += fileName;
|
|
765
697
|
else
|
|
766
698
|
// Source code does not originate from a file and is not native, but we
|
|
@@ -777,8 +709,7 @@ function CallSiteToString() {
|
|
|
777
709
|
let line = "";
|
|
778
710
|
const functionName = this.getFunctionName();
|
|
779
711
|
let addSuffix = true;
|
|
780
|
-
const isConstructor = this.isConstructor();
|
|
781
|
-
const isMethodCall = !(this.isToplevel() || isConstructor);
|
|
712
|
+
const isConstructor = this.isConstructor(), isMethodCall = !(this.isToplevel() || isConstructor);
|
|
782
713
|
if (isMethodCall) {
|
|
783
714
|
let typeName = this.getTypeName();
|
|
784
715
|
// Fixes shim to be backward compatible with Node v0 to v4
|
|
@@ -786,30 +717,24 @@ function CallSiteToString() {
|
|
|
786
717
|
const methodName = this.getMethodName();
|
|
787
718
|
if (functionName) {
|
|
788
719
|
if (typeName && functionName.indexOf(typeName) !== 0) line += `${typeName}.`;
|
|
789
|
-
line += functionName
|
|
790
|
-
if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) line += ` [as ${methodName}]`;
|
|
720
|
+
if (line += functionName, methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) line += ` [as ${methodName}]`;
|
|
791
721
|
} else line += `${typeName}.${methodName || "<anonymous>"}`;
|
|
792
722
|
} else if (isConstructor) line += `new ${functionName || "<anonymous>"}`;
|
|
793
723
|
else if (functionName) line += functionName;
|
|
794
|
-
else
|
|
795
|
-
line += fileLocation;
|
|
796
|
-
addSuffix = false;
|
|
797
|
-
}
|
|
724
|
+
else line += fileLocation, addSuffix = false;
|
|
798
725
|
if (addSuffix) line += ` (${fileLocation})`;
|
|
799
726
|
return line;
|
|
800
727
|
}
|
|
801
728
|
function cloneCallSite(frame) {
|
|
802
729
|
const object = {};
|
|
803
|
-
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
730
|
+
return Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
804
731
|
const key = name;
|
|
805
732
|
// @ts-expect-error difficult to type
|
|
806
733
|
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
807
734
|
// eslint-disable-next-line no-useless-call
|
|
808
735
|
return frame[key].call(frame);
|
|
809
736
|
} : frame[key];
|
|
810
|
-
});
|
|
811
|
-
object.toString = CallSiteToString;
|
|
812
|
-
return object;
|
|
737
|
+
}), object.toString = CallSiteToString, object;
|
|
813
738
|
}
|
|
814
739
|
function wrapCallSite(frame, state) {
|
|
815
740
|
// provides interface backward compatibility
|
|
@@ -817,10 +742,7 @@ function wrapCallSite(frame, state) {
|
|
|
817
742
|
nextPosition: null,
|
|
818
743
|
curPosition: null
|
|
819
744
|
};
|
|
820
|
-
if (frame.isNative())
|
|
821
|
-
state.curPosition = null;
|
|
822
|
-
return frame;
|
|
823
|
-
}
|
|
745
|
+
if (frame.isNative()) return state.curPosition = null, frame;
|
|
824
746
|
// Most call sites will return the source file from getFileName(), but code
|
|
825
747
|
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
|
826
748
|
// from getScriptNameOrSourceURL() instead
|
|
@@ -833,8 +755,7 @@ function wrapCallSite(frame, state) {
|
|
|
833
755
|
// Header removed in node at ^10.16 || >=11.11.0
|
|
834
756
|
// v11 is not an LTS candidate, we can just test the one version with it.
|
|
835
757
|
// Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
|
|
836
|
-
const noHeader = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)
|
|
837
|
-
const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
758
|
+
const noHeader = /^v(?:10\.1[6-9]|10\.[2-9]\d|10\.\d{3,}|1[2-9]\d*|[2-9]\d|\d{3,}|11\.11)/, headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
838
759
|
if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
|
|
839
760
|
const position = mapSourcePosition({
|
|
840
761
|
name: null,
|
|
@@ -842,65 +763,42 @@ function wrapCallSite(frame, state) {
|
|
|
842
763
|
line,
|
|
843
764
|
column
|
|
844
765
|
});
|
|
845
|
-
state.curPosition = position;
|
|
846
|
-
frame = cloneCallSite(frame);
|
|
766
|
+
state.curPosition = position, frame = cloneCallSite(frame);
|
|
847
767
|
const originalFunctionName = frame.getFunctionName;
|
|
848
|
-
frame.getFunctionName = function() {
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
};
|
|
852
|
-
frame.getFileName = function() {
|
|
768
|
+
return frame.getFunctionName = function() {
|
|
769
|
+
return state.nextPosition == null ? originalFunctionName() : state.nextPosition.name || originalFunctionName();
|
|
770
|
+
}, frame.getFileName = function() {
|
|
853
771
|
return position.source ?? null;
|
|
854
|
-
}
|
|
855
|
-
frame.getLineNumber = function() {
|
|
772
|
+
}, frame.getLineNumber = function() {
|
|
856
773
|
return position.line;
|
|
857
|
-
}
|
|
858
|
-
frame.getColumnNumber = function() {
|
|
774
|
+
}, frame.getColumnNumber = function() {
|
|
859
775
|
return position.column + 1;
|
|
860
|
-
}
|
|
861
|
-
frame.getScriptNameOrSourceURL = function() {
|
|
776
|
+
}, frame.getScriptNameOrSourceURL = function() {
|
|
862
777
|
return position.source;
|
|
863
|
-
};
|
|
864
|
-
return frame;
|
|
778
|
+
}, frame;
|
|
865
779
|
}
|
|
866
780
|
// Code called using eval() needs special handling
|
|
867
781
|
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
868
|
-
if (origin) {
|
|
869
|
-
origin = mapEvalOrigin(origin);
|
|
870
|
-
frame = cloneCallSite(frame);
|
|
871
|
-
frame.getEvalOrigin = function() {
|
|
872
|
-
return origin || void 0;
|
|
873
|
-
};
|
|
874
|
-
return frame;
|
|
875
|
-
}
|
|
876
782
|
// If we get here then we were unable to change the source position
|
|
877
|
-
return frame
|
|
783
|
+
return origin ? (origin = mapEvalOrigin(origin), frame = cloneCallSite(frame), frame.getEvalOrigin = function() {
|
|
784
|
+
return origin || void 0;
|
|
785
|
+
}, frame) : frame;
|
|
878
786
|
}
|
|
879
787
|
// This function is part of the V8 stack trace API, for more info see:
|
|
880
788
|
// https://v8.dev/docs/stack-trace-api
|
|
881
789
|
function prepareStackTrace(error, stack) {
|
|
882
|
-
const name = error.name || "Error"
|
|
883
|
-
const message = error.message || "";
|
|
884
|
-
const errorString = `${name}: ${message}`;
|
|
885
|
-
const state = {
|
|
790
|
+
const name = error.name || "Error", message = error.message || "", errorString = `${name}: ${message}`, state = {
|
|
886
791
|
nextPosition: null,
|
|
887
792
|
curPosition: null
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`);
|
|
892
|
-
state.nextPosition = state.curPosition;
|
|
893
|
-
}
|
|
894
|
-
state.curPosition = state.nextPosition = null;
|
|
895
|
-
return errorString + processedStack.reverse().join("");
|
|
793
|
+
}, processedStack = [];
|
|
794
|
+
for (let i = stack.length - 1; i >= 0; i--) processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`), state.nextPosition = state.curPosition;
|
|
795
|
+
return state.curPosition = state.nextPosition = null, errorString + processedStack.reverse().join("");
|
|
896
796
|
}
|
|
897
|
-
retrieveFileHandlers.slice(0);
|
|
898
|
-
retrieveMapHandlers.slice(0);
|
|
797
|
+
retrieveFileHandlers.slice(0); retrieveMapHandlers.slice(0);
|
|
899
798
|
function install(options) {
|
|
900
|
-
options = options || {};
|
|
901
799
|
// Allow sources to be found by methods other than reading the files
|
|
902
800
|
// directly from disk.
|
|
903
|
-
if (options.retrieveFile) {
|
|
801
|
+
if (options = options || {}, options.retrieveFile) {
|
|
904
802
|
if (options.overrideRetrieveFile) retrieveFileHandlers.length = 0;
|
|
905
803
|
retrieveFileHandlers.unshift(options.retrieveFile);
|
|
906
804
|
}
|
|
@@ -911,16 +809,12 @@ function install(options) {
|
|
|
911
809
|
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
912
810
|
}
|
|
913
811
|
// Install the error reformatter
|
|
914
|
-
if (!errorFormatterInstalled)
|
|
915
|
-
errorFormatterInstalled = true;
|
|
916
|
-
Error.prepareStackTrace = prepareStackTrace;
|
|
917
|
-
}
|
|
812
|
+
if (!errorFormatterInstalled) errorFormatterInstalled = true, Error.prepareStackTrace = prepareStackTrace;
|
|
918
813
|
}
|
|
919
814
|
|
|
920
815
|
let SOURCEMAPPING_URL = "sourceMa";
|
|
921
816
|
SOURCEMAPPING_URL += "ppingURL";
|
|
922
|
-
const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
|
|
923
|
-
const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
817
|
+
const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node", VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
924
818
|
function withInlineSourcemap(result, options) {
|
|
925
819
|
const map = result.map;
|
|
926
820
|
let code = result.code;
|
|
@@ -949,26 +843,22 @@ function withInlineSourcemap(result, options) {
|
|
|
949
843
|
// so we don't need to add this mapping anymore.
|
|
950
844
|
if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
|
|
951
845
|
const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
|
|
952
|
-
result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n
|
|
953
|
-
return result;
|
|
846
|
+
return result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`, result;
|
|
954
847
|
}
|
|
955
848
|
function extractSourceMap(code) {
|
|
956
849
|
const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
|
|
957
850
|
let lastMatch, match;
|
|
958
851
|
// eslint-disable-next-line no-cond-assign
|
|
959
852
|
while (match = regexp.exec(code)) lastMatch = match;
|
|
960
|
-
|
|
961
|
-
if (lastMatch) return JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8"));
|
|
962
|
-
return null;
|
|
853
|
+
return lastMatch ? JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8")) : null;
|
|
963
854
|
}
|
|
964
855
|
function installSourcemapsSupport(options) {
|
|
965
856
|
install({ retrieveSourceMap(source) {
|
|
966
857
|
const map = options.getSourceMap(source);
|
|
967
|
-
|
|
858
|
+
return map ? {
|
|
968
859
|
url: source,
|
|
969
860
|
map
|
|
970
|
-
};
|
|
971
|
-
return null;
|
|
861
|
+
} : null;
|
|
972
862
|
} });
|
|
973
863
|
}
|
|
974
864
|
|