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