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.
@@ -1,4 +1,4 @@
1
- import { isAbsolute, resolve as resolve$2, relative, dirname } from 'pathe';
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$1(input, base) {
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
- function resolve(input, base) {
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
- if (!path)
364
- return '';
365
- const index = path.lastIndexOf('/');
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
- const COLUMN = 0;
370
- const SOURCES_INDEX = 1;
371
- const SOURCE_LINE = 2;
372
- const SOURCE_COLUMN = 3;
373
- const NAMES_INDEX = 4;
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
- const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
377
- if (unsortedIndex === mappings.length)
378
- return mappings;
379
- // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
380
- // not, we do not want to modify the consumer's input array.
381
- if (!owned)
382
- mappings = mappings.slice();
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
- for (let i = start; i < mappings.length; i++) {
390
- if (!isSorted(mappings[i]))
391
- return i;
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
- for (let j = 1; j < line.length; j++) {
397
- if (line[j][COLUMN] < line[j - 1][COLUMN]) {
398
- return false;
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
- return true;
394
+ }
395
+ return true;
402
396
  }
403
397
  function sortSegments(line, owned) {
404
- if (!owned)
405
- line = line.slice();
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
- return a[COLUMN] - b[COLUMN];
402
+ return a[COLUMN] - b[COLUMN];
410
403
  }
411
404
 
412
- let found = false;
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
- while (low <= high) {
431
- const mid = low + ((high - low) >> 1);
432
- const cmp = haystack[mid][COLUMN] - needle;
433
- if (cmp === 0) {
434
- found = true;
435
- return mid;
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
- found = false;
445
- return low - 1;
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
- for (let i = index + 1; i < haystack.length; index = i++) {
449
- if (haystack[i][COLUMN] !== needle)
450
- break;
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
- for (let i = index - 1; i >= 0; index = i--) {
456
- if (haystack[i][COLUMN] !== needle)
457
- break;
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
- return {
463
- lastKey: -1,
464
- lastNeedle: -1,
465
- lastIndex: -1,
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
- const { lastKey, lastNeedle, lastIndex } = state;
474
- let low = 0;
475
- let high = haystack.length - 1;
476
- if (key === lastKey) {
477
- if (needle === lastNeedle) {
478
- found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
479
- return lastIndex;
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
- state.lastKey = key;
490
- state.lastNeedle = needle;
491
- return (state.lastIndex = binarySearch(haystack, needle, low, high));
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
- const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
495
- const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
496
- const LEAST_UPPER_BOUND = -1;
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
- * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
530
- * with public access modifiers.
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
- return map;
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
- var _a;
540
- return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
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
- let { line, column, bias } = needle;
549
- line--;
550
- if (line < 0)
551
- throw new Error(LINE_GTR_ZERO);
552
- if (column < 0)
553
- throw new Error(COL_GTR_EQ_ZERO);
554
- const decoded = decodedMappings(map);
555
- // It's common for parent source maps to have pointers to lines that have no
556
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
557
- if (line >= decoded.length)
558
- return OMapping(null, null, null, null);
559
- const segments = decoded[line];
560
- const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
561
- if (index === -1)
562
- return OMapping(null, null, null, null);
563
- const segment = segments[index];
564
- if (segment.length === 1)
565
- return OMapping(null, null, null, null);
566
- const { names, resolvedSources } = map;
567
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
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
- return { source, line, column, name };
539
+ return { source, line, column, name };
571
540
  }
572
541
  function traceSegmentInternal(segments, memo, line, column, bias) {
573
- let index = memoizedBinarySearch(segments, column, memo, line);
574
- if (found) {
575
- index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
576
- }
577
- else if (bias === LEAST_UPPER_BOUND)
578
- index++;
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
- if (typeof process === "object" && process !== null) return process.version;
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
- // Trim the path to make sure there is no extra whitespace.
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
- if (protocol && /^\/\w:/.test(startPath)) {
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
- if (!lastMatch) return null;
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
- sourceMappingURL = source;
667
- } else {
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 ((_sourceMap$map = sourceMap.map) === null || _sourceMap$map === void 0 ? void 0 : _sourceMap$map.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
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
- if (state.nextPosition == null) return originalFunctionName();
848
- return state.nextPosition.name || originalFunctionName();
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
- const processedStack = [];
888
- for (let i = stack.length - 1; i >= 0; i--) {
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$2(options.root, source.slice(1)) : source;
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
- // pick only the last source map keeping user strings that look like maps
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
- if (map) return {
856
+ return map ? {
966
857
  url: source,
967
858
  map
968
- };
969
- return null;
859
+ } : null;
970
860
  } });
971
861
  }
972
862