vite-node 3.1.1 → 3.1.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/cli.cjs CHANGED
@@ -21,7 +21,7 @@ require('node:perf_hooks');
21
21
  require('es-module-lexer');
22
22
  require('./constants.cjs');
23
23
 
24
- var version = "3.1.1";
24
+ var version = "3.1.2";
25
25
 
26
26
  const cli = cac("vite-node");
27
27
  cli.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").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { V as ViteNodeServerOptions } from './index.d-CjeQoW3r.js';
1
+ import { V as ViteNodeServerOptions } from './index.d-CWZbpOcv.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  interface CliOptions {
package/dist/cli.mjs CHANGED
@@ -19,7 +19,7 @@ import 'node:perf_hooks';
19
19
  import 'es-module-lexer';
20
20
  import './constants.mjs';
21
21
 
22
- var version = "3.1.1";
22
+ var version = "3.1.2";
23
23
 
24
24
  const cli = cac("vite-node");
25
25
  cli.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").option("-v, --version", "Output the version number").option("-h, --help", "Display help for command");
package/dist/client.cjs CHANGED
@@ -217,6 +217,18 @@ class ViteNodeRunner {
217
217
  async dependencyRequest(id, fsPath, callstack) {
218
218
  return await this.cachedRequest(id, fsPath, callstack);
219
219
  }
220
+ async _fetchModule(id, importer) {
221
+ try {
222
+ return await this.options.fetchModule(id);
223
+ } catch (cause) {
224
+ if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof (cause === null || cause === void 0 ? void 0 : cause.message) === "string" && cause.message.includes("Failed to load url")) {
225
+ const error = new Error(`Cannot find ${utils.isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
226
+ error.code = "ERR_MODULE_NOT_FOUND";
227
+ throw error;
228
+ }
229
+ throw cause;
230
+ }
231
+ }
220
232
  /** @internal */
221
233
  async directRequest(id, fsPath, _callstack) {
222
234
  const moduleId = utils.normalizeModuleId(fsPath);
@@ -231,7 +243,7 @@ class ViteNodeRunner {
231
243
  };
232
244
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
233
245
  if (id in requestStubs) return requestStubs[id];
234
- let { code: transformed, externalize } = await this.options.fetchModule(id);
246
+ let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
235
247
  if (externalize) {
236
248
  debugNative(externalize);
237
249
  const exports = await this.interopedImport(externalize);
@@ -413,7 +425,7 @@ function defineExport(exports, key, value) {
413
425
  function exportAll(exports, sourceModule) {
414
426
  if (exports === sourceModule) return;
415
427
  if (utils.isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
416
- for (const key in sourceModule) if (key !== "default") try {
428
+ for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
417
429
  defineExport(exports, key, () => sourceModule[key]);
418
430
  } catch {}
419
431
  }
package/dist/client.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import './trace-mapping.d-DLVdEqOp.js';
2
- export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, f as ModuleExecutionInfo, a as ViteNodeRunner } from './index.d-CjeQoW3r.js';
2
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, f as ModuleExecutionInfo, a as ViteNodeRunner } from './index.d-CWZbpOcv.js';
package/dist/client.mjs CHANGED
@@ -4,7 +4,7 @@ import { pathToFileURL, fileURLToPath } from 'node:url';
4
4
  import vm from 'node:vm';
5
5
  import createDebug from 'debug';
6
6
  import { extractSourceMap } from './source-map.mjs';
7
- import { createImportMetaEnvProxy, slash, isInternalRequest, isNodeBuiltin, normalizeRequestId, toFilePath, normalizeModuleId, cleanUrl, isPrimitive } from './utils.mjs';
7
+ import { createImportMetaEnvProxy, slash, isInternalRequest, isNodeBuiltin, normalizeRequestId, toFilePath, normalizeModuleId, cleanUrl, isPrimitive, isBareImport } from './utils.mjs';
8
8
  import 'pathe';
9
9
  import 'node:fs';
10
10
 
@@ -215,6 +215,18 @@ class ViteNodeRunner {
215
215
  async dependencyRequest(id, fsPath, callstack) {
216
216
  return await this.cachedRequest(id, fsPath, callstack);
217
217
  }
218
+ async _fetchModule(id, importer) {
219
+ try {
220
+ return await this.options.fetchModule(id);
221
+ } catch (cause) {
222
+ if (typeof cause === "object" && cause.code === "ERR_LOAD_URL" || typeof (cause === null || cause === void 0 ? void 0 : cause.message) === "string" && cause.message.includes("Failed to load url")) {
223
+ const error = new Error(`Cannot find ${isBareImport(id) ? "package" : "module"} '${id}'${importer ? ` imported from '${importer}'` : ""}`, { cause });
224
+ error.code = "ERR_MODULE_NOT_FOUND";
225
+ throw error;
226
+ }
227
+ throw cause;
228
+ }
229
+ }
218
230
  /** @internal */
219
231
  async directRequest(id, fsPath, _callstack) {
220
232
  const moduleId = normalizeModuleId(fsPath);
@@ -229,7 +241,7 @@ class ViteNodeRunner {
229
241
  };
230
242
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
231
243
  if (id in requestStubs) return requestStubs[id];
232
- let { code: transformed, externalize } = await this.options.fetchModule(id);
244
+ let { code: transformed, externalize } = await this._fetchModule(id, callstack[callstack.length - 2]);
233
245
  if (externalize) {
234
246
  debugNative(externalize);
235
247
  const exports = await this.interopedImport(externalize);
@@ -411,7 +423,7 @@ function defineExport(exports, key, value) {
411
423
  function exportAll(exports, sourceModule) {
412
424
  if (exports === sourceModule) return;
413
425
  if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;
414
- for (const key in sourceModule) if (key !== "default") try {
426
+ for (const key in sourceModule) if (key !== "default" && !(key in exports)) try {
415
427
  defineExport(exports, key, () => sourceModule[key]);
416
428
  } catch {}
417
429
  }
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HMRPayload, Plugin } from 'vite';
2
2
  import { EventEmitter } from 'node:events';
3
- import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index.d-CjeQoW3r.js';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index.d-CWZbpOcv.js';
4
4
  import './trace-mapping.d-DLVdEqOp.js';
5
5
 
6
6
  type EventType = string | symbol;
@@ -186,6 +186,7 @@ declare class ViteNodeRunner {
186
186
  shouldResolveId(id: string, _importee?: string): boolean;
187
187
  private _resolveUrl;
188
188
  resolveUrl(id: string, importee?: string): Promise<[url: string, fsPath: string]>;
189
+ private _fetchModule;
189
190
  protected getContextPrimitives(): {
190
191
  Object: ObjectConstructor
191
192
  Reflect: typeof Reflect
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { A as Arrayable, g as Awaitable, j as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, h as FetchFunction, F as FetchResult, b as HotContext, k as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, i as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, m as ViteNodeResolveModule, l as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-CjeQoW3r.js';
1
+ export { A as Arrayable, g as Awaitable, j as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, h as FetchFunction, F as FetchResult, b as HotContext, k as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, i as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, m as ViteNodeResolveModule, l as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-CWZbpOcv.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index.d-CjeQoW3r.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index.d-CWZbpOcv.js';
3
3
  import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
4
4
 
5
5
  declare class Debugger {
package/dist/types.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
2
- export { A as Arrayable, g as Awaitable, j as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, h as FetchFunction, F as FetchResult, b as HotContext, k as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, i as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, m as ViteNodeResolveModule, l as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-CjeQoW3r.js';
2
+ export { A as Arrayable, g as Awaitable, j as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, h as FetchFunction, F as FetchResult, b as HotContext, k as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, i as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, m as ViteNodeResolveModule, l as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-CWZbpOcv.js';
package/dist/utils.cjs CHANGED
@@ -13,6 +13,10 @@ const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposi
13
13
  function slash(str) {
14
14
  return str.replace(/\\/g, "/");
15
15
  }
16
+ const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
17
+ function isBareImport(id) {
18
+ return bareImportRE.test(id);
19
+ }
16
20
  const VALID_ID_PREFIX = "/@id/";
17
21
  function normalizeRequestId(id, base) {
18
22
  if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
@@ -189,6 +193,7 @@ exports.cleanUrl = cleanUrl;
189
193
  exports.createImportMetaEnvProxy = createImportMetaEnvProxy;
190
194
  exports.findNearestPackageData = findNearestPackageData;
191
195
  exports.getCachedData = getCachedData;
196
+ exports.isBareImport = isBareImport;
192
197
  exports.isInternalRequest = isInternalRequest;
193
198
  exports.isNodeBuiltin = isNodeBuiltin;
194
199
  exports.isPrimitive = isPrimitive;
package/dist/utils.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { N as Nullable, A as Arrayable } from './index.d-CjeQoW3r.js';
1
+ import { N as Nullable, A as Arrayable } from './index.d-CWZbpOcv.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  declare const isWindows: boolean;
5
5
  declare function slash(str: string): string;
6
+ declare function isBareImport(id: string): boolean;
6
7
  declare const VALID_ID_PREFIX = "/@id/";
7
8
  declare function normalizeRequestId(id: string, base?: string): string;
8
9
  declare function cleanUrl(url: string): string;
@@ -28,4 +29,4 @@ declare function findNearestPackageData(basedir: string): Promise<{
28
29
  type?: "module" | "commonjs"
29
30
  }>;
30
31
 
31
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
32
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isBareImport, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/dist/utils.mjs CHANGED
@@ -11,6 +11,10 @@ const driveOppositeRegext = driveOpposite ? new RegExp(`(?:^|/@fs/)${driveOpposi
11
11
  function slash(str) {
12
12
  return str.replace(/\\/g, "/");
13
13
  }
14
+ const bareImportRE = /^(?![a-z]:)[\w@](?!.*:\/\/)/i;
15
+ function isBareImport(id) {
16
+ return bareImportRE.test(id);
17
+ }
14
18
  const VALID_ID_PREFIX = "/@id/";
15
19
  function normalizeRequestId(id, base) {
16
20
  if (base && id.startsWith(withTrailingSlash(base))) id = `/${id.slice(base.length)}`;
@@ -182,4 +186,4 @@ async function findNearestPackageData(basedir) {
182
186
  return {};
183
187
  }
184
188
 
185
- export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
189
+ export { VALID_ID_PREFIX, cleanUrl, createImportMetaEnvProxy, findNearestPackageData, getCachedData, isBareImport, isInternalRequest, isNodeBuiltin, isPrimitive, isWindows, normalizeModuleId, normalizeRequestId, setCacheData, slash, toArray, toFilePath, withTrailingSlash };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "3.1.1",
4
+ "version": "3.1.2",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",