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