vite-node 0.31.1 → 0.31.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
@@ -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.2";
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.2";
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
@@ -195,7 +195,7 @@ ${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
195
195
  if (callstack.includes(fsPath) || callstack.some((c) => {
196
196
  var _a;
197
197
  return (_a = this.moduleCache.get(c).importers) == null ? void 0 : _a.has(fsPath);
198
- })) {
198
+ }) || mod.importers.has(importee)) {
199
199
  if (mod.exports)
200
200
  return mod.exports;
201
201
  }
@@ -251,7 +251,7 @@ ${getStack()}`), 2e3);
251
251
  const callstack = [..._callstack, moduleId];
252
252
  const mod = this.moduleCache.getByModuleId(moduleId);
253
253
  const request = async (dep) => {
254
- const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
254
+ const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
255
255
  return this.dependencyRequest(id2, depFsPath, callstack);
256
256
  };
257
257
  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
@@ -168,7 +168,7 @@ ${[...callstack, fsPath].reverse().map((p) => ` - ${p}`).join("\n")}`;
168
168
  if (callstack.includes(fsPath) || callstack.some((c) => {
169
169
  var _a;
170
170
  return (_a = this.moduleCache.get(c).importers) == null ? void 0 : _a.has(fsPath);
171
- })) {
171
+ }) || mod.importers.has(importee)) {
172
172
  if (mod.exports)
173
173
  return mod.exports;
174
174
  }
@@ -224,7 +224,7 @@ ${getStack()}`), 2e3);
224
224
  const callstack = [..._callstack, moduleId];
225
225
  const mod = this.moduleCache.getByModuleId(moduleId);
226
226
  const request = async (dep) => {
227
- const [id2, depFsPath] = await this.resolveUrl(dep, fsPath);
227
+ const [id2, depFsPath] = await this.resolveUrl(`${dep}`, fsPath);
228
228
  return this.dependencyRequest(id2, depFsPath, callstack);
229
229
  };
230
230
  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, _d;
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,10 @@ 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 customModuleDirectories = (_d = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES) == null ? void 0 : _d.split(",");
246
+ if (customModuleDirectories)
247
+ options.deps.moduleDirectories.push(...customModuleDirectories);
244
248
  }
245
249
  shouldExternalize(id) {
246
250
  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, _d;
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,10 @@ 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 customModuleDirectories = (_d = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES) == null ? void 0 : _d.split(",");
237
+ if (customModuleDirectories)
238
+ options.deps.moduleDirectories.push(...customModuleDirectories);
235
239
  }
236
240
  shouldExternalize(id) {
237
241
  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.2",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",