vite-node 0.32.4 → 0.34.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/utils.mjs CHANGED
@@ -1,9 +1,13 @@
1
1
  import { fileURLToPath, pathToFileURL } from 'node:url';
2
2
  import { builtinModules } from 'node:module';
3
3
  import { existsSync } from 'node:fs';
4
- import { resolve } from 'pathe';
4
+ import { resolve, dirname } from 'pathe';
5
5
 
6
6
  const isWindows = process.platform === "win32";
7
+ const drive = isWindows ? process.cwd()[0] : null;
8
+ const driveOpposite = drive ? drive === drive.toUpperCase() ? drive.toLowerCase() : drive.toUpperCase() : null;
9
+ const driveRegexp = drive ? new RegExp(`(?:^|/@fs/)${drive}(:[\\/])`) : null;
10
+ const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposite}(:[\\/])`) : null;
7
11
  function slash(str) {
8
12
  return str.replace(/\\/g, "/");
9
13
  }
@@ -11,6 +15,8 @@ const VALID_ID_PREFIX = "/@id/";
11
15
  function normalizeRequestId(id, base) {
12
16
  if (base && id.startsWith(base))
13
17
  id = `/${id.slice(base.length)}`;
18
+ if (driveRegexp && !(driveRegexp == null ? void 0 : driveRegexp.test(id)) && (driveOppositeRegext == null ? void 0 : driveOppositeRegext.test(id)))
19
+ id = id.replace(driveOppositeRegext, `${drive}$1`);
14
20
  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(/\?+$/, "");
15
21
  }
16
22
  const queryRE = /\?.*$/s;
@@ -26,7 +32,28 @@ const internalRequestRegexp = new RegExp(`^/?(${internalRequests.join("|")})$`);
26
32
  function isInternalRequest(id) {
27
33
  return internalRequestRegexp.test(id);
28
34
  }
35
+ const prefixedBuiltins = /* @__PURE__ */ new Set([
36
+ "node:test"
37
+ ]);
38
+ const builtins = /* @__PURE__ */ new Set([
39
+ ...builtinModules,
40
+ "assert/strict",
41
+ "diagnostics_channel",
42
+ "dns/promises",
43
+ "fs/promises",
44
+ "path/posix",
45
+ "path/win32",
46
+ "readline/promises",
47
+ "stream/consumers",
48
+ "stream/promises",
49
+ "stream/web",
50
+ "timers/promises",
51
+ "util/types",
52
+ "wasi"
53
+ ]);
29
54
  function normalizeModuleId(id) {
55
+ if (prefixedBuiltins.has(id))
56
+ return id;
30
57
  return id.replace(/\\/g, "/").replace(/^\/@fs\//, isWindows ? "" : "/").replace(/^file:\//, "/").replace(/^node:/, "").replace(/^\/+/, "/");
31
58
  }
32
59
  function isPrimitive(v) {
@@ -52,24 +79,10 @@ function toFilePath(id, root) {
52
79
  exists
53
80
  };
54
81
  }
55
- const builtins = /* @__PURE__ */ new Set([
56
- ...builtinModules,
57
- "assert/strict",
58
- "diagnostics_channel",
59
- "dns/promises",
60
- "fs/promises",
61
- "path/posix",
62
- "path/win32",
63
- "readline/promises",
64
- "stream/consumers",
65
- "stream/promises",
66
- "stream/web",
67
- "timers/promises",
68
- "util/types",
69
- "wasi"
70
- ]);
71
82
  const NODE_BUILTIN_NAMESPACE = "node:";
72
83
  function isNodeBuiltin(id) {
84
+ if (prefixedBuiltins.has(id))
85
+ return true;
73
86
  return builtins.has(
74
87
  id.startsWith(NODE_BUILTIN_NAMESPACE) ? id.slice(NODE_BUILTIN_NAMESPACE.length) : id
75
88
  );
@@ -81,5 +94,29 @@ function toArray(array) {
81
94
  return array;
82
95
  return [array];
83
96
  }
97
+ function getCachedData(cache, basedir, originalBasedir) {
98
+ const pkgData = cache.get(getFnpdCacheKey(basedir));
99
+ if (pkgData) {
100
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
101
+ cache.set(getFnpdCacheKey(dir), pkgData);
102
+ });
103
+ return pkgData;
104
+ }
105
+ }
106
+ function setCacheData(cache, data, basedir, originalBasedir) {
107
+ cache.set(getFnpdCacheKey(basedir), data);
108
+ traverseBetweenDirs(originalBasedir, basedir, (dir) => {
109
+ cache.set(getFnpdCacheKey(dir), data);
110
+ });
111
+ }
112
+ function getFnpdCacheKey(basedir) {
113
+ return `fnpd_${basedir}`;
114
+ }
115
+ function traverseBetweenDirs(longerDir, shorterDir, cb) {
116
+ while (longerDir !== shorterDir) {
117
+ cb(longerDir);
118
+ longerDir = dirname(longerDir);
119
+ }
120
+ }
84
121
 
85
- export { VALID_ID_PREFIX, cleanUrl, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, slash, toArray, toFilePath };
122
+ export { VALID_ID_PREFIX, cleanUrl, getCachedData, hashRE, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, queryRE, setCacheData, slash, toArray, toFilePath };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.32.4",
3
+ "version": "0.34.0",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -45,7 +45,13 @@
45
45
  "types": "./dist/source-map.d.ts",
46
46
  "require": "./dist/source-map.cjs",
47
47
  "import": "./dist/source-map.mjs"
48
- }
48
+ },
49
+ "./constants": {
50
+ "types": "./dist/constants.d.ts",
51
+ "require": "./dist/constants.cjs",
52
+ "import": "./dist/constants.mjs"
53
+ },
54
+ "./*": "./*"
49
55
  },
50
56
  "main": "./dist/index.mjs",
51
57
  "module": "./dist/index.mjs",