vite-node 2.0.0-beta.9 → 2.0.1
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/README.md +5 -2
- package/dist/chunk-hmr.cjs +35 -18
- package/dist/chunk-hmr.mjs +35 -18
- package/dist/cli.cjs +23 -11
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +24 -12
- package/dist/client.cjs +78 -35
- package/dist/client.d.ts +1 -1
- package/dist/client.mjs +78 -35
- package/dist/constants.cjs +4 -1
- package/dist/constants.mjs +4 -1
- package/dist/hmr.d.ts +1 -1
- package/dist/{index-D1EszD4V.d.ts → index-CCsqCcr7.d.ts} +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/server.cjs +186 -104
- package/dist/server.d.ts +1 -7
- package/dist/server.mjs +189 -107
- package/dist/source-map.cjs +66 -31
- package/dist/source-map.mjs +66 -31
- package/dist/types.d.ts +1 -1
- package/dist/utils.cjs +41 -31
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +41 -31
- package/package.json +3 -3
package/dist/utils.cjs
CHANGED
|
@@ -15,27 +15,26 @@ function slash(str) {
|
|
|
15
15
|
}
|
|
16
16
|
const VALID_ID_PREFIX = "/@id/";
|
|
17
17
|
function normalizeRequestId(id, base) {
|
|
18
|
-
if (base && id.startsWith(withTrailingSlash(base)))
|
|
18
|
+
if (base && id.startsWith(withTrailingSlash(base))) {
|
|
19
19
|
id = `/${id.slice(base.length)}`;
|
|
20
|
-
|
|
20
|
+
}
|
|
21
|
+
if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id))) {
|
|
21
22
|
id = id.replace(driveOppositeRegext, `${drive}$1`);
|
|
23
|
+
}
|
|
22
24
|
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
23
25
|
}
|
|
24
26
|
const postfixRE = /[?#].*$/;
|
|
25
27
|
function cleanUrl(url) {
|
|
26
28
|
return url.replace(postfixRE, "");
|
|
27
29
|
}
|
|
28
|
-
const internalRequests = [
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`);
|
|
30
|
+
const internalRequests = ["@vite/client", "@vite/env"];
|
|
31
|
+
const internalRequestRegexp = new RegExp(
|
|
32
|
+
`^/?(?:${internalRequests.join("|")})$`
|
|
33
|
+
);
|
|
33
34
|
function isInternalRequest(id) {
|
|
34
35
|
return internalRequestRegexp.test(id);
|
|
35
36
|
}
|
|
36
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set([
|
|
37
|
-
"node:test"
|
|
38
|
-
]);
|
|
37
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
|
39
38
|
const builtins = /* @__PURE__ */ new Set([
|
|
40
39
|
...node_module.builtinModules,
|
|
41
40
|
"assert/strict",
|
|
@@ -53,8 +52,9 @@ const builtins = /* @__PURE__ */ new Set([
|
|
|
53
52
|
"wasi"
|
|
54
53
|
]);
|
|
55
54
|
function normalizeModuleId(id) {
|
|
56
|
-
if (prefixedBuiltins.has(id))
|
|
55
|
+
if (prefixedBuiltins.has(id)) {
|
|
57
56
|
return id;
|
|
57
|
+
}
|
|
58
58
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
59
59
|
}
|
|
60
60
|
function isPrimitive(v) {
|
|
@@ -62,19 +62,22 @@ function isPrimitive(v) {
|
|
|
62
62
|
}
|
|
63
63
|
function toFilePath(id, root) {
|
|
64
64
|
let { absolute, exists } = (() => {
|
|
65
|
-
if (id.startsWith("/@fs/"))
|
|
65
|
+
if (id.startsWith("/@fs/")) {
|
|
66
66
|
return { absolute: id.slice(4), exists: true };
|
|
67
|
+
}
|
|
67
68
|
if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
|
|
68
69
|
const resolved = pathe.resolve(root, id.slice(1));
|
|
69
|
-
if (fs.existsSync(cleanUrl(resolved)))
|
|
70
|
+
if (fs.existsSync(cleanUrl(resolved))) {
|
|
70
71
|
return { absolute: resolved, exists: true };
|
|
72
|
+
}
|
|
71
73
|
} else if (id.startsWith(withTrailingSlash(root)) && fs.existsSync(cleanUrl(id))) {
|
|
72
74
|
return { absolute: id, exists: true };
|
|
73
75
|
}
|
|
74
76
|
return { absolute: id, exists: false };
|
|
75
77
|
})();
|
|
76
|
-
if (absolute.startsWith("//"))
|
|
78
|
+
if (absolute.startsWith("//")) {
|
|
77
79
|
absolute = absolute.slice(1);
|
|
80
|
+
}
|
|
78
81
|
return {
|
|
79
82
|
path: isWindows && absolute.startsWith("/") ? slash(node_url.fileURLToPath(node_url.pathToFileURL(absolute.slice(1)).href)) : absolute,
|
|
80
83
|
exists
|
|
@@ -82,17 +85,20 @@ function toFilePath(id, root) {
|
|
|
82
85
|
}
|
|
83
86
|
const NODE_BUILTIN_NAMESPACE = "node:";
|
|
84
87
|
function isNodeBuiltin(id) {
|
|
85
|
-
if (prefixedBuiltins.has(id))
|
|
88
|
+
if (prefixedBuiltins.has(id)) {
|
|
86
89
|
return true;
|
|
90
|
+
}
|
|
87
91
|
return builtins.has(
|
|
88
92
|
id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id
|
|
89
93
|
);
|
|
90
94
|
}
|
|
91
95
|
function toArray(array) {
|
|
92
|
-
if (array === null || array === void 0)
|
|
96
|
+
if (array === null || array === void 0) {
|
|
93
97
|
array = [];
|
|
94
|
-
|
|
98
|
+
}
|
|
99
|
+
if (Array.isArray(array)) {
|
|
95
100
|
return array;
|
|
101
|
+
}
|
|
96
102
|
return [array];
|
|
97
103
|
}
|
|
98
104
|
function getCachedData(cache, basedir, originalBasedir) {
|
|
@@ -120,31 +126,32 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
|
120
126
|
}
|
|
121
127
|
}
|
|
122
128
|
function withTrailingSlash(path) {
|
|
123
|
-
if (path[path.length - 1] !== "/")
|
|
129
|
+
if (path[path.length - 1] !== "/") {
|
|
124
130
|
return `${path}/`;
|
|
131
|
+
}
|
|
125
132
|
return path;
|
|
126
133
|
}
|
|
127
134
|
function createImportMetaEnvProxy() {
|
|
128
|
-
const booleanKeys = [
|
|
129
|
-
"DEV",
|
|
130
|
-
"PROD",
|
|
131
|
-
"SSR"
|
|
132
|
-
];
|
|
135
|
+
const booleanKeys = ["DEV", "PROD", "SSR"];
|
|
133
136
|
return new Proxy(process.env, {
|
|
134
137
|
get(_, key) {
|
|
135
|
-
if (typeof key !== "string")
|
|
138
|
+
if (typeof key !== "string") {
|
|
136
139
|
return void 0;
|
|
137
|
-
|
|
140
|
+
}
|
|
141
|
+
if (booleanKeys.includes(key)) {
|
|
138
142
|
return !!process.env[key];
|
|
143
|
+
}
|
|
139
144
|
return process.env[key];
|
|
140
145
|
},
|
|
141
146
|
set(_, key, value) {
|
|
142
|
-
if (typeof key !== "string")
|
|
147
|
+
if (typeof key !== "string") {
|
|
143
148
|
return true;
|
|
144
|
-
|
|
149
|
+
}
|
|
150
|
+
if (booleanKeys.includes(key)) {
|
|
145
151
|
process.env[key] = value ? "1" : "";
|
|
146
|
-
else
|
|
152
|
+
} else {
|
|
147
153
|
process.env[key] = value;
|
|
154
|
+
}
|
|
148
155
|
return true;
|
|
149
156
|
}
|
|
150
157
|
});
|
|
@@ -155,19 +162,22 @@ async function findNearestPackageData(basedir) {
|
|
|
155
162
|
const originalBasedir = basedir;
|
|
156
163
|
while (basedir) {
|
|
157
164
|
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
158
|
-
if (cached)
|
|
165
|
+
if (cached) {
|
|
159
166
|
return cached;
|
|
167
|
+
}
|
|
160
168
|
const pkgPath = pathe.join(basedir, "package.json");
|
|
161
169
|
if ((_a = await fs.promises.stat(pkgPath).catch(() => {
|
|
162
170
|
})) == null ? void 0 : _a.isFile()) {
|
|
163
171
|
const pkgData = JSON.parse(await fs.promises.readFile(pkgPath, "utf8"));
|
|
164
|
-
if (packageCache)
|
|
172
|
+
if (packageCache) {
|
|
165
173
|
setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
174
|
+
}
|
|
166
175
|
return pkgData;
|
|
167
176
|
}
|
|
168
177
|
const nextBasedir = pathe.dirname(basedir);
|
|
169
|
-
if (nextBasedir === basedir)
|
|
178
|
+
if (nextBasedir === basedir) {
|
|
170
179
|
break;
|
|
180
|
+
}
|
|
171
181
|
basedir = nextBasedir;
|
|
172
182
|
}
|
|
173
183
|
return {};
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.mjs
CHANGED
|
@@ -13,27 +13,26 @@ function slash(str) {
|
|
|
13
13
|
}
|
|
14
14
|
const VALID_ID_PREFIX = "/@id/";
|
|
15
15
|
function normalizeRequestId(id, base) {
|
|
16
|
-
if (base && id.startsWith(withTrailingSlash(base)))
|
|
16
|
+
if (base && id.startsWith(withTrailingSlash(base))) {
|
|
17
17
|
id = `/${id.slice(base.length)}`;
|
|
18
|
-
|
|
18
|
+
}
|
|
19
|
+
if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id))) {
|
|
19
20
|
id = id.replace(driveOppositeRegext, `${drive}$1`);
|
|
21
|
+
}
|
|
20
22
|
return id.replace(/^\/@id\/__x00__/, "\0").replace(/^\/@id\//, "").replace(/^__vite-browser-external:/, "").replace(/^file:/, "").replace(/^\/+/, "/").replace(/\?v=\w+/, "?").replace(/&v=\w+/, "").replace(/\?t=\w+/, "?").replace(/&t=\w+/, "").replace(/\?import/, "?").replace(/&import/, "").replace(/\?&/, "?").replace(/\?+$/, "");
|
|
21
23
|
}
|
|
22
24
|
const postfixRE = /[?#].*$/;
|
|
23
25
|
function cleanUrl(url) {
|
|
24
26
|
return url.replace(postfixRE, "");
|
|
25
27
|
}
|
|
26
|
-
const internalRequests = [
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
const internalRequestRegexp = new RegExp(`^/?(?:${internalRequests.join("|")})$`);
|
|
28
|
+
const internalRequests = ["@vite/client", "@vite/env"];
|
|
29
|
+
const internalRequestRegexp = new RegExp(
|
|
30
|
+
`^/?(?:${internalRequests.join("|")})$`
|
|
31
|
+
);
|
|
31
32
|
function isInternalRequest(id) {
|
|
32
33
|
return internalRequestRegexp.test(id);
|
|
33
34
|
}
|
|
34
|
-
const prefixedBuiltins = /* @__PURE__ */ new Set([
|
|
35
|
-
"node:test"
|
|
36
|
-
]);
|
|
35
|
+
const prefixedBuiltins = /* @__PURE__ */ new Set(["node:test"]);
|
|
37
36
|
const builtins = /* @__PURE__ */ new Set([
|
|
38
37
|
...builtinModules,
|
|
39
38
|
"assert/strict",
|
|
@@ -51,8 +50,9 @@ const builtins = /* @__PURE__ */ new Set([
|
|
|
51
50
|
"wasi"
|
|
52
51
|
]);
|
|
53
52
|
function normalizeModuleId(id) {
|
|
54
|
-
if (prefixedBuiltins.has(id))
|
|
53
|
+
if (prefixedBuiltins.has(id)) {
|
|
55
54
|
return id;
|
|
55
|
+
}
|
|
56
56
|
return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
57
57
|
}
|
|
58
58
|
function isPrimitive(v) {
|
|
@@ -60,19 +60,22 @@ function isPrimitive(v) {
|
|
|
60
60
|
}
|
|
61
61
|
function toFilePath(id, root) {
|
|
62
62
|
let { absolute, exists } = (() => {
|
|
63
|
-
if (id.startsWith("/@fs/"))
|
|
63
|
+
if (id.startsWith("/@fs/")) {
|
|
64
64
|
return { absolute: id.slice(4), exists: true };
|
|
65
|
+
}
|
|
65
66
|
if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
|
|
66
67
|
const resolved = resolve(root, id.slice(1));
|
|
67
|
-
if (existsSync(cleanUrl(resolved)))
|
|
68
|
+
if (existsSync(cleanUrl(resolved))) {
|
|
68
69
|
return { absolute: resolved, exists: true };
|
|
70
|
+
}
|
|
69
71
|
} else if (id.startsWith(withTrailingSlash(root)) && existsSync(cleanUrl(id))) {
|
|
70
72
|
return { absolute: id, exists: true };
|
|
71
73
|
}
|
|
72
74
|
return { absolute: id, exists: false };
|
|
73
75
|
})();
|
|
74
|
-
if (absolute.startsWith("//"))
|
|
76
|
+
if (absolute.startsWith("//")) {
|
|
75
77
|
absolute = absolute.slice(1);
|
|
78
|
+
}
|
|
76
79
|
return {
|
|
77
80
|
path: isWindows && absolute.startsWith("/") ? slash(fileURLToPath(pathToFileURL(absolute.slice(1)).href)) : absolute,
|
|
78
81
|
exists
|
|
@@ -80,17 +83,20 @@ function toFilePath(id, root) {
|
|
|
80
83
|
}
|
|
81
84
|
const NODE_BUILTIN_NAMESPACE = "node:";
|
|
82
85
|
function isNodeBuiltin(id) {
|
|
83
|
-
if (prefixedBuiltins.has(id))
|
|
86
|
+
if (prefixedBuiltins.has(id)) {
|
|
84
87
|
return true;
|
|
88
|
+
}
|
|
85
89
|
return builtins.has(
|
|
86
90
|
id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id
|
|
87
91
|
);
|
|
88
92
|
}
|
|
89
93
|
function toArray(array) {
|
|
90
|
-
if (array === null || array === void 0)
|
|
94
|
+
if (array === null || array === void 0) {
|
|
91
95
|
array = [];
|
|
92
|
-
|
|
96
|
+
}
|
|
97
|
+
if (Array.isArray(array)) {
|
|
93
98
|
return array;
|
|
99
|
+
}
|
|
94
100
|
return [array];
|
|
95
101
|
}
|
|
96
102
|
function getCachedData(cache, basedir, originalBasedir) {
|
|
@@ -118,31 +124,32 @@ function traverseBetweenDirs(longerDir, shorterDir, cb) {
|
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
function withTrailingSlash(path) {
|
|
121
|
-
if (path[path.length - 1] !== "/")
|
|
127
|
+
if (path[path.length - 1] !== "/") {
|
|
122
128
|
return `${path}/`;
|
|
129
|
+
}
|
|
123
130
|
return path;
|
|
124
131
|
}
|
|
125
132
|
function createImportMetaEnvProxy() {
|
|
126
|
-
const booleanKeys = [
|
|
127
|
-
"DEV",
|
|
128
|
-
"PROD",
|
|
129
|
-
"SSR"
|
|
130
|
-
];
|
|
133
|
+
const booleanKeys = ["DEV", "PROD", "SSR"];
|
|
131
134
|
return new Proxy(process.env, {
|
|
132
135
|
get(_, key) {
|
|
133
|
-
if (typeof key !== "string")
|
|
136
|
+
if (typeof key !== "string") {
|
|
134
137
|
return void 0;
|
|
135
|
-
|
|
138
|
+
}
|
|
139
|
+
if (booleanKeys.includes(key)) {
|
|
136
140
|
return !!process.env[key];
|
|
141
|
+
}
|
|
137
142
|
return process.env[key];
|
|
138
143
|
},
|
|
139
144
|
set(_, key, value) {
|
|
140
|
-
if (typeof key !== "string")
|
|
145
|
+
if (typeof key !== "string") {
|
|
141
146
|
return true;
|
|
142
|
-
|
|
147
|
+
}
|
|
148
|
+
if (booleanKeys.includes(key)) {
|
|
143
149
|
process.env[key] = value ? "1" : "";
|
|
144
|
-
else
|
|
150
|
+
} else {
|
|
145
151
|
process.env[key] = value;
|
|
152
|
+
}
|
|
146
153
|
return true;
|
|
147
154
|
}
|
|
148
155
|
});
|
|
@@ -153,19 +160,22 @@ async function findNearestPackageData(basedir) {
|
|
|
153
160
|
const originalBasedir = basedir;
|
|
154
161
|
while (basedir) {
|
|
155
162
|
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
156
|
-
if (cached)
|
|
163
|
+
if (cached) {
|
|
157
164
|
return cached;
|
|
165
|
+
}
|
|
158
166
|
const pkgPath = join(basedir, "package.json");
|
|
159
167
|
if ((_a = await promises.stat(pkgPath).catch(() => {
|
|
160
168
|
})) == null ? void 0 : _a.isFile()) {
|
|
161
169
|
const pkgData = JSON.parse(await promises.readFile(pkgPath, "utf8"));
|
|
162
|
-
if (packageCache)
|
|
170
|
+
if (packageCache) {
|
|
163
171
|
setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
172
|
+
}
|
|
164
173
|
return pkgData;
|
|
165
174
|
}
|
|
166
175
|
const nextBasedir = dirname(basedir);
|
|
167
|
-
if (nextBasedir === basedir)
|
|
176
|
+
if (nextBasedir === basedir) {
|
|
168
177
|
break;
|
|
178
|
+
}
|
|
169
179
|
basedir = nextBasedir;
|
|
170
180
|
}
|
|
171
181
|
return {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "Vite as Node.js runtime",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -78,9 +78,9 @@
|
|
|
78
78
|
},
|
|
79
79
|
"dependencies": {
|
|
80
80
|
"cac": "^6.7.14",
|
|
81
|
-
"debug": "^4.3.
|
|
81
|
+
"debug": "^4.3.5",
|
|
82
82
|
"pathe": "^1.1.2",
|
|
83
|
-
"picocolors": "^1.0.
|
|
83
|
+
"picocolors": "^1.0.1",
|
|
84
84
|
"vite": "^5.0.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|