vite-node 3.2.0-beta.2 → 3.2.0
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 +29 -12
- package/dist/chunk-hmr.mjs +29 -12
- package/dist/cli.cjs +5 -2
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +7 -4
- package/dist/client.cjs +84 -8
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +84 -8
- package/dist/hmr.d.ts +4 -1
- package/dist/{index.d-CWZbpOcv.d.ts → index.d-DGmxD2U7.d.ts} +48 -8
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +36 -15
- package/dist/server.d.ts +1 -1
- package/dist/server.mjs +36 -15
- package/dist/source-map.cjs +90 -7
- package/dist/source-map.mjs +90 -7
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +10 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +10 -1
- package/package.json +3 -3
package/dist/source-map.mjs
CHANGED
|
@@ -581,10 +581,15 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
|
581
581
|
return index;
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
// Only install once if called multiple times
|
|
584
585
|
let errorFormatterInstalled = false;
|
|
586
|
+
// Maps a file path to a string containing the file contents
|
|
585
587
|
const fileContentsCache = {};
|
|
588
|
+
// Maps a file path to a source map for that file
|
|
586
589
|
const sourceMapCache = {};
|
|
590
|
+
// Regex for detecting source maps
|
|
587
591
|
const reSourceMap = /^data:application\/json[^,]+base64,/;
|
|
592
|
+
// Priority list of retrieve handlers
|
|
588
593
|
let retrieveFileHandlers = [];
|
|
589
594
|
let retrieveMapHandlers = [];
|
|
590
595
|
function globalProcessVersion() {
|
|
@@ -602,8 +607,11 @@ function handlerExec(list) {
|
|
|
602
607
|
}
|
|
603
608
|
let retrieveFile = handlerExec(retrieveFileHandlers);
|
|
604
609
|
retrieveFileHandlers.push((path) => {
|
|
610
|
+
// Trim the path to make sure there is no extra whitespace.
|
|
605
611
|
path = path.trim();
|
|
606
|
-
if (path.startsWith("file:"))
|
|
612
|
+
if (path.startsWith("file:"))
|
|
613
|
+
// existsSync/readFileSync can't handle file protocol, but once stripped, it works
|
|
614
|
+
path = path.replace(/file:\/\/\/(\w:)?/, (protocol, drive) => {
|
|
607
615
|
return drive ? "" : "/";
|
|
608
616
|
});
|
|
609
617
|
if (path in fileContentsCache) return fileContentsCache[path];
|
|
@@ -613,6 +621,7 @@ retrieveFileHandlers.push((path) => {
|
|
|
613
621
|
} catch {}
|
|
614
622
|
return fileContentsCache[path] = contents;
|
|
615
623
|
});
|
|
624
|
+
// Support URLs relative to a directory, but be careful about a protocol prefix
|
|
616
625
|
function supportRelativeURL(file, url) {
|
|
617
626
|
if (!file) return url;
|
|
618
627
|
const dir = path.dirname(file);
|
|
@@ -620,30 +629,43 @@ function supportRelativeURL(file, url) {
|
|
|
620
629
|
let protocol = match ? match[0] : "";
|
|
621
630
|
const startPath = dir.slice(protocol.length);
|
|
622
631
|
if (protocol && /^\/\w:/.test(startPath)) {
|
|
632
|
+
// handle file:///C:/ paths
|
|
623
633
|
protocol += "/";
|
|
624
634
|
return protocol + path.resolve(dir.slice(protocol.length), url).replace(/\\/g, "/");
|
|
625
635
|
}
|
|
626
636
|
return protocol + path.resolve(dir.slice(protocol.length), url);
|
|
627
637
|
}
|
|
628
638
|
function retrieveSourceMapURL(source) {
|
|
639
|
+
// Get the URL of the source map
|
|
629
640
|
const fileData = retrieveFile(source);
|
|
630
641
|
if (!fileData) return null;
|
|
631
642
|
const re = /\/\/[@#]\s*sourceMappingURL=([^\s'"]+)\s*$|\/\*[@#]\s*sourceMappingURL=[^\s*'"]+\s*\*\/\s*$/gm;
|
|
643
|
+
// Keep executing the search to find the *last* sourceMappingURL to avoid
|
|
644
|
+
// picking up sourceMappingURLs from comments, strings, etc.
|
|
632
645
|
let lastMatch, match;
|
|
646
|
+
// eslint-disable-next-line no-cond-assign
|
|
633
647
|
while (match = re.exec(fileData)) lastMatch = match;
|
|
634
648
|
if (!lastMatch) return null;
|
|
635
649
|
return lastMatch[1];
|
|
636
650
|
}
|
|
651
|
+
// Can be overridden by the retrieveSourceMap option to install. Takes a
|
|
652
|
+
// generated source filename; returns a {map, optional url} object, or null if
|
|
653
|
+
// there is no source map. The map field may be either a string or the parsed
|
|
654
|
+
// JSON object (ie, it must be a valid argument to the SourceMapConsumer
|
|
655
|
+
// constructor).
|
|
637
656
|
let retrieveSourceMap = handlerExec(retrieveMapHandlers);
|
|
638
657
|
retrieveMapHandlers.push((source) => {
|
|
639
658
|
let sourceMappingURL = retrieveSourceMapURL(source);
|
|
640
659
|
if (!sourceMappingURL) return null;
|
|
660
|
+
// Read the contents of the source map
|
|
641
661
|
let sourceMapData;
|
|
642
662
|
if (reSourceMap.test(sourceMappingURL)) {
|
|
663
|
+
// Support source map URL as a data url
|
|
643
664
|
const rawData = sourceMappingURL.slice(sourceMappingURL.indexOf(",") + 1);
|
|
644
665
|
sourceMapData = Buffer.from(rawData, "base64").toString();
|
|
645
666
|
sourceMappingURL = source;
|
|
646
667
|
} else {
|
|
668
|
+
// Support source map URLs relative to the source URL
|
|
647
669
|
sourceMappingURL = supportRelativeURL(source, sourceMappingURL);
|
|
648
670
|
sourceMapData = retrieveFile(sourceMappingURL);
|
|
649
671
|
}
|
|
@@ -653,10 +675,16 @@ retrieveMapHandlers.push((source) => {
|
|
|
653
675
|
map: sourceMapData
|
|
654
676
|
};
|
|
655
677
|
});
|
|
678
|
+
// interface Position {
|
|
679
|
+
// source: string
|
|
680
|
+
// line: number
|
|
681
|
+
// column: number
|
|
682
|
+
// }
|
|
656
683
|
function mapSourcePosition(position) {
|
|
657
684
|
if (!position.source) return position;
|
|
658
685
|
let sourceMap = sourceMapCache[position.source];
|
|
659
686
|
if (!sourceMap) {
|
|
687
|
+
// Call the (overridable) retrieveSourceMap function to get the source map.
|
|
660
688
|
const urlAndMap = retrieveSourceMap(position.source);
|
|
661
689
|
if (urlAndMap && urlAndMap.map) {
|
|
662
690
|
var _sourceMap$map;
|
|
@@ -664,6 +692,8 @@ function mapSourcePosition(position) {
|
|
|
664
692
|
url: urlAndMap.url,
|
|
665
693
|
map: new TraceMap(urlAndMap.map)
|
|
666
694
|
};
|
|
695
|
+
// Load all sources stored inline with the source map into the file cache
|
|
696
|
+
// to pretend like they are already loaded. They may not exist on disk.
|
|
667
697
|
if ((_sourceMap$map = sourceMap.map) === null || _sourceMap$map === void 0 ? void 0 : _sourceMap$map.sourcesContent) sourceMap.map.sources.forEach((source, i) => {
|
|
668
698
|
var _sourceMap$map2;
|
|
669
699
|
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];
|
|
@@ -677,8 +707,14 @@ function mapSourcePosition(position) {
|
|
|
677
707
|
map: null
|
|
678
708
|
};
|
|
679
709
|
}
|
|
710
|
+
// Resolve the source URL relative to the URL of the source map
|
|
680
711
|
if (sourceMap && sourceMap.map && sourceMap.url) {
|
|
681
712
|
const originalPosition = originalPositionFor(sourceMap.map, position);
|
|
713
|
+
// Only return the original position if a matching line was found. If no
|
|
714
|
+
// matching line is found then we return position instead, which will cause
|
|
715
|
+
// the stack trace to print the path and line for the compiled file. It is
|
|
716
|
+
// better to give a precise location in the compiled file than a vague
|
|
717
|
+
// location in the original file.
|
|
682
718
|
if (originalPosition.source !== null) {
|
|
683
719
|
originalPosition.source = supportRelativeURL(sourceMap.url, originalPosition.source);
|
|
684
720
|
return originalPosition;
|
|
@@ -686,7 +722,10 @@ function mapSourcePosition(position) {
|
|
|
686
722
|
}
|
|
687
723
|
return position;
|
|
688
724
|
}
|
|
725
|
+
// Parses code generated by FormatEvalOrigin(), a function inside V8:
|
|
726
|
+
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js
|
|
689
727
|
function mapEvalOrigin(origin) {
|
|
728
|
+
// Most eval() calls are in this format
|
|
690
729
|
let match = /^eval at ([^(]+) \((.+):(\d+):(\d+)\)$/.exec(origin);
|
|
691
730
|
if (match) {
|
|
692
731
|
const position = mapSourcePosition({
|
|
@@ -697,10 +736,18 @@ function mapEvalOrigin(origin) {
|
|
|
697
736
|
});
|
|
698
737
|
return `eval at ${match[1]} (${position.source}:${position.line}:${position.column + 1})`;
|
|
699
738
|
}
|
|
739
|
+
// Parse nested eval() calls using recursion
|
|
700
740
|
match = /^eval at ([^(]+) \((.+)\)$/.exec(origin);
|
|
701
741
|
if (match) return `eval at ${match[1]} (${mapEvalOrigin(match[2])})`;
|
|
742
|
+
// Make sure we still return useful information if we didn't find anything
|
|
702
743
|
return origin;
|
|
703
744
|
}
|
|
745
|
+
// This is copied almost verbatim from the V8 source code at
|
|
746
|
+
// https://code.google.com/p/v8/source/browse/trunk/src/messages.js. The
|
|
747
|
+
// implementation of wrapCallSite() used to just forward to the actual source
|
|
748
|
+
// code of CallSite.prototype.toString but unfortunately a new release of V8
|
|
749
|
+
// did something to the prototype chain and broke the shim. The only fix I
|
|
750
|
+
// could find was copy/paste.
|
|
704
751
|
function CallSiteToString() {
|
|
705
752
|
let fileName;
|
|
706
753
|
let fileLocation = "";
|
|
@@ -712,7 +759,11 @@ function CallSiteToString() {
|
|
|
712
759
|
fileLocation += ", ";
|
|
713
760
|
}
|
|
714
761
|
if (fileName) fileLocation += fileName;
|
|
715
|
-
else
|
|
762
|
+
else
|
|
763
|
+
// Source code does not originate from a file and is not native, but we
|
|
764
|
+
// can still get the source position inside the source string, e.g. in
|
|
765
|
+
// an eval string.
|
|
766
|
+
fileLocation += "<anonymous>";
|
|
716
767
|
const lineNumber = this.getLineNumber();
|
|
717
768
|
if (lineNumber != null) {
|
|
718
769
|
fileLocation += `:${lineNumber}`;
|
|
@@ -727,6 +778,7 @@ function CallSiteToString() {
|
|
|
727
778
|
const isMethodCall = !(this.isToplevel() || isConstructor);
|
|
728
779
|
if (isMethodCall) {
|
|
729
780
|
let typeName = this.getTypeName();
|
|
781
|
+
// Fixes shim to be backward compatible with Node v0 to v4
|
|
730
782
|
if (typeName === "[object Object]") typeName = "null";
|
|
731
783
|
const methodName = this.getMethodName();
|
|
732
784
|
if (functionName) {
|
|
@@ -747,7 +799,9 @@ function cloneCallSite(frame) {
|
|
|
747
799
|
const object = {};
|
|
748
800
|
Object.getOwnPropertyNames(Object.getPrototypeOf(frame)).forEach((name) => {
|
|
749
801
|
const key = name;
|
|
802
|
+
// @ts-expect-error difficult to type
|
|
750
803
|
object[key] = /^(?:is|get)/.test(name) ? function() {
|
|
804
|
+
// eslint-disable-next-line no-useless-call
|
|
751
805
|
return frame[key].call(frame);
|
|
752
806
|
} : frame[key];
|
|
753
807
|
});
|
|
@@ -755,6 +809,7 @@ function cloneCallSite(frame) {
|
|
|
755
809
|
return object;
|
|
756
810
|
}
|
|
757
811
|
function wrapCallSite(frame, state) {
|
|
812
|
+
// provides interface backward compatibility
|
|
758
813
|
if (state === void 0) state = {
|
|
759
814
|
nextPosition: null,
|
|
760
815
|
curPosition: null
|
|
@@ -763,10 +818,18 @@ function wrapCallSite(frame, state) {
|
|
|
763
818
|
state.curPosition = null;
|
|
764
819
|
return frame;
|
|
765
820
|
}
|
|
821
|
+
// Most call sites will return the source file from getFileName(), but code
|
|
822
|
+
// passed to eval() ending in "//# sourceURL=..." will return the source file
|
|
823
|
+
// from getScriptNameOrSourceURL() instead
|
|
766
824
|
const source = frame.getFileName() || frame.getScriptNameOrSourceURL();
|
|
767
825
|
if (source) {
|
|
768
826
|
const line = frame.getLineNumber();
|
|
769
827
|
let column = frame.getColumnNumber() - 1;
|
|
828
|
+
// Fix position in Node where some (internal) code is prepended.
|
|
829
|
+
// See https://github.com/evanw/node-source-map-support/issues/36
|
|
830
|
+
// Header removed in node at ^10.16 || >=11.11.0
|
|
831
|
+
// v11 is not an LTS candidate, we can just test the one version with it.
|
|
832
|
+
// Test node versions for: 10.16-19, 10.20+, 12-19, 20-99, 100+, or 11.11
|
|
770
833
|
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
834
|
const headerLength = noHeader.test(globalProcessVersion()) ? 0 : 62;
|
|
772
835
|
if (line === 1 && column > headerLength && !frame.isEval()) column -= headerLength;
|
|
@@ -784,7 +847,7 @@ function wrapCallSite(frame, state) {
|
|
|
784
847
|
return state.nextPosition.name || originalFunctionName();
|
|
785
848
|
};
|
|
786
849
|
frame.getFileName = function() {
|
|
787
|
-
return position.source ??
|
|
850
|
+
return position.source ?? null;
|
|
788
851
|
};
|
|
789
852
|
frame.getLineNumber = function() {
|
|
790
853
|
return position.line;
|
|
@@ -797,6 +860,7 @@ function wrapCallSite(frame, state) {
|
|
|
797
860
|
};
|
|
798
861
|
return frame;
|
|
799
862
|
}
|
|
863
|
+
// Code called using eval() needs special handling
|
|
800
864
|
let origin = frame.isEval() && frame.getEvalOrigin();
|
|
801
865
|
if (origin) {
|
|
802
866
|
origin = mapEvalOrigin(origin);
|
|
@@ -806,8 +870,11 @@ function wrapCallSite(frame, state) {
|
|
|
806
870
|
};
|
|
807
871
|
return frame;
|
|
808
872
|
}
|
|
873
|
+
// If we get here then we were unable to change the source position
|
|
809
874
|
return frame;
|
|
810
875
|
}
|
|
876
|
+
// This function is part of the V8 stack trace API, for more info see:
|
|
877
|
+
// https://v8.dev/docs/stack-trace-api
|
|
811
878
|
function prepareStackTrace(error, stack) {
|
|
812
879
|
const name = error.name || "Error";
|
|
813
880
|
const message = error.message || "";
|
|
@@ -828,14 +895,19 @@ retrieveFileHandlers.slice(0);
|
|
|
828
895
|
retrieveMapHandlers.slice(0);
|
|
829
896
|
function install(options) {
|
|
830
897
|
options = options || {};
|
|
898
|
+
// Allow sources to be found by methods other than reading the files
|
|
899
|
+
// directly from disk.
|
|
831
900
|
if (options.retrieveFile) {
|
|
832
901
|
if (options.overrideRetrieveFile) retrieveFileHandlers.length = 0;
|
|
833
902
|
retrieveFileHandlers.unshift(options.retrieveFile);
|
|
834
903
|
}
|
|
904
|
+
// Allow source maps to be found by methods other than reading the files
|
|
905
|
+
// directly from disk.
|
|
835
906
|
if (options.retrieveSourceMap) {
|
|
836
907
|
if (options.overrideRetrieveSourceMap) retrieveMapHandlers.length = 0;
|
|
837
908
|
retrieveMapHandlers.unshift(options.retrieveSourceMap);
|
|
838
909
|
}
|
|
910
|
+
// Install the error reformatter
|
|
839
911
|
if (!errorFormatterInstalled) {
|
|
840
912
|
errorFormatterInstalled = true;
|
|
841
913
|
Error.prepareStackTrace = prepareStackTrace;
|
|
@@ -846,7 +918,6 @@ let SOURCEMAPPING_URL = "sourceMa";
|
|
|
846
918
|
SOURCEMAPPING_URL += "ppingURL";
|
|
847
919
|
const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
|
|
848
920
|
const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
|
|
849
|
-
const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
|
|
850
921
|
function withInlineSourcemap(result, options) {
|
|
851
922
|
const map = result.map;
|
|
852
923
|
let code = result.code;
|
|
@@ -855,6 +926,10 @@ function withInlineSourcemap(result, options) {
|
|
|
855
926
|
var _map$sources;
|
|
856
927
|
map.sources = (_map$sources = map.sources) === null || _map$sources === void 0 ? void 0 : _map$sources.map((source) => {
|
|
857
928
|
if (!source) return source;
|
|
929
|
+
// sometimes files here are absolute,
|
|
930
|
+
// but they are considered absolute to the server url, not the file system
|
|
931
|
+
// this is a bug in Vite
|
|
932
|
+
// all files should be either absolute to the file system or relative to the source map file
|
|
858
933
|
if (isAbsolute(source)) {
|
|
859
934
|
const actualPath = !source.startsWith(withTrailingSlash(options.root)) && source.startsWith("/") ? resolve$2(options.root, source.slice(1)) : source;
|
|
860
935
|
return relative(dirname(options.filepath), actualPath);
|
|
@@ -862,17 +937,25 @@ function withInlineSourcemap(result, options) {
|
|
|
862
937
|
return source;
|
|
863
938
|
});
|
|
864
939
|
}
|
|
940
|
+
// to reduce the payload size, we only inline vite node source map, because it's also the only one we use
|
|
865
941
|
const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
|
|
866
942
|
while (OTHER_SOURCE_MAP_REGEXP.test(code)) code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
|
|
943
|
+
// If the first line is not present on source maps, add simple 1:1 mapping ([0,0,0,0], [1,0,0,0])
|
|
944
|
+
// so that debuggers can be set to break on first line
|
|
945
|
+
// Since Vite 6, import statements at the top of the file are preserved correctly,
|
|
946
|
+
// so we don't need to add this mapping anymore.
|
|
867
947
|
if (!options.noFirstLineMapping && map.mappings.startsWith(";")) map.mappings = `AAAA,CAAA${map.mappings}`;
|
|
868
948
|
const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
|
|
869
949
|
result.code = `${code.trimEnd()}\n\n${VITE_NODE_SOURCEMAPPING_SOURCE}\n//# ${VITE_NODE_SOURCEMAPPING_URL};base64,${sourceMap}\n`;
|
|
870
950
|
return result;
|
|
871
951
|
}
|
|
872
952
|
function extractSourceMap(code) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
953
|
+
const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
|
|
954
|
+
let lastMatch, match;
|
|
955
|
+
// eslint-disable-next-line no-cond-assign
|
|
956
|
+
while (match = regexp.exec(code)) lastMatch = match;
|
|
957
|
+
// pick only the last source map keeping user strings that look like maps
|
|
958
|
+
if (lastMatch) return JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8"));
|
|
876
959
|
return null;
|
|
877
960
|
}
|
|
878
961
|
function installSourcemapsSupport(options) {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
|
|
2
|
-
export { A as Arrayable,
|
|
2
|
+
export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-DGmxD2U7.js';
|
package/dist/utils.cjs
CHANGED
|
@@ -20,8 +20,12 @@ function isBareImport(id) {
|
|
|
20
20
|
const VALID_ID_PREFIX = "/@id/";
|
|
21
21
|
function normalizeRequestId(id, base) {
|
|
22
22
|
if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
|
|
23
|
+
// keep drive the same as in process cwd. ideally, this should be resolved on Vite side
|
|
24
|
+
// Vite always resolves drive letters to the upper case because of the use of `realpathSync`
|
|
25
|
+
// https://github.com/vitejs/vite/blob/0ab20a3ee26eacf302415b3087732497d0a2f358/packages/vite/src/node/utils.ts#L635
|
|
23
26
|
if (driveRegexp && !(driveRegexp === null || driveRegexp === void 0 ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext === null || driveOppositeRegext === void 0 ? void 0 : driveOppositeRegext.test(id))) id = id.replace(driveOppositeRegext, `${drive}$1`);
|
|
24
27
|
if (id.startsWith("file://")) {
|
|
28
|
+
// preserve hash/query
|
|
25
29
|
const { file, postfix } = splitFileAndPostfix(id);
|
|
26
30
|
return node_url.fileURLToPath(file) + postfix;
|
|
27
31
|
}
|
|
@@ -43,6 +47,7 @@ const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`
|
|
|
43
47
|
function isInternalRequest(id) {
|
|
44
48
|
return internalRequestRegexp.test(id);
|
|
45
49
|
}
|
|
50
|
+
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
|
|
46
51
|
const prefixedBuiltins = new Set([
|
|
47
52
|
"node:sea",
|
|
48
53
|
"node:sqlite",
|
|
@@ -66,6 +71,7 @@ const builtins = new Set([
|
|
|
66
71
|
"wasi"
|
|
67
72
|
]);
|
|
68
73
|
function normalizeModuleId(id) {
|
|
74
|
+
// unique id that is not available as "test"
|
|
69
75
|
if (prefixedBuiltins.has(id)) return id;
|
|
70
76
|
if (id.startsWith("file://")) return node_url.fileURLToPath(id);
|
|
71
77
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
@@ -79,6 +85,7 @@ function toFilePath(id, root) {
|
|
|
79
85
|
absolute: id.slice(4),
|
|
80
86
|
exists: true
|
|
81
87
|
};
|
|
88
|
+
// check if /src/module.js -> <root>/src/module.js
|
|
82
89
|
if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
|
|
83
90
|
const resolved = pathe.resolve(root, id.slice(1));
|
|
84
91
|
if (fs.existsSync(cleanUrl(resolved))) return {
|
|
@@ -95,6 +102,7 @@ function toFilePath(id, root) {
|
|
|
95
102
|
};
|
|
96
103
|
})();
|
|
97
104
|
if (absolute.startsWith("//")) absolute = absolute.slice(1);
|
|
105
|
+
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
|
|
98
106
|
return {
|
|
99
107
|
path: isWindows && absolute.startsWith("/") ? slash(node_url.fileURLToPath(node_url.pathToFileURL(absolute.slice(1)).href)) : absolute,
|
|
100
108
|
exists
|
|
@@ -149,6 +157,7 @@ function withTrailingSlash(path) {
|
|
|
149
157
|
return path;
|
|
150
158
|
}
|
|
151
159
|
function createImportMetaEnvProxy() {
|
|
160
|
+
// packages/vitest/src/node/plugins/index.ts:146
|
|
152
161
|
const booleanKeys = [
|
|
153
162
|
"DEV",
|
|
154
163
|
"PROD",
|
|
@@ -168,7 +177,7 @@ function createImportMetaEnvProxy() {
|
|
|
168
177
|
}
|
|
169
178
|
});
|
|
170
179
|
}
|
|
171
|
-
const packageCache = new Map();
|
|
180
|
+
const packageCache = /* @__PURE__ */ new Map();
|
|
172
181
|
async function findNearestPackageData(basedir) {
|
|
173
182
|
const originalBasedir = basedir;
|
|
174
183
|
while (basedir) {
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.mjs
CHANGED
|
@@ -18,8 +18,12 @@ function isBareImport(id) {
|
|
|
18
18
|
const VALID_ID_PREFIX = "/@id/";
|
|
19
19
|
function normalizeRequestId(id, base) {
|
|
20
20
|
if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
|
|
21
|
+
// keep drive the same as in process cwd. ideally, this should be resolved on Vite side
|
|
22
|
+
// Vite always resolves drive letters to the upper case because of the use of `realpathSync`
|
|
23
|
+
// https://github.com/vitejs/vite/blob/0ab20a3ee26eacf302415b3087732497d0a2f358/packages/vite/src/node/utils.ts#L635
|
|
21
24
|
if (driveRegexp && !(driveRegexp === null || driveRegexp === void 0 ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext === null || driveOppositeRegext === void 0 ? void 0 : driveOppositeRegext.test(id))) id = id.replace(driveOppositeRegext, `${drive}$1`);
|
|
22
25
|
if (id.startsWith("file://")) {
|
|
26
|
+
// preserve hash/query
|
|
23
27
|
const { file, postfix } = splitFileAndPostfix(id);
|
|
24
28
|
return fileURLToPath(file) + postfix;
|
|
25
29
|
}
|
|
@@ -41,6 +45,7 @@ const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`
|
|
|
41
45
|
function isInternalRequest(id) {
|
|
42
46
|
return internalRequestRegexp.test(id);
|
|
43
47
|
}
|
|
48
|
+
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
|
|
44
49
|
const prefixedBuiltins = new Set([
|
|
45
50
|
"node:sea",
|
|
46
51
|
"node:sqlite",
|
|
@@ -64,6 +69,7 @@ const builtins = new Set([
|
|
|
64
69
|
"wasi"
|
|
65
70
|
]);
|
|
66
71
|
function normalizeModuleId(id) {
|
|
72
|
+
// unique id that is not available as "test"
|
|
67
73
|
if (prefixedBuiltins.has(id)) return id;
|
|
68
74
|
if (id.startsWith("file://")) return fileURLToPath(id);
|
|
69
75
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
@@ -77,6 +83,7 @@ function toFilePath(id, root) {
|
|
|
77
83
|
absolute: id.slice(4),
|
|
78
84
|
exists: true
|
|
79
85
|
};
|
|
86
|
+
// check if /src/module.js -> <root>/src/module.js
|
|
80
87
|
if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
|
|
81
88
|
const resolved = resolve(root, id.slice(1));
|
|
82
89
|
if (existsSync(cleanUrl(resolved))) return {
|
|
@@ -93,6 +100,7 @@ function toFilePath(id, root) {
|
|
|
93
100
|
};
|
|
94
101
|
})();
|
|
95
102
|
if (absolute.startsWith("//")) absolute = absolute.slice(1);
|
|
103
|
+
// disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
|
|
96
104
|
return {
|
|
97
105
|
path: isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute,
|
|
98
106
|
exists
|
|
@@ -147,6 +155,7 @@ function withTrailingSlash(path) {
|
|
|
147
155
|
return path;
|
|
148
156
|
}
|
|
149
157
|
function createImportMetaEnvProxy() {
|
|
158
|
+
// packages/vitest/src/node/plugins/index.ts:146
|
|
150
159
|
const booleanKeys = [
|
|
151
160
|
"DEV",
|
|
152
161
|
"PROD",
|
|
@@ -166,7 +175,7 @@ function createImportMetaEnvProxy() {
|
|
|
166
175
|
}
|
|
167
176
|
});
|
|
168
177
|
}
|
|
169
|
-
const packageCache = new Map();
|
|
178
|
+
const packageCache = /* @__PURE__ */ new Map();
|
|
170
179
|
async function findNearestPackageData(basedir) {
|
|
171
180
|
const originalBasedir = basedir;
|
|
172
181
|
while (basedir) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.2.0
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"description": "Vite as Node.js runtime",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -78,10 +78,10 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"cac": "^6.7.14",
|
|
81
|
-
"debug": "^4.4.
|
|
81
|
+
"debug": "^4.4.1",
|
|
82
82
|
"es-module-lexer": "^1.7.0",
|
|
83
83
|
"pathe": "^2.0.3",
|
|
84
|
-
"vite": "^5.0.0 || ^6.0.0"
|
|
84
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@jridgewell/trace-mapping": "^0.3.25",
|