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/utils.mjs
CHANGED
|
@@ -6,195 +6,180 @@ import { resolve, join, dirname } from 'pathe';
|
|
|
6
6
|
const isWindows = process.platform === "win32";
|
|
7
7
|
const drive = isWindows ? process.cwd()[0] : null;
|
|
8
8
|
const driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null;
|
|
9
|
-
const driveRegexp = drive ? new RegExp(`(?:^|/@fs/)${drive}(
|
|
10
|
-
const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposite}(
|
|
9
|
+
const driveRegexp = drive ? new RegExp(`(?:^|/@fs/)${drive}(\:[\\/])`) : null;
|
|
10
|
+
const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposite}(\:[\\/])`) : null;
|
|
11
11
|
function slash(str) {
|
|
12
|
-
|
|
12
|
+
return str.replace(/\\/g, "/");
|
|
13
13
|
}
|
|
14
14
|
const VALID_ID_PREFIX = "/@id/";
|
|
15
15
|
function normalizeRequestId(id, base) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const { file, postfix } = splitFileAndPostfix(id);
|
|
24
|
-
return fileURLToPath(file) + postfix;
|
|
25
|
-
}
|
|
26
|
-
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
16
|
+
if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
|
|
17
|
+
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`);
|
|
18
|
+
if (id.startsWith("file://")) {
|
|
19
|
+
const { file, postfix } = splitFileAndPostfix(id);
|
|
20
|
+
return fileURLToPath(file) + postfix;
|
|
21
|
+
}
|
|
22
|
+
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
27
23
|
}
|
|
28
24
|
const postfixRE = /[?#].*$/;
|
|
29
25
|
function cleanUrl(url) {
|
|
30
|
-
|
|
26
|
+
return url.replace(postfixRE, "");
|
|
31
27
|
}
|
|
32
28
|
function splitFileAndPostfix(path) {
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const file = cleanUrl(path);
|
|
30
|
+
return {
|
|
31
|
+
file,
|
|
32
|
+
postfix: path.slice(file.length)
|
|
33
|
+
};
|
|
35
34
|
}
|
|
36
35
|
const internalRequests = ["@vite/client", "@vite/env"];
|
|
37
|
-
const internalRequestRegexp = new RegExp(
|
|
38
|
-
`^/?(?:${internalRequests.join("|")})$`
|
|
39
|
-
);
|
|
36
|
+
const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`);
|
|
40
37
|
function isInternalRequest(id) {
|
|
41
|
-
|
|
38
|
+
return internalRequestRegexp.test(id);
|
|
42
39
|
}
|
|
43
|
-
const prefixedBuiltins =
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
const prefixedBuiltins = new Set([
|
|
41
|
+
"node:sea",
|
|
42
|
+
"node:sqlite",
|
|
43
|
+
"node:test",
|
|
44
|
+
"node:test/reporters"
|
|
48
45
|
]);
|
|
49
|
-
const builtins =
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
46
|
+
const builtins = new Set([
|
|
47
|
+
...builtinModules,
|
|
48
|
+
"assert/strict",
|
|
49
|
+
"diagnostics_channel",
|
|
50
|
+
"dns/promises",
|
|
51
|
+
"fs/promises",
|
|
52
|
+
"path/posix",
|
|
53
|
+
"path/win32",
|
|
54
|
+
"readline/promises",
|
|
55
|
+
"stream/consumers",
|
|
56
|
+
"stream/promises",
|
|
57
|
+
"stream/web",
|
|
58
|
+
"timers/promises",
|
|
59
|
+
"util/types",
|
|
60
|
+
"wasi"
|
|
64
61
|
]);
|
|
65
62
|
function normalizeModuleId(id) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (id.startsWith("file://")) {
|
|
70
|
-
return fileURLToPath(id);
|
|
71
|
-
}
|
|
72
|
-
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
63
|
+
if (prefixedBuiltins.has(id)) return id;
|
|
64
|
+
if (id.startsWith("file://")) return fileURLToPath(id);
|
|
65
|
+
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
73
66
|
}
|
|
74
67
|
function isPrimitive(v) {
|
|
75
|
-
|
|
68
|
+
return v !== Object(v);
|
|
76
69
|
}
|
|
77
70
|
function toFilePath(id, root) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
71
|
+
let { absolute, exists } = (() => {
|
|
72
|
+
if (id.startsWith("/@fs/")) return {
|
|
73
|
+
absolute: id.slice(4),
|
|
74
|
+
exists: true
|
|
75
|
+
};
|
|
76
|
+
if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
|
|
77
|
+
const resolved = resolve(root, id.slice(1));
|
|
78
|
+
if (existsSync(cleanUrl(resolved))) return {
|
|
79
|
+
absolute: resolved,
|
|
80
|
+
exists: true
|
|
81
|
+
};
|
|
82
|
+
} else if (id.startsWith(withTrailingSlash(root)) && existsSync(cleanUrl(id))) return {
|
|
83
|
+
absolute: id,
|
|
84
|
+
exists: true
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
absolute: id,
|
|
88
|
+
exists: false
|
|
89
|
+
};
|
|
90
|
+
})();
|
|
91
|
+
if (absolute.startsWith("//")) absolute = absolute.slice(1);
|
|
92
|
+
return {
|
|
93
|
+
path: isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute,
|
|
94
|
+
exists
|
|
95
|
+
};
|
|
99
96
|
}
|
|
100
97
|
const NODE_BUILTIN_NAMESPACE = "node:";
|
|
101
98
|
function isNodeBuiltin(id) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
99
|
+
if (prefixedBuiltins.has(id)) return true;
|
|
100
|
+
return builtins.has(id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Convert `Arrayable<T>` to `Array<T>`
|
|
104
|
+
*
|
|
105
|
+
* @category Array
|
|
106
|
+
*/
|
|
109
107
|
function toArray(array) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (Array.isArray(array)) {
|
|
114
|
-
return array;
|
|
115
|
-
}
|
|
116
|
-
return [array];
|
|
108
|
+
if (array === null || array === void 0) array = [];
|
|
109
|
+
if (Array.isArray(array)) return array;
|
|
110
|
+
return [array];
|
|
117
111
|
}
|
|
118
112
|
function getCachedData(cache, basedir, originalBasedir) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
const pkgData = cache.get(getFnpdCacheKey(basedir));
|
|
114
|
+
if (pkgData) {
|
|
115
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
116
|
+
cache.set(getFnpdCacheKey(dir), pkgData);
|
|
117
|
+
});
|
|
118
|
+
return pkgData;
|
|
119
|
+
}
|
|
126
120
|
}
|
|
127
121
|
function setCacheData(cache, data, basedir, originalBasedir) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
cache.set(getFnpdCacheKey(basedir), data);
|
|
123
|
+
traverseBetweenDirs(originalBasedir, basedir, (dir) => {
|
|
124
|
+
cache.set(getFnpdCacheKey(dir), data);
|
|
125
|
+
});
|
|
132
126
|
}
|
|
133
127
|
function getFnpdCacheKey(basedir) {
|
|
134
|
-
|
|
128
|
+
return `fnpd_${basedir}`;
|
|
135
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Traverse between `longerDir` (inclusive) and `shorterDir` (exclusive) and call `cb` for each dir.
|
|
132
|
+
* @param longerDir Longer dir path, e.g. `/User/foo/bar/baz`
|
|
133
|
+
* @param shorterDir Shorter dir path, e.g. `/User/foo`
|
|
134
|
+
*/
|
|
136
135
|
function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
while (longerDir !== shorterDir) {
|
|
137
|
+
cb(longerDir);
|
|
138
|
+
longerDir = dirname(longerDir);
|
|
139
|
+
}
|
|
141
140
|
}
|
|
142
141
|
function withTrailingSlash(path) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
return path;
|
|
142
|
+
if (path[path.length - 1] !== "/") return `${path}/`;
|
|
143
|
+
return path;
|
|
147
144
|
}
|
|
148
145
|
function createImportMetaEnvProxy() {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
const packageCache = /* @__PURE__ */ new Map();
|
|
146
|
+
const booleanKeys = [
|
|
147
|
+
"DEV",
|
|
148
|
+
"PROD",
|
|
149
|
+
"SSR"
|
|
150
|
+
];
|
|
151
|
+
return new Proxy(process.env, {
|
|
152
|
+
get(_, key) {
|
|
153
|
+
if (typeof key !== "string") return void 0;
|
|
154
|
+
if (booleanKeys.includes(key)) return !!process.env[key];
|
|
155
|
+
return process.env[key];
|
|
156
|
+
},
|
|
157
|
+
set(_, key, value) {
|
|
158
|
+
if (typeof key !== "string") return true;
|
|
159
|
+
if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";
|
|
160
|
+
else process.env[key] = value;
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const packageCache = new Map();
|
|
174
166
|
async function findNearestPackageData(basedir) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const nextBasedir = dirname(basedir);
|
|
192
|
-
if (nextBasedir === basedir) {
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
basedir = nextBasedir;
|
|
196
|
-
}
|
|
197
|
-
return {};
|
|
167
|
+
const originalBasedir = basedir;
|
|
168
|
+
while (basedir) {
|
|
169
|
+
var _await$fsp$stat$catch;
|
|
170
|
+
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
171
|
+
if (cached) return cached;
|
|
172
|
+
const pkgPath = join(basedir, "package.json");
|
|
173
|
+
if ((_await$fsp$stat$catch = await promises.stat(pkgPath).catch(() => {})) === null || _await$fsp$stat$catch === void 0 ? void 0 : _await$fsp$stat$catch.isFile()) {
|
|
174
|
+
const pkgData = JSON.parse(await promises.readFile(pkgPath, "utf8"));
|
|
175
|
+
if (packageCache) setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
176
|
+
return pkgData;
|
|
177
|
+
}
|
|
178
|
+
const nextBasedir = dirname(basedir);
|
|
179
|
+
if (nextBasedir === basedir) break;
|
|
180
|
+
basedir = nextBasedir;
|
|
181
|
+
}
|
|
182
|
+
return {};
|
|
198
183
|
}
|
|
199
184
|
|
|
200
185
|
export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
|