vite-node 3.0.9 → 3.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -588,385 +588,302 @@ const reSourceMap = /^data:application\/json[^,]+base64,/;
588
588
  let retrieveFileHandlers = [];
589
589
  let retrieveMapHandlers = [];
590
590
  function globalProcessVersion() {
591
- if (typeof process === "object" && process !== null) {
592
- return process.version;
593
- } else {
594
- return "";
595
- }
591
+ if (typeof process === "object" && process !== null) return process.version;
592
+ else return "";
596
593
  }
597
594
  function handlerExec(list) {
598
- return function(arg) {
599
- for (let i = 0; i < list.length; i++) {
600
- const ret = list[i](arg);
601
- if (ret) {
602
- return ret;
603
- }
604
- }
605
- return null;
606
- };
595
+ return function(arg) {
596
+ for (let i = 0; i < list.length; i++) {
597
+ const ret = list[i](arg);
598
+ if (ret) return ret;
599
+ }
600
+ return null;
601
+ };
607
602
  }
608
603
  let retrieveFile = handlerExec(retrieveFileHandlers);
609
- retrieveFileHandlers.push((path2) => {
610
- path2 = path2.trim();
611
- if (path2.startsWith("file:")) {
612
- path2 = path2.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
613
- return drive ? "" : "/";
614
- });
615
- }
616
- if (path2 in fileContentsCache) {
617
- return fileContentsCache[path2];
618
- }
619
- let contents = "";
620
- try {
621
- if (fs.existsSync(path2)) {
622
- contents = fs.readFileSync(path2, "utf8");
623
- }
624
- } catch {
625
- }
626
- return fileContentsCache[path2] = contents;
604
+ retrieveFileHandlers.push((path) => {
605
+ path = path.trim();
606
+ if (path.startsWith("file:")) path = path.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
607
+ return drive ? "" : "/";
608
+ });
609
+ if (path in fileContentsCache) return fileContentsCache[path];
610
+ let contents = "";
611
+ try {
612
+ if (fs.existsSync(path)) contents = fs.readFileSync(path, "utf8");
613
+ } catch {}
614
+ return fileContentsCache[path] = contents;
627
615
  });
628
616
  function supportRelativeURL(file, url) {
629
- if (!file) {
630
- return url;
631
- }
632
- const dir = path.dirname(file);
633
- const match = /^\w+:\/\/[^/]*/.exec(dir);
634
- let protocol = match ? match[0] : "";
635
- const startPath = dir.slice(protocol.length);
636
- if (protocol && /^\/\w:/.test(startPath)) {
637
- protocol += "/";
638
- return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
639
- }
640
- return protocol + path.resolve(dir.slice(protocol.length), url);
617
+ if (!file) return url;
618
+ const dir = path.dirname(file);
619
+ const match = /^\w+:\/\/[^/]*/.exec(dir);
620
+ let protocol = match ? match[0] : "";
621
+ const startPath = dir.slice(protocol.length);
622
+ if (protocol && /^\/\w:/.test(startPath)) {
623
+ protocol += "/";
624
+ return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
625
+ }
626
+ return protocol + path.resolve(dir.slice(protocol.length), url);
641
627
  }
642
628
  function retrieveSourceMapURL(source) {
643
- const fileData = retrieveFile(source);
644
- if (!fileData) {
645
- return null;
646
- }
647
- const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
648
- let lastMatch, match;
649
- while (match = re.exec(fileData)) {
650
- lastMatch = match;
651
- }
652
- if (!lastMatch) {
653
- return null;
654
- }
655
- return lastMatch[1];
629
+ const fileData = retrieveFile(source);
630
+ if (!fileData) return null;
631
+ const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
632
+ let lastMatch, match;
633
+ while (match = re.exec(fileData)) lastMatch = match;
634
+ if (!lastMatch) return null;
635
+ return lastMatch[1];
656
636
  }
657
637
  let retrieveSourceMap = handlerExec(retrieveMapHandlers);
658
638
  retrieveMapHandlers.push((source) => {
659
- let sourceMappingURL = retrieveSourceMapURL(source);
660
- if (!sourceMappingURL) {
661
- return null;
662
- }
663
- let sourceMapData;
664
- if (reSourceMap.test(sourceMappingURL)) {
665
- const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
666
- sourceMapData = Buffer.from(rawData, "base64").toString();
667
- sourceMappingURL = source;
668
- } else {
669
- sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
670
- sourceMapData = retrieveFile(sourceMappingURL);
671
- }
672
- if (!sourceMapData) {
673
- return null;
674
- }
675
- return {
676
- url: sourceMappingURL,
677
- map: sourceMapData
678
- };
639
+ let sourceMappingURL = retrieveSourceMapURL(source);
640
+ if (!sourceMappingURL) return null;
641
+ let sourceMapData;
642
+ if (reSourceMap.test(sourceMappingURL)) {
643
+ const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
644
+ sourceMapData = Buffer.from(rawData, "base64").toString();
645
+ sourceMappingURL = source;
646
+ } else {
647
+ sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
648
+ sourceMapData = retrieveFile(sourceMappingURL);
649
+ }
650
+ if (!sourceMapData) return null;
651
+ return {
652
+ url: sourceMappingURL,
653
+ map: sourceMapData
654
+ };
679
655
  });
680
656
  function mapSourcePosition(position) {
681
- var _a;
682
- if (!position.source) {
683
- return position;
684
- }
685
- let sourceMap = sourceMapCache[position.source];
686
- if (!sourceMap) {
687
- const urlAndMap = retrieveSourceMap(position.source);
688
- if (urlAndMap && urlAndMap.map) {
689
- sourceMap = sourceMapCache[position.source] = {
690
- url: urlAndMap.url,
691
- map: new TraceMap(urlAndMap.map)
692
- };
693
- if ((_a = sourceMap.map) == null ? void 0 : _a.sourcesContent) {
694
- sourceMap.map.sources.forEach((source, i) => {
695
- var _a2, _b;
696
- const contents = (_b = (_a2 = sourceMap.map) == null ? void 0 : _a2.sourcesContent) == null ? void 0 : _b[i];
697
- if (contents && source && sourceMap.url) {
698
- const url = supportRelativeURL(sourceMap.url, source);
699
- fileContentsCache[url] = contents;
700
- }
701
- });
702
- }
703
- } else {
704
- sourceMap = sourceMapCache[position.source] = {
705
- url: null,
706
- map: null
707
- };
708
- }
709
- }
710
- if (sourceMap && sourceMap.map && sourceMap.url) {
711
- const originalPosition = originalPositionFor(sourceMap.map, position);
712
- if (originalPosition.source !== null) {
713
- originalPosition.source = supportRelativeURL(
714
- sourceMap.url,
715
- originalPosition.source
716
- );
717
- return originalPosition;
718
- }
719
- }
720
- return position;
657
+ if (!position.source) return position;
658
+ let sourceMap = sourceMapCache[position.source];
659
+ if (!sourceMap) {
660
+ const urlAndMap = retrieveSourceMap(position.source);
661
+ if (urlAndMap && urlAndMap.map) {
662
+ var _sourceMap$map;
663
+ sourceMap = sourceMapCache[position.source] = {
664
+ url: urlAndMap.url,
665
+ map: new TraceMap(urlAndMap.map)
666
+ };
667
+ if ((_sourceMap$map = sourceMap.map) === null || _sourceMap$map === void 0 ? void 0 : _sourceMap$map.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
668
+ var _sourceMap$map2;
669
+ 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];
670
+ if (contents && source && sourceMap.url) {
671
+ const url = supportRelativeURL(sourceMap.url, source);
672
+ fileContentsCache[url] = contents;
673
+ }
674
+ });
675
+ } else sourceMap = sourceMapCache[position.source] = {
676
+ url: null,
677
+ map: null
678
+ };
679
+ }
680
+ if (sourceMap && sourceMap.map && sourceMap.url) {
681
+ const originalPosition = originalPositionFor(sourceMap.map, position);
682
+ if (originalPosition.source !== null) {
683
+ originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
684
+ return originalPosition;
685
+ }
686
+ }
687
+ return position;
721
688
  }
722
689
  function mapEvalOrigin(origin) {
723
- let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
724
- if (match) {
725
- const position = mapSourcePosition({
726
- name: null,
727
- source: match[2],
728
- line: +match[3],
729
- column: +match[4] - 1
730
- });
731
- return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
732
- }
733
- match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
734
- if (match) {
735
- return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
736
- }
737
- return origin;
690
+ let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
691
+ if (match) {
692
+ const position = mapSourcePosition({
693
+ name: null,
694
+ source: match[2],
695
+ line: +match[3],
696
+ column: +match[4] - 1
697
+ });
698
+ return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
699
+ }
700
+ match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
701
+ if (match) return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
702
+ return origin;
738
703
  }
739
704
  function CallSiteToString() {
740
- let fileName;
741
- let fileLocation = "";
742
- if (this.isNative()) {
743
- fileLocation = "native";
744
- } else {
745
- fileName = this.getScriptNameOrSourceURL();
746
- if (!fileName && this.isEval()) {
747
- fileLocation = this.getEvalOrigin();
748
- fileLocation += ", ";
749
- }
750
- if (fileName) {
751
- fileLocation += fileName;
752
- } else {
753
- fileLocation += "<anonymous>";
754
- }
755
- const lineNumber = this.getLineNumber();
756
- if (lineNumber != null) {
757
- fileLocation += `:${lineNumber}`;
758
- const columnNumber = this.getColumnNumber();
759
- if (columnNumber) {
760
- fileLocation += `:${columnNumber}`;
761
- }
762
- }
763
- }
764
- let line = "";
765
- const functionName = this.getFunctionName();
766
- let addSuffix = true;
767
- const isConstructor = this.isConstructor();
768
- const isMethodCall = !(this.isToplevel() || isConstructor);
769
- if (isMethodCall) {
770
- let typeName = this.getTypeName();
771
- if (typeName === "[object Object]") {
772
- typeName = "null";
773
- }
774
- const methodName = this.getMethodName();
775
- if (functionName) {
776
- if (typeName && functionName.indexOf(typeName) !== 0) {
777
- line += `${typeName}.`;
778
- }
779
- line += functionName;
780
- if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) {
781
- line += ` [as ${methodName}]`;
782
- }
783
- } else {
784
- line += `${typeName}.${methodName || "<anonymous>"}`;
785
- }
786
- } else if (isConstructor) {
787
- line += `new ${functionName || "<anonymous>"}`;
788
- } else if (functionName) {
789
- line += functionName;
790
- } else {
791
- line += fileLocation;
792
- addSuffix = false;
793
- }
794
- if (addSuffix) {
795
- line += ` (${fileLocation})`;
796
- }
797
- return line;
705
+ let fileName;
706
+ let fileLocation = "";
707
+ if (this.isNative()) fileLocation = "native";
708
+ else {
709
+ fileName = this.getScriptNameOrSourceURL();
710
+ if (!fileName && this.isEval()) {
711
+ fileLocation = this.getEvalOrigin();
712
+ fileLocation += ", ";
713
+ }
714
+ if (fileName) fileLocation += fileName;
715
+ else fileLocation += "<anonymous>";
716
+ const lineNumber = this.getLineNumber();
717
+ if (lineNumber != null) {
718
+ fileLocation += `:${lineNumber}`;
719
+ const columnNumber = this.getColumnNumber();
720
+ if (columnNumber) fileLocation += `:${columnNumber}`;
721
+ }
722
+ }
723
+ let line = "";
724
+ const functionName = this.getFunctionName();
725
+ let addSuffix = true;
726
+ const isConstructor = this.isConstructor();
727
+ const isMethodCall = !(this.isToplevel() || isConstructor);
728
+ if (isMethodCall) {
729
+ let typeName = this.getTypeName();
730
+ if (typeName === "[object Object]") typeName = "null";
731
+ const methodName = this.getMethodName();
732
+ if (functionName) {
733
+ if (typeName && functionName.indexOf(typeName) !== 0) line += `${typeName}.`;
734
+ line += functionName;
735
+ if (methodName && functionName.indexOf(`.${methodName}`) !== functionName.length - methodName.length - 1) line += ` [as ${methodName}]`;
736
+ } else line += `${typeName}.${methodName || "<anonymous>"}`;
737
+ } else if (isConstructor) line += `new ${functionName || "<anonymous>"}`;
738
+ else if (functionName) line += functionName;
739
+ else {
740
+ line += fileLocation;
741
+ addSuffix = false;
742
+ }
743
+ if (addSuffix) line += ` (${fileLocation})`;
744
+ return line;
798
745
  }
799
746
  function cloneCallSite(frame) {
800
- const object = {};
801
- Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
802
- const key = name;
803
- object[key] = /^(?:is|get)/.test(name) ? function() {
804
- return frame[key].call(frame);
805
- } : frame[key];
806
- });
807
- object.toString = CallSiteToString;
808
- return object;
747
+ const object = {};
748
+ Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
749
+ const key = name;
750
+ object[key] = /^(?:is|get)/.test(name) ? function() {
751
+ return frame[key].call(frame);
752
+ } : frame[key];
753
+ });
754
+ object.toString = CallSiteToString;
755
+ return object;
809
756
  }
810
757
  function wrapCallSite(frame, state) {
811
- if (state === void 0) {
812
- state = { nextPosition: null, curPosition: null };
813
- }
814
- if (frame.isNative()) {
815
- state.curPosition = null;
816
- return frame;
817
- }
818
- const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
819
- if (source) {
820
- const line = frame.getLineNumber();
821
- let column = frame.getColumnNumber() - 1;
822
- 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)/;
823
- const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
824
- if (line === 1 && column > headerLength && !frame.isEval()) {
825
- column -= headerLength;
826
- }
827
- const position = mapSourcePosition({
828
- name: null,
829
- source,
830
- line,
831
- column
832
- });
833
- state.curPosition = position;
834
- frame = cloneCallSite(frame);
835
- const originalFunctionName = frame.getFunctionName;
836
- frame.getFunctionName = function() {
837
- if (state.nextPosition == null) {
838
- return originalFunctionName();
839
- }
840
- return state.nextPosition.name || originalFunctionName();
841
- };
842
- frame.getFileName = function() {
843
- return position.source ?? void 0;
844
- };
845
- frame.getLineNumber = function() {
846
- return position.line;
847
- };
848
- frame.getColumnNumber = function() {
849
- return position.column + 1;
850
- };
851
- frame.getScriptNameOrSourceURL = function() {
852
- return position.source;
853
- };
854
- return frame;
855
- }
856
- let origin = frame.isEval() && frame.getEvalOrigin();
857
- if (origin) {
858
- origin = mapEvalOrigin(origin);
859
- frame = cloneCallSite(frame);
860
- frame.getEvalOrigin = function() {
861
- return origin || void 0;
862
- };
863
- return frame;
864
- }
865
- return frame;
758
+ if (state === void 0) state = {
759
+ nextPosition: null,
760
+ curPosition: null
761
+ };
762
+ if (frame.isNative()) {
763
+ state.curPosition = null;
764
+ return frame;
765
+ }
766
+ const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
767
+ if (source) {
768
+ const line = frame.getLineNumber();
769
+ let column = frame.getColumnNumber() - 1;
770
+ 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)/;
771
+ const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
772
+ if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
773
+ const position = mapSourcePosition({
774
+ name: null,
775
+ source,
776
+ line,
777
+ column
778
+ });
779
+ state.curPosition = position;
780
+ frame = cloneCallSite(frame);
781
+ const originalFunctionName = frame.getFunctionName;
782
+ frame.getFunctionName = function() {
783
+ if (state.nextPosition == null) return originalFunctionName();
784
+ return state.nextPosition.name || originalFunctionName();
785
+ };
786
+ frame.getFileName = function() {
787
+ return position.source ?? void 0;
788
+ };
789
+ frame.getLineNumber = function() {
790
+ return position.line;
791
+ };
792
+ frame.getColumnNumber = function() {
793
+ return position.column + 1;
794
+ };
795
+ frame.getScriptNameOrSourceURL = function() {
796
+ return position.source;
797
+ };
798
+ return frame;
799
+ }
800
+ let origin = frame.isEval() && frame.getEvalOrigin();
801
+ if (origin) {
802
+ origin = mapEvalOrigin(origin);
803
+ frame = cloneCallSite(frame);
804
+ frame.getEvalOrigin = function() {
805
+ return origin || void 0;
806
+ };
807
+ return frame;
808
+ }
809
+ return frame;
866
810
  }
867
811
  function prepareStackTrace(error, stack) {
868
- const name = error.name || "Error";
869
- const message = error.message || "";
870
- const errorString = `${name}: ${message}`;
871
- const state = { nextPosition: null, curPosition: null };
872
- const processedStack = [];
873
- for (let i = stack.length - 1; i >= 0; i--) {
874
- processedStack.push(`
875
- at ${wrapCallSite(stack[i], state)}`);
876
- state.nextPosition = state.curPosition;
877
- }
878
- state.curPosition = state.nextPosition = null;
879
- return errorString + processedStack.reverse().join("");
812
+ const name = error.name || "Error";
813
+ const message = error.message || "";
814
+ const errorString = `${name}: ${message}`;
815
+ const state = {
816
+ nextPosition: null,
817
+ curPosition: null
818
+ };
819
+ const processedStack = [];
820
+ for (let i = stack.length - 1; i >= 0; i--) {
821
+ processedStack.push(`\n at ${wrapCallSite(stack[i], state)}`);
822
+ state.nextPosition = state.curPosition;
823
+ }
824
+ state.curPosition = state.nextPosition = null;
825
+ return errorString + processedStack.reverse().join("");
880
826
  }
881
827
  retrieveFileHandlers.slice(0);
882
828
  retrieveMapHandlers.slice(0);
883
829
  function install(options) {
884
- options = options || {};
885
- if (options.retrieveFile) {
886
- if (options.overrideRetrieveFile) {
887
- retrieveFileHandlers.length = 0;
888
- }
889
- retrieveFileHandlers.unshift(options.retrieveFile);
890
- }
891
- if (options.retrieveSourceMap) {
892
- if (options.overrideRetrieveSourceMap) {
893
- retrieveMapHandlers.length = 0;
894
- }
895
- retrieveMapHandlers.unshift(options.retrieveSourceMap);
896
- }
897
- if (!errorFormatterInstalled) {
898
- errorFormatterInstalled = true;
899
- Error.prepareStackTrace = prepareStackTrace;
900
- }
830
+ options = options || {};
831
+ if (options.retrieveFile) {
832
+ if (options.overrideRetrieveFile) retrieveFileHandlers.length = 0;
833
+ retrieveFileHandlers.unshift(options.retrieveFile);
834
+ }
835
+ if (options.retrieveSourceMap) {
836
+ if (options.overrideRetrieveSourceMap) retrieveMapHandlers.length = 0;
837
+ retrieveMapHandlers.unshift(options.retrieveSourceMap);
838
+ }
839
+ if (!errorFormatterInstalled) {
840
+ errorFormatterInstalled = true;
841
+ Error.prepareStackTrace = prepareStackTrace;
842
+ }
901
843
  }
902
844
 
903
845
  let SOURCEMAPPING_URL = "sourceMa";
904
846
  SOURCEMAPPING_URL += "ppingURL";
905
847
  const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
906
848
  const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
907
- const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(
908
- `//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`
909
- );
849
+ const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
910
850
  function withInlineSourcemap(result, options) {
911
- var _a;
912
- const map = result.map;
913
- let code = result.code;
914
- if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE)) {
915
- return result;
916
- }
917
- if ("sources" in map) {
918
- map.sources = (_a = map.sources) == null ? void 0 : _a.map((source) => {
919
- if (!source) {
920
- return source;
921
- }
922
- if (isAbsolute(source)) {
923
- const actualPath = !source.startsWith(withTrailingSlash(options.root)) && source.startsWith("/") ? resolve$2(options.root, source.slice(1)) : source;
924
- return relative(dirname(options.filepath), actualPath);
925
- }
926
- return source;
927
- });
928
- }
929
- const OTHER_SOURCE_MAP_REGEXP = new RegExp(
930
- `//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`,
931
- "gm"
932
- );
933
- while (OTHER_SOURCE_MAP_REGEXP.test(code)) {
934
- code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
935
- }
936
- if (!options.noFirstLineMapping && map.mappings.startsWith(";")) {
937
- map.mappings = `AAAA,CAAA${map.mappings}`;
938
- }
939
- const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString(
940
- "base64"
941
- );
942
- result.code = `${code.trimEnd()}
943
-
944
- ${VITE_NODE_SOURCEMAPPING_SOURCE}
945
- //# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}
946
- `;
947
- return result;
851
+ const map = result.map;
852
+ let code = result.code;
853
+ if (!map || code.includes(VITE_NODE_SOURCEMAPPING_SOURCE)) return result;
854
+ if ("sources" in map) {
855
+ var _map$sources;
856
+ map.sources = (_map$sources = map.sources) === null || _map$sources === void 0 ? void 0 : _map$sources.map((source) => {
857
+ if (!source) return source;
858
+ if (isAbsolute(source)) {
859
+ const actualPath = !source.startsWith(withTrailingSlash(options.root)) && source.startsWith("/") ? resolve$2(options.root, source.slice(1)) : source;
860
+ return relative(dirname(options.filepath), actualPath);
861
+ }
862
+ return source;
863
+ });
864
+ }
865
+ const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
866
+ while (OTHER_SOURCE_MAP_REGEXP.test(code)) code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
867
+ if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
868
+ const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
869
+ result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`;
870
+ return result;
948
871
  }
949
872
  function extractSourceMap(code) {
950
- var _a;
951
- const mapString = (_a = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) == null ? void 0 : _a[1];
952
- if (mapString) {
953
- return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
954
- }
955
- return null;
873
+ var _code$match;
874
+ const mapString = (_code$match = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) === null || _code$match === void 0 ? void 0 : _code$match[1];
875
+ if (mapString) return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
876
+ return null;
956
877
  }
957
878
  function installSourcemapsSupport(options) {
958
- install({
959
- retrieveSourceMap(source) {
960
- const map = options.getSourceMap(source);
961
- if (map) {
962
- return {
963
- url: source,
964
- map
965
- };
966
- }
967
- return null;
968
- }
969
- });
879
+ install({ retrieveSourceMap(source) {
880
+ const map = options.getSourceMap(source);
881
+ if (map) return {
882
+ url: source,
883
+ map
884
+ };
885
+ return null;
886
+ } });
970
887
  }
971
888
 
972
889
  export { extractSourceMap, installSourcemapsSupport, withInlineSourcemap };