vite-node 4.0.0-beta.8 → 5.0.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/types.cjs DELETED
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-
package/dist/utils.cjs DELETED
@@ -1,196 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('node:fs');
4
- var node_module = require('node:module');
5
- var node_url = require('node:url');
6
- var pathe = require('pathe');
7
-
8
- const isWindows = process.platform === "win32";
9
- const drive = isWindows ? process.cwd()[0] : null, driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null, driveRegexp = drive ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${drive}(\:[\\/])`) : null, driveOppositeRegext = driveOpposite ? /* @__PURE__ */ new RegExp(`(?:^|/@fs/)${driveOpposite}(\:[\\/])`) : null;
10
- function slash(str) {
11
- return str.replace(/\\/g, "/");
12
- }
13
- const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
14
- function isBareImport(id) {
15
- return bareImportRE.test(id);
16
- }
17
- const VALID_ID_PREFIX = "/@id/";
18
- function normalizeRequestId(id, base) {
19
- if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
20
- // keep drive the same as in process cwd. ideally, this should be resolved on Vite side
21
- // Vite always resolves drive letters to the upper case because of the use of `realpathSync`
22
- // https://github.com/vitejs/vite/blob/0ab20a3ee26eacf302415b3087732497d0a2f358/packages/vite/src/node/utils.ts#L635
23
- 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
- if (id.startsWith("file://")) {
25
- // preserve hash/query
26
- const { file, postfix } = splitFileAndPostfix(id);
27
- return node_url.fileURLToPath(file) + postfix;
28
- }
29
- 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(/\?+$/, "");
30
- }
31
- const postfixRE = /[?#].*$/;
32
- function cleanUrl(url) {
33
- return url.replace(postfixRE, "");
34
- }
35
- function splitFileAndPostfix(path) {
36
- const file = cleanUrl(path);
37
- return {
38
- file,
39
- postfix: path.slice(file.length)
40
- };
41
- }
42
- const internalRequests = ["@vite/client", "@vite/env"], internalRequestRegexp = /* @__PURE__ */ new RegExp(`^/?(?:${internalRequests.join("|")})$`);
43
- function isInternalRequest(id) {
44
- return internalRequestRegexp.test(id);
45
- }
46
- // https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
47
- const prefixedBuiltins = new Set([
48
- "node:sea",
49
- "node:sqlite",
50
- "node:test",
51
- "node:test/reporters"
52
- ]), builtins = new Set([
53
- ...node_module.builtinModules,
54
- "assert/strict",
55
- "diagnostics_channel",
56
- "dns/promises",
57
- "fs/promises",
58
- "path/posix",
59
- "path/win32",
60
- "readline/promises",
61
- "stream/consumers",
62
- "stream/promises",
63
- "stream/web",
64
- "timers/promises",
65
- "util/types",
66
- "wasi"
67
- ]);
68
- function normalizeModuleId(id) {
69
- return prefixedBuiltins.has(id) ? id : id.startsWith("file://") ? node_url.fileURLToPath(id) : id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
70
- }
71
- function isPrimitive(v) {
72
- return v !== Object(v);
73
- }
74
- function toFilePath(id, root) {
75
- let { absolute, exists } = (() => {
76
- if (id.startsWith("/@fs/")) return {
77
- absolute: id.slice(4),
78
- exists: true
79
- };
80
- // check if /src/module.js -> <root>/src/module.js
81
- if (!id.startsWith(withTrailingSlash(root)) && id.startsWith("/")) {
82
- const resolved = pathe.resolve(root, id.slice(1));
83
- if (fs.existsSync(cleanUrl(resolved))) return {
84
- absolute: resolved,
85
- exists: true
86
- };
87
- } else if (id.startsWith(withTrailingSlash(root)) && fs.existsSync(cleanUrl(id))) return {
88
- absolute: id,
89
- exists: true
90
- };
91
- return {
92
- absolute: id,
93
- exists: false
94
- };
95
- })();
96
- if (absolute.startsWith("//")) absolute = absolute.slice(1);
97
- // disambiguate the `<UNIT>:/` on windows: see nodejs/node#31710
98
- return {
99
- path: isWindows && absolute.startsWith("/") ? slash(node_url.fileURLToPath(node_url.pathToFileURL(absolute.slice(1)).href)) : absolute,
100
- exists
101
- };
102
- }
103
- const NODE_BUILTIN_NAMESPACE = "node:";
104
- function isNodeBuiltin(id) {
105
- return prefixedBuiltins.has(id) ? true : builtins.has(id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(5) : id);
106
- }
107
- /**
108
- * Convert `Arrayable<T>` to `Array<T>`
109
- *
110
- * @category Array
111
- */
112
- function toArray(array) {
113
- if (array === null || array === void 0) array = [];
114
- return Array.isArray(array) ? array : [array];
115
- }
116
- function getCachedData(cache, basedir, originalBasedir) {
117
- const pkgData = cache.get(getFnpdCacheKey(basedir));
118
- if (pkgData) return traverseBetweenDirs(originalBasedir, basedir, (dir) => {
119
- cache.set(getFnpdCacheKey(dir), pkgData);
120
- }), pkgData;
121
- }
122
- function setCacheData(cache, data, basedir, originalBasedir) {
123
- cache.set(getFnpdCacheKey(basedir), data), traverseBetweenDirs(originalBasedir, basedir, (dir) => {
124
- cache.set(getFnpdCacheKey(dir), data);
125
- });
126
- }
127
- function getFnpdCacheKey(basedir) {
128
- return `fnpd_${basedir}`;
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
- */
135
- function traverseBetweenDirs(longerDir, shorterDir, cb) {
136
- while (longerDir !== shorterDir) cb(longerDir), longerDir = pathe.dirname(longerDir);
137
- }
138
- function withTrailingSlash(path) {
139
- return path[path.length - 1] === "/" ? path : `${path}/`;
140
- }
141
- function createImportMetaEnvProxy() {
142
- // packages/vitest/src/node/plugins/index.ts:146
143
- const booleanKeys = [
144
- "DEV",
145
- "PROD",
146
- "SSR"
147
- ];
148
- return new Proxy(process.env, {
149
- get(_, key) {
150
- return typeof key === "string" ? booleanKeys.includes(key) ? !!process.env[key] : process.env[key] : void 0;
151
- },
152
- set(_, key, value) {
153
- if (typeof key !== "string") return true;
154
- if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";
155
- else process.env[key] = value;
156
- return true;
157
- }
158
- });
159
- }
160
- const packageCache = /* @__PURE__ */ new Map();
161
- async function findNearestPackageData(basedir) {
162
- const originalBasedir = basedir;
163
- while (basedir) {
164
- var _await$fsp$stat$catch;
165
- const cached = getCachedData(packageCache, basedir, originalBasedir);
166
- if (cached) return cached;
167
- const pkgPath = pathe.join(basedir, "package.json");
168
- 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()) {
169
- const pkgData = JSON.parse(await fs.promises.readFile(pkgPath, "utf8"));
170
- if (packageCache) setCacheData(packageCache, pkgData, basedir, originalBasedir);
171
- return pkgData;
172
- }
173
- const nextBasedir = pathe.dirname(basedir);
174
- if (nextBasedir === basedir) break;
175
- basedir = nextBasedir;
176
- }
177
- return {};
178
- }
179
-
180
- exports.VALID_ID_PREFIX = VALID_ID_PREFIX;
181
- exports.cleanUrl = cleanUrl;
182
- exports.createImportMetaEnvProxy = createImportMetaEnvProxy;
183
- exports.findNearestPackageData = findNearestPackageData;
184
- exports.getCachedData = getCachedData;
185
- exports.isBareImport = isBareImport;
186
- exports.isInternalRequest = isInternalRequest;
187
- exports.isNodeBuiltin = isNodeBuiltin;
188
- exports.isPrimitive = isPrimitive;
189
- exports.isWindows = isWindows;
190
- exports.normalizeModuleId = normalizeModuleId;
191
- exports.normalizeRequestId = normalizeRequestId;
192
- exports.setCacheData = setCacheData;
193
- exports.slash = slash;
194
- exports.toArray = toArray;
195
- exports.toFilePath = toFilePath;
196
- exports.withTrailingSlash = withTrailingSlash;
package/vite-node.mjs DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import('./dist/cli.mjs')
File without changes
File without changes
File without changes