vite-node 0.31.3 → 0.32.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/cli.cjs CHANGED
@@ -24,7 +24,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
24
24
  var cac__default = /*#__PURE__*/_interopDefaultLegacy(cac);
25
25
  var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
26
26
 
27
- var version = "0.31.3";
27
+ var version = "0.32.0";
28
28
 
29
29
  const cli = cac__default["default"]("vite-node");
30
30
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as ViteNodeServerOptions } from './types-33f0e4ff.js';
1
+ import { f as ViteNodeServerOptions } from './types-516036fa.js';
2
2
  import 'vite/types/hot';
3
3
  import './types.d-7442d07f.js';
4
4
 
package/dist/cli.mjs CHANGED
@@ -17,7 +17,7 @@ import 'node:path';
17
17
  import 'node:vm';
18
18
  import 'node:events';
19
19
 
20
- var version = "0.31.3";
20
+ var version = "0.32.0";
21
21
 
22
22
  const cli = cac("vite-node");
23
23
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-m, --mode <mode>", "Set env mode").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--script", "Use vite-node as a script runner").option("--options <options>", "Use specified Vite server options").help();
package/dist/client.cjs CHANGED
@@ -86,7 +86,7 @@ class ModuleCacheMap extends Map {
86
86
  update(fsPath, mod) {
87
87
  fsPath = this.normalizePath(fsPath);
88
88
  if (!super.has(fsPath))
89
- super.set(fsPath, mod);
89
+ this.setByModuleId(fsPath, mod);
90
90
  else
91
91
  Object.assign(super.get(fsPath), mod);
92
92
  return this;
@@ -99,8 +99,15 @@ class ModuleCacheMap extends Map {
99
99
  }
100
100
  getByModuleId(modulePath) {
101
101
  if (!super.has(modulePath))
102
- super.set(modulePath, {});
103
- return super.get(modulePath);
102
+ this.setByModuleId(modulePath, {});
103
+ const mod = super.get(modulePath);
104
+ if (!mod.imports) {
105
+ Object.assign(mod, {
106
+ imports: /* @__PURE__ */ new Set(),
107
+ importers: /* @__PURE__ */ new Set()
108
+ });
109
+ }
110
+ return mod;
104
111
  }
105
112
  get(fsPath) {
106
113
  return this.getByModuleId(this.normalizePath(fsPath));
@@ -112,12 +119,13 @@ class ModuleCacheMap extends Map {
112
119
  return this.deleteByModuleId(this.normalizePath(fsPath));
113
120
  }
114
121
  invalidateModule(mod) {
115
- var _a;
122
+ var _a, _b;
116
123
  delete mod.evaluated;
117
124
  delete mod.resolving;
118
125
  delete mod.promise;
119
126
  delete mod.exports;
120
127
  (_a = mod.importers) == null ? void 0 : _a.clear();
128
+ (_b = mod.imports) == null ? void 0 : _b.clear();
121
129
  return true;
122
130
  }
123
131
  /**
@@ -188,16 +196,12 @@ class ViteNodeRunner {
188
196
  async cachedRequest(id, fsPath, callstack) {
189
197
  const importee = callstack[callstack.length - 1];
190
198
  const mod = this.moduleCache.get(fsPath);
191
- if (!mod.importers)
192
- mod.importers = /* @__PURE__ */ new Set();
199
+ const { imports, importers } = mod;
193
200
  if (importee)
194
- mod.importers.add(importee);
201
+ importers.add(importee);
195
202
  const getStack = () => `stack:
196
203
  ${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
197
- if (callstack.includes(fsPath) || callstack.some((c) => {
198
- var _a;
199
- return (_a = this.moduleCache.get(c).importers) == null ? void 0 : _a.has(fsPath);
200
- })) {
204
+ if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
201
205
  if (mod.exports)
202
206
  return mod.exports;
203
207
  }
@@ -218,7 +222,7 @@ ${getStack()}`), 2e3);
218
222
  }
219
223
  }
220
224
  shouldResolveId(id, _importee) {
221
- return !utils.isInternalRequest(id) && !utils.isNodeBuiltin(id);
225
+ return !utils.isInternalRequest(id) && !utils.isNodeBuiltin(id) && !id.startsWith("data:");
222
226
  }
223
227
  async _resolveUrl(id, importer) {
224
228
  if (importer && id.startsWith(utils.VALID_ID_PREFIX))
@@ -230,9 +234,19 @@ ${getStack()}`), 2e3);
230
234
  if (!this.options.resolveId || exists)
231
235
  return [id, path];
232
236
  const resolved = await this.options.resolveId(id, importer);
233
- const resolvedId = resolved ? utils.normalizeRequestId(resolved.id, this.options.base) : id;
234
- const fsPath = resolved ? resolvedId : path;
235
- return [resolvedId, fsPath];
237
+ if (!resolved) {
238
+ const error = new Error(
239
+ `Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
240
+
241
+ - If you rely on tsconfig.json to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
242
+ - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`
243
+ );
244
+ Object.defineProperty(error, "code", { value: "ERR_MODULE_NOT_FOUND", enumerable: true });
245
+ Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), { value: { id, importer }, enumerable: false });
246
+ throw error;
247
+ }
248
+ const resolvedId = utils.normalizeRequestId(resolved.id, this.options.base);
249
+ return [resolvedId, resolvedId];
236
250
  }
237
251
  async resolveUrl(id, importee) {
238
252
  const resolveKey = `resolve:${id}`;
@@ -254,6 +268,9 @@ ${getStack()}`), 2e3);
254
268
  const mod = this.moduleCache.getByModuleId(moduleId);
255
269
  const request = async (dep) => {
256
270
  const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
271
+ const depMod = this.moduleCache.getByModuleId(depFsPath);
272
+ depMod.importers.add(moduleId);
273
+ mod.imports.add(depFsPath);
257
274
  return this.dependencyRequest(id2, depFsPath, callstack);
258
275
  };
259
276
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
package/dist/client.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import './types.d-7442d07f.js';
2
- export { i as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-33f0e4ff.js';
2
+ export { i as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-516036fa.js';
3
3
  import 'vite/types/hot';
package/dist/client.mjs CHANGED
@@ -59,7 +59,7 @@ class ModuleCacheMap extends Map {
59
59
  update(fsPath, mod) {
60
60
  fsPath = this.normalizePath(fsPath);
61
61
  if (!super.has(fsPath))
62
- super.set(fsPath, mod);
62
+ this.setByModuleId(fsPath, mod);
63
63
  else
64
64
  Object.assign(super.get(fsPath), mod);
65
65
  return this;
@@ -72,8 +72,15 @@ class ModuleCacheMap extends Map {
72
72
  }
73
73
  getByModuleId(modulePath) {
74
74
  if (!super.has(modulePath))
75
- super.set(modulePath, {});
76
- return super.get(modulePath);
75
+ this.setByModuleId(modulePath, {});
76
+ const mod = super.get(modulePath);
77
+ if (!mod.imports) {
78
+ Object.assign(mod, {
79
+ imports: /* @__PURE__ */ new Set(),
80
+ importers: /* @__PURE__ */ new Set()
81
+ });
82
+ }
83
+ return mod;
77
84
  }
78
85
  get(fsPath) {
79
86
  return this.getByModuleId(this.normalizePath(fsPath));
@@ -85,12 +92,13 @@ class ModuleCacheMap extends Map {
85
92
  return this.deleteByModuleId(this.normalizePath(fsPath));
86
93
  }
87
94
  invalidateModule(mod) {
88
- var _a;
95
+ var _a, _b;
89
96
  delete mod.evaluated;
90
97
  delete mod.resolving;
91
98
  delete mod.promise;
92
99
  delete mod.exports;
93
100
  (_a = mod.importers) == null ? void 0 : _a.clear();
101
+ (_b = mod.imports) == null ? void 0 : _b.clear();
94
102
  return true;
95
103
  }
96
104
  /**
@@ -161,16 +169,12 @@ class ViteNodeRunner {
161
169
  async cachedRequest(id, fsPath, callstack) {
162
170
  const importee = callstack[callstack.length - 1];
163
171
  const mod = this.moduleCache.get(fsPath);
164
- if (!mod.importers)
165
- mod.importers = /* @__PURE__ */ new Set();
172
+ const { imports, importers } = mod;
166
173
  if (importee)
167
- mod.importers.add(importee);
174
+ importers.add(importee);
168
175
  const getStack = () => `stack:
169
176
  ${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
170
- if (callstack.includes(fsPath) || callstack.some((c) => {
171
- var _a;
172
- return (_a = this.moduleCache.get(c).importers) == null ? void 0 : _a.has(fsPath);
173
- })) {
177
+ if (callstack.includes(fsPath) || Array.from(imports.values()).some((i) => importers.has(i))) {
174
178
  if (mod.exports)
175
179
  return mod.exports;
176
180
  }
@@ -191,7 +195,7 @@ ${getStack()}`), 2e3);
191
195
  }
192
196
  }
193
197
  shouldResolveId(id, _importee) {
194
- return !isInternalRequest(id) && !isNodeBuiltin(id);
198
+ return !isInternalRequest(id) && !isNodeBuiltin(id) && !id.startsWith("data:");
195
199
  }
196
200
  async _resolveUrl(id, importer) {
197
201
  if (importer && id.startsWith(VALID_ID_PREFIX))
@@ -203,9 +207,19 @@ ${getStack()}`), 2e3);
203
207
  if (!this.options.resolveId || exists)
204
208
  return [id, path];
205
209
  const resolved = await this.options.resolveId(id, importer);
206
- const resolvedId = resolved ? normalizeRequestId(resolved.id, this.options.base) : id;
207
- const fsPath = resolved ? resolvedId : path;
208
- return [resolvedId, fsPath];
210
+ if (!resolved) {
211
+ const error = new Error(
212
+ `Cannot find module '${id}'${importer ? ` imported from '${importer}'` : ""}.
213
+
214
+ - If you rely on tsconfig.json to resolve modules, please install "vite-tsconfig-paths" plugin to handle module resolution.
215
+ - Make sure you don't have relative aliases in your Vitest config. Use absolute paths instead. Read more: https://vitest.dev/guide/common-errors`
216
+ );
217
+ Object.defineProperty(error, "code", { value: "ERR_MODULE_NOT_FOUND", enumerable: true });
218
+ Object.defineProperty(error, Symbol.for("vitest.error.not_found.data"), { value: { id, importer }, enumerable: false });
219
+ throw error;
220
+ }
221
+ const resolvedId = normalizeRequestId(resolved.id, this.options.base);
222
+ return [resolvedId, resolvedId];
209
223
  }
210
224
  async resolveUrl(id, importee) {
211
225
  const resolveKey = `resolve:${id}`;
@@ -227,6 +241,9 @@ ${getStack()}`), 2e3);
227
241
  const mod = this.moduleCache.getByModuleId(moduleId);
228
242
  const request = async (dep) => {
229
243
  const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
244
+ const depMod = this.moduleCache.getByModuleId(depFsPath);
245
+ depMod.importers.add(moduleId);
246
+ mod.imports.add(depFsPath);
230
247
  return this.dependencyRequest(id2, depFsPath, callstack);
231
248
  };
232
249
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HMRPayload as HMRPayload$1, Plugin } from 'vite';
3
- import { h as ViteNodeRunner, H as HotContext } from './types-33f0e4ff.js';
3
+ import { h as ViteNodeRunner, H as HotContext } from './types-516036fa.js';
4
4
  import 'vite/types/hot';
5
5
  import './types.d-7442d07f.js';
6
6
 
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-33f0e4ff.js';
1
+ export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-516036fa.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
3
3
  import 'vite/types/hot';
package/dist/server.cjs CHANGED
@@ -21,6 +21,7 @@ var c__default = /*#__PURE__*/_interopDefaultLegacy(c);
21
21
 
22
22
  const KNOWN_ASSET_TYPES = [
23
23
  // images
24
+ "apng",
24
25
  "png",
25
26
  "jpe?g",
26
27
  "jfif",
@@ -124,7 +125,7 @@ function matchExternalizePattern(id, moduleDirectories, patterns) {
124
125
  return true;
125
126
  for (const ex of patterns) {
126
127
  if (typeof ex === "string") {
127
- if (moduleDirectories.some((dir) => id.includes(pathe.join(dir, id))))
128
+ if (moduleDirectories.some((dir) => id.includes(pathe.join(dir, ex))))
128
129
  return true;
129
130
  } else {
130
131
  if (ex.test(id))
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
2
  import { E as EncodedSourceMap } from './types.d-7442d07f.js';
3
- import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-33f0e4ff.js';
3
+ import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-516036fa.js';
4
4
  import 'vite/types/hot';
5
5
 
6
6
  declare class Debugger {
package/dist/server.mjs CHANGED
@@ -12,6 +12,7 @@ import 'node:path';
12
12
 
13
13
  const KNOWN_ASSET_TYPES = [
14
14
  // images
15
+ "apng",
15
16
  "png",
16
17
  "jpe?g",
17
18
  "jfif",
@@ -115,7 +116,7 @@ function matchExternalizePattern(id, moduleDirectories, patterns) {
115
116
  return true;
116
117
  for (const ex of patterns) {
117
118
  if (typeof ex === "string") {
118
- if (moduleDirectories.some((dir) => id.includes(join(dir, id))))
119
+ if (moduleDirectories.some((dir) => id.includes(join(dir, ex))))
119
120
  return true;
120
121
  } else {
121
122
  if (ex.test(id))
@@ -7,11 +7,11 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
7
7
  /**
8
8
  * Assign partial data to the map
9
9
  */
10
- update(fsPath: string, mod: Partial<ModuleCache>): this;
10
+ update(fsPath: string, mod: ModuleCache): this;
11
11
  setByModuleId(modulePath: string, mod: ModuleCache): this;
12
12
  set(fsPath: string, mod: ModuleCache): this;
13
- getByModuleId(modulePath: string): ModuleCache;
14
- get(fsPath: string): ModuleCache;
13
+ getByModuleId(modulePath: string): ModuleCache & Required<Pick<ModuleCache, "imports" | "importers">>;
14
+ get(fsPath: string): ModuleCache & Required<Pick<ModuleCache, "imports" | "importers">>;
15
15
  deleteByModuleId(modulePath: string): boolean;
16
16
  delete(fsPath: string): boolean;
17
17
  invalidateModule(mod: ModuleCache): boolean;
@@ -115,6 +115,7 @@ interface ModuleCache {
115
115
  * Module ids that imports this module
116
116
  */
117
117
  importers?: Set<string>;
118
+ imports?: Set<string>;
118
119
  }
119
120
  interface ViteNodeRunnerOptions {
120
121
  root: string;
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  import 'vite/types/hot';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap } from './types.d-7442d07f.js';
3
- export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-33f0e4ff.js';
3
+ export { A as Arrayable, a as Awaitable, C as CreateHotContextFunction, g as DebuggerOptions, D as DepsHandlingOptions, b as FetchFunction, F as FetchResult, H as HotContext, d as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, c as ResolveIdFunction, S as StartOfSourceMap, e as ViteNodeResolveId, V as ViteNodeRunnerOptions, f as ViteNodeServerOptions } from './types-516036fa.js';
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-33f0e4ff.js';
1
+ import { N as Nullable, A as Arrayable } from './types-516036fa.js';
2
2
  import 'vite/types/hot';
3
3
  import './types.d-7442d07f.js';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.31.3",
3
+ "version": "0.32.0",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",