vite-node 0.31.1 → 0.31.3

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.1";
27
+ var version = "0.31.3";
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();
@@ -87,7 +87,7 @@ async function run(files, options = {}) {
87
87
  }
88
88
  }
89
89
  function parseServerOptions(serverOptions) {
90
- var _a, _b, _c, _d, _e;
90
+ var _a, _b, _c, _d, _e, _f, _g;
91
91
  const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : utils.toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
92
92
  return {
93
93
  ...serverOptions,
@@ -98,12 +98,13 @@ function parseServerOptions(serverOptions) {
98
98
  }) : true,
99
99
  external: utils.toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
100
100
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
101
- })
101
+ }),
102
+ moduleDirectories: ((_d = serverOptions.deps) == null ? void 0 : _d.moduleDirectories) ? utils.toArray((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) : void 0
102
103
  },
103
104
  transformMode: {
104
105
  ...serverOptions.transformMode,
105
- ssr: utils.toArray((_d = serverOptions.transformMode) == null ? void 0 : _d.ssr).map((dep) => new RegExp(dep)),
106
- web: utils.toArray((_e = serverOptions.transformMode) == null ? void 0 : _e.web).map((dep) => new RegExp(dep))
106
+ ssr: utils.toArray((_f = serverOptions.transformMode) == null ? void 0 : _f.ssr).map((dep) => new RegExp(dep)),
107
+ web: utils.toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.web).map((dep) => new RegExp(dep))
107
108
  }
108
109
  };
109
110
  }
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { f as ViteNodeServerOptions } from './types-557128db.js';
1
+ import { f as ViteNodeServerOptions } from './types-33f0e4ff.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.1";
20
+ var version = "0.31.3";
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();
@@ -80,7 +80,7 @@ async function run(files, options = {}) {
80
80
  }
81
81
  }
82
82
  function parseServerOptions(serverOptions) {
83
- var _a, _b, _c, _d, _e;
83
+ var _a, _b, _c, _d, _e, _f, _g;
84
84
  const inlineOptions = ((_a = serverOptions.deps) == null ? void 0 : _a.inline) === true ? true : toArray((_b = serverOptions.deps) == null ? void 0 : _b.inline);
85
85
  return {
86
86
  ...serverOptions,
@@ -91,12 +91,13 @@ function parseServerOptions(serverOptions) {
91
91
  }) : true,
92
92
  external: toArray((_c = serverOptions.deps) == null ? void 0 : _c.external).map((dep) => {
93
93
  return dep.startsWith("/") && dep.endsWith("/") ? new RegExp(dep) : dep;
94
- })
94
+ }),
95
+ moduleDirectories: ((_d = serverOptions.deps) == null ? void 0 : _d.moduleDirectories) ? toArray((_e = serverOptions.deps) == null ? void 0 : _e.moduleDirectories) : void 0
95
96
  },
96
97
  transformMode: {
97
98
  ...serverOptions.transformMode,
98
- ssr: toArray((_d = serverOptions.transformMode) == null ? void 0 : _d.ssr).map((dep) => new RegExp(dep)),
99
- web: toArray((_e = serverOptions.transformMode) == null ? void 0 : _e.web).map((dep) => new RegExp(dep))
99
+ ssr: toArray((_f = serverOptions.transformMode) == null ? void 0 : _f.ssr).map((dep) => new RegExp(dep)),
100
+ web: toArray((_g = serverOptions.transformMode) == null ? void 0 : _g.web).map((dep) => new RegExp(dep))
100
101
  }
101
102
  };
102
103
  }
package/dist/client.cjs CHANGED
@@ -112,10 +112,12 @@ class ModuleCacheMap extends Map {
112
112
  return this.deleteByModuleId(this.normalizePath(fsPath));
113
113
  }
114
114
  invalidateModule(mod) {
115
+ var _a;
115
116
  delete mod.evaluated;
116
117
  delete mod.resolving;
117
118
  delete mod.promise;
118
119
  delete mod.exports;
120
+ (_a = mod.importers) == null ? void 0 : _a.clear();
119
121
  return true;
120
122
  }
121
123
  /**
@@ -251,7 +253,7 @@ ${getStack()}`), 2e3);
251
253
  const callstack = [..._callstack, moduleId];
252
254
  const mod = this.moduleCache.getByModuleId(moduleId);
253
255
  const request = async (dep) => {
254
- const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
256
+ const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
255
257
  return this.dependencyRequest(id2, depFsPath, callstack);
256
258
  };
257
259
  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-557128db.js';
2
+ export { i as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-33f0e4ff.js';
3
3
  import 'vite/types/hot';
package/dist/client.mjs CHANGED
@@ -85,10 +85,12 @@ class ModuleCacheMap extends Map {
85
85
  return this.deleteByModuleId(this.normalizePath(fsPath));
86
86
  }
87
87
  invalidateModule(mod) {
88
+ var _a;
88
89
  delete mod.evaluated;
89
90
  delete mod.resolving;
90
91
  delete mod.promise;
91
92
  delete mod.exports;
93
+ (_a = mod.importers) == null ? void 0 : _a.clear();
92
94
  return true;
93
95
  }
94
96
  /**
@@ -224,7 +226,7 @@ ${getStack()}`), 2e3);
224
226
  const callstack = [..._callstack, moduleId];
225
227
  const mod = this.moduleCache.getByModuleId(moduleId);
226
228
  const request = async (dep) => {
227
- const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
229
+ const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
228
230
  return this.dependencyRequest(id2, depFsPath, callstack);
229
231
  };
230
232
  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-557128db.js';
3
+ import { h as ViteNodeRunner, H as HotContext } from './types-33f0e4ff.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-557128db.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-33f0e4ff.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
@@ -101,30 +101,30 @@ async function _shouldExternalize(id, options) {
101
101
  id = patchWindowsImportPath(id);
102
102
  if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
103
103
  return id;
104
- if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
104
+ const moduleDirectories = (options == null ? void 0 : options.moduleDirectories) || ["/node_modules/"];
105
+ if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline))
105
106
  return false;
106
- if (matchExternalizePattern(id, options == null ? void 0 : options.external))
107
+ if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external))
107
108
  return id;
108
- const isNodeModule = id.includes("/node_modules/");
109
- const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
109
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
110
+ const guessCJS = isLibraryModule && (options == null ? void 0 : options.fallbackCJS);
110
111
  id = guessCJS ? guessCJSversion(id) || id : id;
111
- if (matchExternalizePattern(id, defaultInline))
112
+ if (matchExternalizePattern(id, moduleDirectories, defaultInline))
112
113
  return false;
113
- if (matchExternalizePattern(id, depsExternal))
114
+ if (matchExternalizePattern(id, moduleDirectories, depsExternal))
114
115
  return id;
115
- const isDist = id.includes("/dist/");
116
- if ((isNodeModule || isDist) && await mlly.isValidNodeImport(id))
116
+ if (isLibraryModule && await mlly.isValidNodeImport(id))
117
117
  return id;
118
118
  return false;
119
119
  }
120
- function matchExternalizePattern(id, patterns) {
120
+ function matchExternalizePattern(id, moduleDirectories, patterns) {
121
121
  if (patterns == null)
122
122
  return false;
123
123
  if (patterns === true)
124
124
  return true;
125
125
  for (const ex of patterns) {
126
126
  if (typeof ex === "string") {
127
- if (id.includes(`/node_modules/${ex}/`))
127
+ if (moduleDirectories.some((dir) => id.includes(pathe.join(dir, id))))
128
128
  return true;
129
129
  } else {
130
130
  if (ex.test(id))
@@ -221,7 +221,7 @@ class ViteNodeServer {
221
221
  this.existingOptimizedDeps = /* @__PURE__ */ new Set();
222
222
  this.fetchCache = /* @__PURE__ */ new Map();
223
223
  this.externalizeCache = /* @__PURE__ */ new Map();
224
- var _a, _b;
224
+ var _a, _b, _c;
225
225
  const ssrOptions = server.config.ssr;
226
226
  options.deps ?? (options.deps = {});
227
227
  options.deps.cacheDir = pathe.relative(server.config.root, server.config.cacheDir);
@@ -241,6 +241,11 @@ class ViteNodeServer {
241
241
  }
242
242
  if (options.debug)
243
243
  this.debugger = new Debugger(server.config.root, options.debug);
244
+ (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
245
+ const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
246
+ const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
247
+ if (customModuleDirectories)
248
+ options.deps.moduleDirectories.push(...customModuleDirectories);
244
249
  }
245
250
  shouldExternalize(id) {
246
251
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
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-557128db.js';
3
+ import { g as DebuggerOptions, D as DepsHandlingOptions, f as ViteNodeServerOptions, F as FetchResult, e as ViteNodeResolveId } from './types-33f0e4ff.js';
4
4
  import 'vite/types/hot';
5
5
 
6
6
  declare class Debugger {
package/dist/server.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { performance } from 'node:perf_hooks';
2
2
  import { existsSync, promises } from 'node:fs';
3
- import { resolve, join, relative } from 'pathe';
3
+ import { join, resolve, relative } from 'pathe';
4
4
  import createDebug from 'debug';
5
5
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
6
6
  import { slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
@@ -92,30 +92,30 @@ async function _shouldExternalize(id, options) {
92
92
  id = patchWindowsImportPath(id);
93
93
  if ((options == null ? void 0 : options.cacheDir) && id.includes(options.cacheDir))
94
94
  return id;
95
- if (matchExternalizePattern(id, options == null ? void 0 : options.inline))
95
+ const moduleDirectories = (options == null ? void 0 : options.moduleDirectories) || ["/node_modules/"];
96
+ if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.inline))
96
97
  return false;
97
- if (matchExternalizePattern(id, options == null ? void 0 : options.external))
98
+ if (matchExternalizePattern(id, moduleDirectories, options == null ? void 0 : options.external))
98
99
  return id;
99
- const isNodeModule = id.includes("/node_modules/");
100
- const guessCJS = isNodeModule && (options == null ? void 0 : options.fallbackCJS);
100
+ const isLibraryModule = moduleDirectories.some((dir) => id.includes(dir));
101
+ const guessCJS = isLibraryModule && (options == null ? void 0 : options.fallbackCJS);
101
102
  id = guessCJS ? guessCJSversion(id) || id : id;
102
- if (matchExternalizePattern(id, defaultInline))
103
+ if (matchExternalizePattern(id, moduleDirectories, defaultInline))
103
104
  return false;
104
- if (matchExternalizePattern(id, depsExternal))
105
+ if (matchExternalizePattern(id, moduleDirectories, depsExternal))
105
106
  return id;
106
- const isDist = id.includes("/dist/");
107
- if ((isNodeModule || isDist) && await isValidNodeImport(id))
107
+ if (isLibraryModule && await isValidNodeImport(id))
108
108
  return id;
109
109
  return false;
110
110
  }
111
- function matchExternalizePattern(id, patterns) {
111
+ function matchExternalizePattern(id, moduleDirectories, patterns) {
112
112
  if (patterns == null)
113
113
  return false;
114
114
  if (patterns === true)
115
115
  return true;
116
116
  for (const ex of patterns) {
117
117
  if (typeof ex === "string") {
118
- if (id.includes(`/node_modules/${ex}/`))
118
+ if (moduleDirectories.some((dir) => id.includes(join(dir, id))))
119
119
  return true;
120
120
  } else {
121
121
  if (ex.test(id))
@@ -212,7 +212,7 @@ class ViteNodeServer {
212
212
  this.existingOptimizedDeps = /* @__PURE__ */ new Set();
213
213
  this.fetchCache = /* @__PURE__ */ new Map();
214
214
  this.externalizeCache = /* @__PURE__ */ new Map();
215
- var _a, _b;
215
+ var _a, _b, _c;
216
216
  const ssrOptions = server.config.ssr;
217
217
  options.deps ?? (options.deps = {});
218
218
  options.deps.cacheDir = relative(server.config.root, server.config.cacheDir);
@@ -232,6 +232,11 @@ class ViteNodeServer {
232
232
  }
233
233
  if (options.debug)
234
234
  this.debugger = new Debugger(server.config.root, options.debug);
235
+ (_c = options.deps).moduleDirectories ?? (_c.moduleDirectories = []);
236
+ const envValue = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES || process.env.npm_config_VITE_NODE_DEPS_MODULE_DIRECTORIES;
237
+ const customModuleDirectories = envValue == null ? void 0 : envValue.split(",");
238
+ if (customModuleDirectories)
239
+ options.deps.moduleDirectories.push(...customModuleDirectories);
235
240
  }
236
241
  shouldExternalize(id) {
237
242
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
@@ -880,7 +880,7 @@ function withInlineSourcemap(result, options) {
880
880
  }
881
881
  return source;
882
882
  });
883
- const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, "g");
883
+ const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
884
884
  while (OTHER_SOURCE_MAP_REGEXP.test(code))
885
885
  code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
886
886
  const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
@@ -871,7 +871,7 @@ function withInlineSourcemap(result, options) {
871
871
  }
872
872
  return source;
873
873
  });
874
- const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,(.+)`, "g");
874
+ const OTHER_SOURCE_MAP_REGEXP = new RegExp(`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`, "gm");
875
875
  while (OTHER_SOURCE_MAP_REGEXP.test(code))
876
876
  code = code.replace(OTHER_SOURCE_MAP_REGEXP, "");
877
877
  const sourceMap = Buffer.from(JSON.stringify(map), "utf-8").toString("base64");
@@ -67,6 +67,15 @@ type Awaitable<T> = T | PromiseLike<T>;
67
67
  interface DepsHandlingOptions {
68
68
  external?: (string | RegExp)[];
69
69
  inline?: (string | RegExp)[] | true;
70
+ /**
71
+ * A list of directories that are considered to hold Node.js modules
72
+ * Have to include "/" at the start and end of the path
73
+ *
74
+ * Vite-Node checks the whole absolute path of the import, so make sure you don't include
75
+ * unwanted files accidentally
76
+ * @default ['/node_modules/']
77
+ */
78
+ moduleDirectories?: string[];
70
79
  cacheDir?: string;
71
80
  /**
72
81
  * Try to guess the CJS version of a package when it's invalid ESM
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-557128db.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';
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-557128db.js';
1
+ import { N as Nullable, A as Arrayable } from './types-33f0e4ff.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.1",
3
+ "version": "0.31.3",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",