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.
- package/dist/chunk-hmr.cjs +193 -231
- package/dist/chunk-hmr.mjs +193 -231
- package/dist/cli.cjs +100 -113
- package/dist/cli.mjs +100 -113
- package/dist/client.cjs +387 -468
- package/dist/client.mjs +387 -468
- package/dist/constants.cjs +27 -33
- package/dist/constants.mjs +27 -33
- package/dist/server.cjs +354 -516
- package/dist/server.mjs +354 -516
- package/dist/source-map.cjs +258 -341
- package/dist/source-map.mjs +258 -341
- package/dist/utils.cjs +137 -152
- package/dist/utils.mjs +137 -152
- package/package.json +1 -1
package/dist/source-map.cjs
CHANGED
|
@@ -590,385 +590,302 @@ const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
|
590
590
|
let retrieveFileHandlers = [];
|
|
591
591
|
let retrieveMapHandlers = [];
|
|
592
592
|
function globalProcessVersion() {
|
|
593
|
-
|
|
594
|
-
|
|
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
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
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((
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
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
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
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
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
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
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
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
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
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
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
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
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
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
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
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
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
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
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
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
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
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;
|