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