vite-node 0.25.5 → 0.25.7

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.
@@ -193,6 +193,9 @@ function createHotContext(runner, emitter, files, ownerPath) {
193
193
  get data() {
194
194
  return maps.dataMap.get(ownerPath);
195
195
  },
196
+ acceptExports(_, callback) {
197
+ acceptDeps([ownerPath], callback && (([mod2]) => callback(mod2)));
198
+ },
196
199
  accept(deps, callback) {
197
200
  if (typeof deps === "function" || !deps) {
198
201
  acceptDeps([ownerPath], ([mod2]) => deps && deps(mod2));
@@ -211,7 +214,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
211
214
  maps.pruneMap.set(ownerPath, cb);
212
215
  },
213
216
  invalidate() {
214
- notifyListeners(runner, "vite:invalidate", { path: ownerPath });
217
+ notifyListeners(runner, "vite:invalidate", { path: ownerPath, message: void 0 });
215
218
  return reload(runner, files);
216
219
  },
217
220
  on(event, cb) {
@@ -187,6 +187,9 @@ function createHotContext(runner, emitter, files, ownerPath) {
187
187
  get data() {
188
188
  return maps.dataMap.get(ownerPath);
189
189
  },
190
+ acceptExports(_, callback) {
191
+ acceptDeps([ownerPath], callback && (([mod2]) => callback(mod2)));
192
+ },
190
193
  accept(deps, callback) {
191
194
  if (typeof deps === "function" || !deps) {
192
195
  acceptDeps([ownerPath], ([mod2]) => deps && deps(mod2));
@@ -205,7 +208,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
205
208
  maps.pruneMap.set(ownerPath, cb);
206
209
  },
207
210
  invalidate() {
208
- notifyListeners(runner, "vite:invalidate", { path: ownerPath });
211
+ notifyListeners(runner, "vite:invalidate", { path: ownerPath, message: void 0 });
209
212
  return reload(runner, files);
210
213
  },
211
214
  on(event, cb) {
package/dist/cli.cjs CHANGED
@@ -632,7 +632,7 @@ class CAC extends events.EventEmitter {
632
632
 
633
633
  const cac = (name = "") => new CAC(name);
634
634
 
635
- var version = "0.25.5";
635
+ var version = "0.25.7";
636
636
 
637
637
  const cli = cac("vite-node");
638
638
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
package/dist/cli.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { e as ViteNodeServerOptions } from './types-de49c638.js';
1
+ import { e as ViteNodeServerOptions } from './types-c9a1a6b2.js';
2
2
 
3
3
  interface CliOptions {
4
4
  root?: string;
package/dist/cli.mjs CHANGED
@@ -630,7 +630,7 @@ class CAC extends EventEmitter {
630
630
 
631
631
  const cac = (name = "") => new CAC(name);
632
632
 
633
- var version = "0.25.5";
633
+ var version = "0.25.7";
634
634
 
635
635
  const cli = cac("vite-node");
636
636
  cli.version(version).option("-r, --root <path>", "Use specified root directory").option("-c, --config <path>", "Use specified config file").option("-w, --watch", 'Restart on file changes, similar to "nodemon"').option("--options <options>", "Use specified Vite server options").help();
package/dist/client.cjs CHANGED
@@ -177,9 +177,9 @@ class ViteNodeRunner {
177
177
  async directRequest(id, fsPath, _callstack) {
178
178
  const callstack = [..._callstack, fsPath];
179
179
  let mod = this.moduleCache.get(fsPath);
180
- const request = async (dep) => {
180
+ const request = async (dep2) => {
181
181
  var _a;
182
- const depFsPath = utils.toFilePath(utils.normalizeRequestId(dep, this.options.base), this.root);
182
+ const depFsPath = utils.toFilePath(utils.normalizeRequestId(dep2, this.options.base), this.root);
183
183
  const getStack = () => {
184
184
  return `stack:
185
185
  ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
@@ -195,37 +195,40 @@ ${getStack()}`), 2e3);
195
195
  return depExports;
196
196
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
197
197
  }
198
- return await this.cachedRequest(dep, callstack);
198
+ return await this.cachedRequest(dep2, callstack);
199
199
  } finally {
200
200
  if (debugTimer)
201
201
  clearTimeout(debugTimer);
202
202
  }
203
203
  };
204
204
  Object.defineProperty(request, "callstack", { get: () => callstack });
205
- const resolveId = async (dep, callstackPosition = 1) => {
206
- if (this.options.resolveId && this.shouldResolveId(dep)) {
205
+ const resolveId = async (dep2, callstackPosition = 1) => {
206
+ if (this.options.resolveId && this.shouldResolveId(dep2)) {
207
207
  let importer = callstack[callstack.length - callstackPosition];
208
+ if (importer && !dep2.startsWith("."))
209
+ importer = void 0;
208
210
  if (importer && importer.startsWith("mock:"))
209
211
  importer = importer.slice(5);
210
- const { id: id2 } = await this.options.resolveId(dep, importer) || {};
211
- dep = id2 && pathe.isAbsolute(id2) ? utils.mergeSlashes(`/@fs/${id2}`) : id2 || dep;
212
+ const resolved = await this.options.resolveId(utils.normalizeRequestId(dep2), importer);
213
+ return [dep2, resolved == null ? void 0 : resolved.id];
212
214
  }
213
- return dep;
215
+ return [dep2, void 0];
214
216
  };
217
+ const [dep, resolvedId] = await resolveId(id, 2);
215
218
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
216
219
  if (id in requestStubs)
217
220
  return requestStubs[id];
218
- let { code: transformed, externalize, file } = await this.options.fetchModule(id);
219
- if (file && !fsPath.includes("?") && fsPath !== file) {
220
- if (this.moduleCache.has(file)) {
221
- mod = this.moduleCache.get(file);
221
+ let { code: transformed, externalize } = await this.options.fetchModule(resolvedId || dep);
222
+ if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
223
+ if (this.moduleCache.has(resolvedId)) {
224
+ mod = this.moduleCache.get(resolvedId);
222
225
  this.moduleCache.set(fsPath, mod);
223
226
  if (mod.promise)
224
227
  return mod.promise;
225
228
  if (mod.exports)
226
229
  return mod.exports;
227
230
  } else {
228
- this.moduleCache.set(file, mod);
231
+ this.moduleCache.set(resolvedId, mod);
229
232
  }
230
233
  }
231
234
  if (externalize) {
@@ -236,7 +239,8 @@ ${getStack()}`), 2e3);
236
239
  }
237
240
  if (transformed == null)
238
241
  throw new Error(`[vite-node] Failed to load ${id}`);
239
- const url$1 = url.pathToFileURL(file || fsPath).href;
242
+ const file = utils.cleanUrl(resolvedId || fsPath);
243
+ const url$1 = url.pathToFileURL(file).href;
240
244
  const meta = { url: url$1 };
241
245
  const exports = /* @__PURE__ */ Object.create(null);
242
246
  Object.defineProperty(exports, Symbol.toStringTag, {
package/dist/client.d.ts CHANGED
@@ -1 +1 @@
1
- export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-de49c638.js';
1
+ export { j as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, h as ViteNodeRunner } from './types-c9a1a6b2.js';
package/dist/client.mjs CHANGED
@@ -4,7 +4,7 @@ import vm from 'vm';
4
4
  import { resolve, dirname, isAbsolute, extname } from 'pathe';
5
5
  import { isNodeBuiltin } from 'mlly';
6
6
  import createDebug from 'debug';
7
- import { normalizeModuleId, slash, normalizeRequestId, toFilePath, isPrimitive, mergeSlashes } from './utils.mjs';
7
+ import { normalizeModuleId, slash, normalizeRequestId, toFilePath, cleanUrl, isPrimitive } from './utils.mjs';
8
8
  import { extractSourceMap } from './source-map.mjs';
9
9
  import 'fs';
10
10
  import 'source-map-support';
@@ -150,9 +150,9 @@ class ViteNodeRunner {
150
150
  async directRequest(id, fsPath, _callstack) {
151
151
  const callstack = [..._callstack, fsPath];
152
152
  let mod = this.moduleCache.get(fsPath);
153
- const request = async (dep) => {
153
+ const request = async (dep2) => {
154
154
  var _a;
155
- const depFsPath = toFilePath(normalizeRequestId(dep, this.options.base), this.root);
155
+ const depFsPath = toFilePath(normalizeRequestId(dep2, this.options.base), this.root);
156
156
  const getStack = () => {
157
157
  return `stack:
158
158
  ${[...callstack, depFsPath].reverse().map((p) => `- ${p}`).join("\n")}`;
@@ -168,37 +168,40 @@ ${getStack()}`), 2e3);
168
168
  return depExports;
169
169
  throw new Error(`[vite-node] Failed to resolve circular dependency, ${getStack()}`);
170
170
  }
171
- return await this.cachedRequest(dep, callstack);
171
+ return await this.cachedRequest(dep2, callstack);
172
172
  } finally {
173
173
  if (debugTimer)
174
174
  clearTimeout(debugTimer);
175
175
  }
176
176
  };
177
177
  Object.defineProperty(request, "callstack", { get: () => callstack });
178
- const resolveId = async (dep, callstackPosition = 1) => {
179
- if (this.options.resolveId && this.shouldResolveId(dep)) {
178
+ const resolveId = async (dep2, callstackPosition = 1) => {
179
+ if (this.options.resolveId && this.shouldResolveId(dep2)) {
180
180
  let importer = callstack[callstack.length - callstackPosition];
181
+ if (importer && !dep2.startsWith("."))
182
+ importer = void 0;
181
183
  if (importer && importer.startsWith("mock:"))
182
184
  importer = importer.slice(5);
183
- const { id: id2 } = await this.options.resolveId(dep, importer) || {};
184
- dep = id2 && isAbsolute(id2) ? mergeSlashes(`/@fs/${id2}`) : id2 || dep;
185
+ const resolved = await this.options.resolveId(normalizeRequestId(dep2), importer);
186
+ return [dep2, resolved == null ? void 0 : resolved.id];
185
187
  }
186
- return dep;
188
+ return [dep2, void 0];
187
189
  };
190
+ const [dep, resolvedId] = await resolveId(id, 2);
188
191
  const requestStubs = this.options.requestStubs || DEFAULT_REQUEST_STUBS;
189
192
  if (id in requestStubs)
190
193
  return requestStubs[id];
191
- let { code: transformed, externalize, file } = await this.options.fetchModule(id);
192
- if (file && !fsPath.includes("?") && fsPath !== file) {
193
- if (this.moduleCache.has(file)) {
194
- mod = this.moduleCache.get(file);
194
+ let { code: transformed, externalize } = await this.options.fetchModule(resolvedId || dep);
195
+ if (resolvedId && !fsPath.includes("?") && fsPath !== resolvedId) {
196
+ if (this.moduleCache.has(resolvedId)) {
197
+ mod = this.moduleCache.get(resolvedId);
195
198
  this.moduleCache.set(fsPath, mod);
196
199
  if (mod.promise)
197
200
  return mod.promise;
198
201
  if (mod.exports)
199
202
  return mod.exports;
200
203
  } else {
201
- this.moduleCache.set(file, mod);
204
+ this.moduleCache.set(resolvedId, mod);
202
205
  }
203
206
  }
204
207
  if (externalize) {
@@ -209,7 +212,8 @@ ${getStack()}`), 2e3);
209
212
  }
210
213
  if (transformed == null)
211
214
  throw new Error(`[vite-node] Failed to load ${id}`);
212
- const url = pathToFileURL(file || fsPath).href;
215
+ const file = cleanUrl(resolvedId || fsPath);
216
+ const url = pathToFileURL(file).href;
213
217
  const meta = { url };
214
218
  const exports = /* @__PURE__ */ Object.create(null);
215
219
  Object.defineProperty(exports, Symbol.toStringTag, {
package/dist/hmr.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EventEmitter } from 'events';
2
2
  import { HMRPayload, Plugin } from 'vite';
3
- import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-de49c638.js';
3
+ import { g as CustomEventMap, h as ViteNodeRunner, i as HMRPayload$1, H as HotContext } from './types-c9a1a6b2.js';
4
4
 
5
5
  declare type EventType = string | symbol;
6
6
  declare type Handler<T = unknown> = (event: T) => void;
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-de49c638.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-c9a1a6b2.js';
package/dist/server.cjs CHANGED
@@ -263,8 +263,6 @@ class ViteNodeServer {
263
263
  const module = this.server.moduleGraph.getModuleById(id);
264
264
  const timestamp = module ? module.lastHMRTimestamp : null;
265
265
  const cache = this.fetchCache.get(filePath);
266
- if (cache == null ? void 0 : cache.result.id)
267
- id = cache.result.id;
268
266
  if (timestamp !== null && cache && cache.timestamp >= timestamp)
269
267
  return cache.result;
270
268
  const time = Date.now();
@@ -274,16 +272,10 @@ class ViteNodeServer {
274
272
  result = { externalize };
275
273
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
276
274
  } else {
277
- let file = module == null ? void 0 : module.file;
278
- if (!file) {
279
- const [, resolvedId] = await this.server.moduleGraph.resolveUrl(id, true);
280
- id = resolvedId;
281
- file = utils.cleanUrl(resolvedId);
282
- }
283
275
  const start = perf_hooks.performance.now();
284
276
  const r = await this._transformRequest(id);
285
277
  duration = perf_hooks.performance.now() - start;
286
- result = { file, id, code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
278
+ result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
287
279
  }
288
280
  this.fetchCache.set(filePath, {
289
281
  duration,
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { TransformResult, ViteDevServer } from 'vite';
2
- import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-de49c638.js';
2
+ import { f as DebuggerOptions, D as DepsHandlingOptions, e as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId, R as RawSourceMap } from './types-c9a1a6b2.js';
3
3
 
4
4
  declare class Debugger {
5
5
  options: DebuggerOptions;
package/dist/server.mjs CHANGED
@@ -3,7 +3,7 @@ import { resolve, join } from 'pathe';
3
3
  import createDebug from 'debug';
4
4
  import { existsSync, promises } from 'fs';
5
5
  import { isNodeBuiltin, isValidNodeImport } from 'mlly';
6
- import { slash, toArray, normalizeModuleId, toFilePath, cleanUrl } from './utils.mjs';
6
+ import { slash, toArray, normalizeModuleId, toFilePath } from './utils.mjs';
7
7
  import { p as picocolors } from './chunk-picocolors.mjs';
8
8
  import { withInlineSourcemap } from './source-map.mjs';
9
9
  import 'url';
@@ -255,8 +255,6 @@ class ViteNodeServer {
255
255
  const module = this.server.moduleGraph.getModuleById(id);
256
256
  const timestamp = module ? module.lastHMRTimestamp : null;
257
257
  const cache = this.fetchCache.get(filePath);
258
- if (cache == null ? void 0 : cache.result.id)
259
- id = cache.result.id;
260
258
  if (timestamp !== null && cache && cache.timestamp >= timestamp)
261
259
  return cache.result;
262
260
  const time = Date.now();
@@ -266,16 +264,10 @@ class ViteNodeServer {
266
264
  result = { externalize };
267
265
  (_a = this.debugger) == null ? void 0 : _a.recordExternalize(id, externalize);
268
266
  } else {
269
- let file = module == null ? void 0 : module.file;
270
- if (!file) {
271
- const [, resolvedId] = await this.server.moduleGraph.resolveUrl(id, true);
272
- id = resolvedId;
273
- file = cleanUrl(resolvedId);
274
- }
275
267
  const start = performance.now();
276
268
  const r = await this._transformRequest(id);
277
269
  duration = performance.now() - start;
278
- result = { file, id, code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
270
+ result = { code: r == null ? void 0 : r.code, map: r == null ? void 0 : r.map };
279
271
  }
280
272
  this.fetchCache.set(filePath, {
281
273
  duration,
@@ -1,5 +1,5 @@
1
1
  import { TransformResult } from 'vite';
2
- import { R as RawSourceMap } from './types-de49c638.js';
2
+ import { R as RawSourceMap } from './types-c9a1a6b2.js';
3
3
 
4
4
  interface InstallSourceMapSupportOptions {
5
5
  getSourceMap: (source: string) => RawSourceMap | null | undefined;
@@ -71,6 +71,7 @@ interface CustomEventMap {
71
71
 
72
72
  interface InvalidatePayload {
73
73
  path: string
74
+ message: string | undefined
74
75
  }
75
76
 
76
77
  type InferCustomEventPayload<T extends string> =
@@ -88,22 +89,21 @@ interface ViteHotContext {
88
89
  accept(dep: string, cb: (mod: ModuleNamespace | undefined) => void): void
89
90
  accept(
90
91
  deps: readonly string[],
91
- cb: (mods: Array<ModuleNamespace | undefined>) => void
92
+ cb: (mods: Array<ModuleNamespace | undefined>) => void,
92
93
  ): void
93
94
 
94
- acceptExports(exportNames: string | readonly string[]): void
95
95
  acceptExports(
96
96
  exportNames: string | readonly string[],
97
- cb: (mod: ModuleNamespace | undefined) => void
97
+ cb?: (mod: ModuleNamespace | undefined) => void,
98
98
  ): void
99
99
 
100
100
  dispose(cb: (data: any) => void): void
101
- decline(): void
102
- invalidate(): void
101
+ prune(cb: (data: any) => void): void
102
+ invalidate(message?: string): void
103
103
 
104
104
  on<T extends string>(
105
105
  event: T,
106
- cb: (payload: InferCustomEventPayload<T>) => void
106
+ cb: (payload: InferCustomEventPayload<T>) => void,
107
107
  ): void
108
108
  send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
109
109
  }
@@ -201,8 +201,6 @@ interface FetchResult {
201
201
  code?: string;
202
202
  externalize?: string;
203
203
  map?: RawSourceMap;
204
- id?: string;
205
- file?: string;
206
204
  }
207
205
  declare type HotContext = Omit<ViteHotContext, 'acceptDeps' | 'decline'>;
208
206
  declare type FetchFunction = (id: string) => Promise<FetchResult>;
package/dist/types.d.ts CHANGED
@@ -1 +1 @@
1
- export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-de49c638.js';
1
+ export { A as Arrayable, C as CreateHotContextFunction, f as DebuggerOptions, D as DepsHandlingOptions, a as FetchFunction, F as FetchResult, H as HotContext, c as ModuleCache, M as ModuleCacheMap, N as Nullable, R as RawSourceMap, b as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, V as ViteNodeRunnerOptions, e as ViteNodeServerOptions } from './types-c9a1a6b2.js';
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './types-de49c638.js';
1
+ import { N as Nullable, A as Arrayable } from './types-c9a1a6b2.js';
2
2
 
3
3
  declare const isWindows: boolean;
4
4
  declare function slash(str: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.25.5",
3
+ "version": "0.25.7",
4
4
  "description": "Vite as Node.js runtime",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -74,7 +74,7 @@
74
74
  "pathe": "^0.2.0",
75
75
  "source-map": "^0.6.1",
76
76
  "source-map-support": "^0.5.21",
77
- "vite": "^3.0.0"
77
+ "vite": "^3.0.0 || ^4.0.0"
78
78
  },
79
79
  "devDependencies": {
80
80
  "@types/debug": "^4.1.7",