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.mjs
CHANGED
|
@@ -588,385 +588,302 @@ const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
|
588
588
|
let retrieveFileHandlers = [];
|
|
589
589
|
let retrieveMapHandlers = [];
|
|
590
590
|
function globalProcessVersion() {
|
|
591
|
-
|
|
592
|
-
|
|
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
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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((
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
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
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
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
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
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
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
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
|
-
|
|
682
|
-
|
|
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
|
-
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
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
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
|
-
|
|
741
|
-
|
|
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
|
-
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
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
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
|
-
|
|
812
|
-
|
|
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
|
-
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
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
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
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
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
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
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
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
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
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
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 };
|