vite-node 3.2.0-beta.3 → 3.2.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.
@@ -36,15 +36,15 @@ function viteNodeHmrPlugin() {
36
36
  }
37
37
 
38
38
  const debugHmr = createDebug("vite-node:hmr");
39
- const cache = new WeakMap();
39
+ const cache = /* @__PURE__ */ new WeakMap();
40
40
  function getCache(runner) {
41
41
  if (!cache.has(runner)) cache.set(runner, {
42
- hotModulesMap: new Map(),
43
- dataMap: new Map(),
44
- disposeMap: new Map(),
45
- pruneMap: new Map(),
46
- customListenersMap: new Map(),
47
- ctxToListenersMap: new Map(),
42
+ hotModulesMap: /* @__PURE__ */ new Map(),
43
+ dataMap: /* @__PURE__ */ new Map(),
44
+ disposeMap: /* @__PURE__ */ new Map(),
45
+ pruneMap: /* @__PURE__ */ new Map(),
46
+ customListenersMap: /* @__PURE__ */ new Map(),
47
+ ctxToListenersMap: /* @__PURE__ */ new Map(),
48
48
  messageBuffer: [],
49
49
  isFirstUpdate: false,
50
50
  pending: false,
@@ -161,7 +161,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
161
161
  // clear its stale callbacks
162
162
  const mod = maps.hotModulesMap.get(ownerPath);
163
163
  if (mod) mod.callbacks = [];
164
- const newListeners = new Map();
164
+ const newListeners = /* @__PURE__ */ new Map();
165
165
  maps.ctxToListenersMap.set(ownerPath, newListeners);
166
166
  function acceptDeps(deps, callback = () => {}) {
167
167
  const mod = maps.hotModulesMap.get(ownerPath) || {
@@ -200,7 +200,8 @@ function createHotContext(runner, emitter, files, ownerPath) {
200
200
  invalidate() {
201
201
  notifyListeners(runner, "vite:invalidate", {
202
202
  path: ownerPath,
203
- message: void 0
203
+ message: void 0,
204
+ firstInvalidatedBy: ownerPath
204
205
  });
205
206
  return reload(runner, files);
206
207
  },
@@ -34,15 +34,15 @@ function viteNodeHmrPlugin() {
34
34
  }
35
35
 
36
36
  const debugHmr = createDebug("vite-node:hmr");
37
- const cache = new WeakMap();
37
+ const cache = /* @__PURE__ */ new WeakMap();
38
38
  function getCache(runner) {
39
39
  if (!cache.has(runner)) cache.set(runner, {
40
- hotModulesMap: new Map(),
41
- dataMap: new Map(),
42
- disposeMap: new Map(),
43
- pruneMap: new Map(),
44
- customListenersMap: new Map(),
45
- ctxToListenersMap: new Map(),
40
+ hotModulesMap: /* @__PURE__ */ new Map(),
41
+ dataMap: /* @__PURE__ */ new Map(),
42
+ disposeMap: /* @__PURE__ */ new Map(),
43
+ pruneMap: /* @__PURE__ */ new Map(),
44
+ customListenersMap: /* @__PURE__ */ new Map(),
45
+ ctxToListenersMap: /* @__PURE__ */ new Map(),
46
46
  messageBuffer: [],
47
47
  isFirstUpdate: false,
48
48
  pending: false,
@@ -159,7 +159,7 @@ function createHotContext(runner, emitter, files, ownerPath) {
159
159
  // clear its stale callbacks
160
160
  const mod = maps.hotModulesMap.get(ownerPath);
161
161
  if (mod) mod.callbacks = [];
162
- const newListeners = new Map();
162
+ const newListeners = /* @__PURE__ */ new Map();
163
163
  maps.ctxToListenersMap.set(ownerPath, newListeners);
164
164
  function acceptDeps(deps, callback = () => {}) {
165
165
  const mod = maps.hotModulesMap.get(ownerPath) || {
@@ -198,7 +198,8 @@ function createHotContext(runner, emitter, files, ownerPath) {
198
198
  invalidate() {
199
199
  notifyListeners(runner, "vite:invalidate", {
200
200
  path: ownerPath,
201
- message: void 0
201
+ message: void 0,
202
+ firstInvalidatedBy: ownerPath
202
203
  });
203
204
  return reload(runner, files);
204
205
  },
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.2.0-beta.3";
24
+ var version = "3.2.0";
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-CWZbpOcv.js';
1
+ import { V as ViteNodeServerOptions } from './index.d-DGmxD2U7.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  interface CliOptions {
package/dist/cli.mjs CHANGED
@@ -3,23 +3,23 @@ import cac from 'cac';
3
3
  import { s } from './chunk-browser.mjs';
4
4
  import { createServer, version as version$1, loadEnv } from 'vite';
5
5
  import { ViteNodeRunner } from './client.mjs';
6
- import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
7
6
  import { ViteNodeServer } from './server.mjs';
8
7
  import { installSourcemapsSupport } from './source-map.mjs';
9
8
  import { toArray } from './utils.mjs';
9
+ import { v as viteNodeHmrPlugin, a as createHotContext, h as handleMessage } from './chunk-hmr.mjs';
10
10
  import 'node:module';
11
11
  import 'node:url';
12
12
  import 'node:vm';
13
13
  import 'debug';
14
14
  import 'pathe';
15
15
  import 'node:fs';
16
- import 'node:events';
17
16
  import 'node:assert';
18
17
  import 'node:perf_hooks';
19
18
  import 'es-module-lexer';
20
19
  import './constants.mjs';
20
+ import 'node:events';
21
21
 
22
- var version = "3.2.0-beta.3";
22
+ var version = "3.2.0";
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
@@ -57,8 +57,8 @@ class ModuleCacheMap extends Map {
57
57
  if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
58
58
  const mod = super.get(modulePath);
59
59
  if (!mod.imports) Object.assign(mod, {
60
- imports: new Set(),
61
- importers: new Set()
60
+ imports: /* @__PURE__ */ new Set(),
61
+ importers: /* @__PURE__ */ new Set()
62
62
  });
63
63
  return mod;
64
64
  }
@@ -84,7 +84,7 @@ class ModuleCacheMap extends Map {
84
84
  /**
85
85
  * Invalidate modules that dependent on the given modules, up to the main entry
86
86
  */
87
- invalidateDepTree(ids, invalidated = new Set()) {
87
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
88
88
  for (const _id of ids) {
89
89
  const id = this.normalizePath(_id);
90
90
  if (invalidated.has(id)) continue;
@@ -98,7 +98,7 @@ class ModuleCacheMap extends Map {
98
98
  /**
99
99
  * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
100
100
  */
101
- invalidateSubDepTree(ids, invalidated = new Set()) {
101
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
102
102
  for (const _id of ids) {
103
103
  const id = this.normalizePath(_id);
104
104
  if (invalidated.has(id)) continue;
@@ -134,6 +134,25 @@ class ViteNodeRunner {
134
134
  * Keys of the map are filepaths, or plain package names
135
135
  */
136
136
  moduleCache;
137
+ /**
138
+ * Tracks the stack of modules being executed for the purpose of calculating import self-time.
139
+ *
140
+ * Note that while in most cases, imports are a linear stack of modules,
141
+ * this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
142
+ *
143
+ * ```ts
144
+ * await Promise.all([
145
+ * import('./module1'),
146
+ * import('./module2'),
147
+ * ]);
148
+ * ```
149
+ *
150
+ * In this case, the self time will be reported incorrectly for one of the modules (could go negative).
151
+ * As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
152
+ */
153
+ executionStack = [];
154
+ // `performance` can be mocked, so make sure we're using the original function
155
+ performanceNow = performance.now.bind(performance);
137
156
  constructor(options) {
138
157
  this.options = options;
139
158
  this.root = options.root ?? process.cwd();
@@ -366,7 +385,6 @@ class ViteNodeRunner {
366
385
  };
367
386
  }
368
387
  async runModule(context, transformed) {
369
- var _this$options$moduleE;
370
388
  // add 'use strict' since ESM enables it by default
371
389
  const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
372
390
  const code = `${codeDefinition}${transformed}\n}}`;
@@ -375,9 +393,38 @@ class ViteNodeRunner {
375
393
  lineOffset: 0,
376
394
  columnOffset: -codeDefinition.length
377
395
  };
378
- (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, { startOffset: codeDefinition.length });
379
- const fn = vm.runInThisContext(code, options);
380
- await fn(...Object.values(context));
396
+ const finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
397
+ try {
398
+ const fn = vm.runInThisContext(code, options);
399
+ await fn(...Object.values(context));
400
+ } finally {
401
+ var _this$options$moduleE;
402
+ (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
403
+ }
404
+ }
405
+ /**
406
+ * Starts calculating the module execution info such as the total duration and self time spent on executing the module.
407
+ * Returns a function to call once the module has finished executing.
408
+ */
409
+ startCalculateModuleExecutionInfo(filename, startOffset) {
410
+ const startTime = this.performanceNow();
411
+ this.executionStack.push({
412
+ filename,
413
+ startTime,
414
+ subImportTime: 0
415
+ });
416
+ return () => {
417
+ const duration = this.performanceNow() - startTime;
418
+ const currentExecution = this.executionStack.pop();
419
+ if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
420
+ const selfTime = duration - currentExecution.subImportTime;
421
+ if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
422
+ return {
423
+ startOffset,
424
+ duration,
425
+ selfTime
426
+ };
427
+ };
381
428
  }
382
429
  prepareContext(context) {
383
430
  return context;
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-CWZbpOcv.js';
2
+ export { e as DEFAULT_REQUEST_STUBS, M as ModuleCacheMap, f as ModuleExecutionInfo, g as ModuleExecutionInfoEntry, a as ViteNodeRunner } from './index.d-DGmxD2U7.js';
package/dist/client.mjs CHANGED
@@ -55,8 +55,8 @@ class ModuleCacheMap extends Map {
55
55
  if (!super.has(modulePath)) this.setByModuleId(modulePath, {});
56
56
  const mod = super.get(modulePath);
57
57
  if (!mod.imports) Object.assign(mod, {
58
- imports: new Set(),
59
- importers: new Set()
58
+ imports: /* @__PURE__ */ new Set(),
59
+ importers: /* @__PURE__ */ new Set()
60
60
  });
61
61
  return mod;
62
62
  }
@@ -82,7 +82,7 @@ class ModuleCacheMap extends Map {
82
82
  /**
83
83
  * Invalidate modules that dependent on the given modules, up to the main entry
84
84
  */
85
- invalidateDepTree(ids, invalidated = new Set()) {
85
+ invalidateDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
86
86
  for (const _id of ids) {
87
87
  const id = this.normalizePath(_id);
88
88
  if (invalidated.has(id)) continue;
@@ -96,7 +96,7 @@ class ModuleCacheMap extends Map {
96
96
  /**
97
97
  * Invalidate dependency modules of the given modules, down to the bottom-level dependencies
98
98
  */
99
- invalidateSubDepTree(ids, invalidated = new Set()) {
99
+ invalidateSubDepTree(ids, invalidated = /* @__PURE__ */ new Set()) {
100
100
  for (const _id of ids) {
101
101
  const id = this.normalizePath(_id);
102
102
  if (invalidated.has(id)) continue;
@@ -132,6 +132,25 @@ class ViteNodeRunner {
132
132
  * Keys of the map are filepaths, or plain package names
133
133
  */
134
134
  moduleCache;
135
+ /**
136
+ * Tracks the stack of modules being executed for the purpose of calculating import self-time.
137
+ *
138
+ * Note that while in most cases, imports are a linear stack of modules,
139
+ * this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
140
+ *
141
+ * ```ts
142
+ * await Promise.all([
143
+ * import('./module1'),
144
+ * import('./module2'),
145
+ * ]);
146
+ * ```
147
+ *
148
+ * In this case, the self time will be reported incorrectly for one of the modules (could go negative).
149
+ * As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
150
+ */
151
+ executionStack = [];
152
+ // `performance` can be mocked, so make sure we're using the original function
153
+ performanceNow = performance.now.bind(performance);
135
154
  constructor(options) {
136
155
  this.options = options;
137
156
  this.root = options.root ?? process.cwd();
@@ -364,7 +383,6 @@ class ViteNodeRunner {
364
383
  };
365
384
  }
366
385
  async runModule(context, transformed) {
367
- var _this$options$moduleE;
368
386
  // add 'use strict' since ESM enables it by default
369
387
  const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
370
388
  const code = `${codeDefinition}${transformed}\n}}`;
@@ -373,9 +391,38 @@ class ViteNodeRunner {
373
391
  lineOffset: 0,
374
392
  columnOffset: -codeDefinition.length
375
393
  };
376
- (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, { startOffset: codeDefinition.length });
377
- const fn = vm.runInThisContext(code, options);
378
- await fn(...Object.values(context));
394
+ const finishModuleExecutionInfo = this.startCalculateModuleExecutionInfo(options.filename, codeDefinition.length);
395
+ try {
396
+ const fn = vm.runInThisContext(code, options);
397
+ await fn(...Object.values(context));
398
+ } finally {
399
+ var _this$options$moduleE;
400
+ (_this$options$moduleE = this.options.moduleExecutionInfo) === null || _this$options$moduleE === void 0 || _this$options$moduleE.set(options.filename, finishModuleExecutionInfo());
401
+ }
402
+ }
403
+ /**
404
+ * Starts calculating the module execution info such as the total duration and self time spent on executing the module.
405
+ * Returns a function to call once the module has finished executing.
406
+ */
407
+ startCalculateModuleExecutionInfo(filename, startOffset) {
408
+ const startTime = this.performanceNow();
409
+ this.executionStack.push({
410
+ filename,
411
+ startTime,
412
+ subImportTime: 0
413
+ });
414
+ return () => {
415
+ const duration = this.performanceNow() - startTime;
416
+ const currentExecution = this.executionStack.pop();
417
+ if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");
418
+ const selfTime = duration - currentExecution.subImportTime;
419
+ if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;
420
+ return {
421
+ startOffset,
422
+ duration,
423
+ selfTime
424
+ };
425
+ };
379
426
  }
380
427
  prepareContext(context) {
381
428
  return context;
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-CWZbpOcv.js';
3
+ import { C as CustomEventMap, a as ViteNodeRunner, H as HMRPayload$1, b as HotContext } from './index.d-DGmxD2U7.js';
4
4
  import './trace-mapping.d-DLVdEqOp.js';
5
5
 
6
6
  type EventType = string | symbol;
@@ -34,6 +34,8 @@ interface Update {
34
34
  /** @internal */
35
35
  isWithinCircularImport?: boolean
36
36
  /** @internal */
37
+ firstInvalidatedBy?: string
38
+ /** @internal */
37
39
  invalidates?: string[]
38
40
  }
39
41
 
@@ -98,14 +100,20 @@ interface WebSocketConnectionPayload {
98
100
  interface InvalidatePayload {
99
101
  path: string
100
102
  message: string | undefined
103
+ firstInvalidatedBy: string
101
104
  }
102
105
 
103
106
  /**
104
- * provides types for built-in Vite events
107
+ * provides types for payloads of built-in Vite events
105
108
  */
106
109
  type InferCustomEventPayload<T extends string> =
107
110
  T extends keyof CustomEventMap ? CustomEventMap[T] : any
108
111
 
112
+ /**
113
+ * provides types for names of built-in Vite events
114
+ */
115
+ type CustomEventName = keyof CustomEventMap | (string & {})
116
+
109
117
  type ModuleNamespace = Record<string, any> & {
110
118
  [Symbol.toStringTag]: 'Module'
111
119
  }
@@ -130,15 +138,18 @@ interface ViteHotContext {
130
138
  prune(cb: (data: any) => void): void
131
139
  invalidate(message?: string): void
132
140
 
133
- on<T extends string>(
141
+ on<T extends CustomEventName>(
134
142
  event: T,
135
143
  cb: (payload: InferCustomEventPayload<T>) => void,
136
144
  ): void
137
- off<T extends string>(
145
+ off<T extends CustomEventName>(
138
146
  event: T,
139
147
  cb: (payload: InferCustomEventPayload<T>) => void,
140
148
  ): void
141
- send<T extends string>(event: T, data?: InferCustomEventPayload<T>): void
149
+ send<T extends CustomEventName>(
150
+ event: T,
151
+ data?: InferCustomEventPayload<T>,
152
+ ): void
142
153
  }
143
154
 
144
155
  declare const DEFAULT_REQUEST_STUBS: Record<string, Record<string, unknown>>;
@@ -168,9 +179,14 @@ declare class ModuleCacheMap extends Map<string, ModuleCache> {
168
179
  */
169
180
  getSourceMap(id: string): EncodedSourceMap | null;
170
181
  }
171
- type ModuleExecutionInfo = Map<string, {
172
- startOffset: number
173
- }>;
182
+ type ModuleExecutionInfo = Map<string, ModuleExecutionInfoEntry>;
183
+ interface ModuleExecutionInfoEntry {
184
+ startOffset: number;
185
+ /** The duration that was spent executing the module. */
186
+ duration: number;
187
+ /** The time that was spent executing the module itself and externalized imports. */
188
+ selfTime: number;
189
+ }
174
190
  declare class ViteNodeRunner {
175
191
  options: ViteNodeRunnerOptions;
176
192
  root: string;
@@ -180,6 +196,25 @@ declare class ViteNodeRunner {
180
196
  * Keys of the map are filepaths, or plain package names
181
197
  */
182
198
  moduleCache: ModuleCacheMap;
199
+ /**
200
+ * Tracks the stack of modules being executed for the purpose of calculating import self-time.
201
+ *
202
+ * Note that while in most cases, imports are a linear stack of modules,
203
+ * this is occasionally not the case, for example when you have parallel top-level dynamic imports like so:
204
+ *
205
+ * ```ts
206
+ * await Promise.all([
207
+ * import('./module1'),
208
+ * import('./module2'),
209
+ * ]);
210
+ * ```
211
+ *
212
+ * In this case, the self time will be reported incorrectly for one of the modules (could go negative).
213
+ * As top-level awaits with dynamic imports like this are uncommon, we don't handle this case specifically.
214
+ */
215
+ private executionStack;
216
+ // `performance` can be mocked, so make sure we're using the original function
217
+ private performanceNow;
183
218
  constructor(options: ViteNodeRunnerOptions);
184
219
  executeFile(file: string): Promise<any>;
185
220
  executeId(rawId: string): Promise<any>;
@@ -193,6 +228,11 @@ declare class ViteNodeRunner {
193
228
  Symbol: SymbolConstructor
194
229
  };
195
230
  protected runModule(context: Record<string, any>, transformed: string): Promise<void>;
231
+ /**
232
+ * Starts calculating the module execution info such as the total duration and self time spent on executing the module.
233
+ * Returns a function to call once the module has finished executing.
234
+ */
235
+ protected startCalculateModuleExecutionInfo(filename: string, startOffset: number): () => ModuleExecutionInfoEntry;
196
236
  prepareContext(context: Record<string, any>): Record<string, any>;
197
237
  /**
198
238
  * Define if a module should be interop-ed
@@ -320,4 +360,4 @@ interface DebuggerOptions {
320
360
  }
321
361
 
322
362
  export { ModuleCacheMap as M, ViteNodeRunner as a, DEFAULT_REQUEST_STUBS as e };
323
- export type { Arrayable as A, CustomEventMap as C, DebuggerOptions as D, FetchResult as F, HMRPayload as H, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeServerOptions as V, HotContext as b, DepsHandlingOptions as c, ViteNodeResolveId as d, ModuleExecutionInfo as f, Awaitable as g, FetchFunction as h, ResolveIdFunction as i, CreateHotContextFunction as j, ModuleCache as k, ViteNodeRunnerOptions as l, ViteNodeResolveModule as m };
363
+ export type { Arrayable as A, CustomEventMap as C, DebuggerOptions as D, FetchResult as F, HMRPayload as H, Nullable as N, RawSourceMap as R, StartOfSourceMap as S, ViteNodeServerOptions as V, HotContext as b, DepsHandlingOptions as c, ViteNodeResolveId as d, ModuleExecutionInfo as f, ModuleExecutionInfoEntry as g, Awaitable as h, FetchFunction as i, ResolveIdFunction as j, CreateHotContextFunction as k, ModuleCache as l, ViteNodeRunnerOptions as m, ViteNodeResolveModule as n };
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-CWZbpOcv.js';
1
+ export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-DGmxD2U7.js';
2
2
  export { D as DecodedSourceMap, E as EncodedSourceMap, S as SourceMapInput } from './trace-mapping.d-DLVdEqOp.js';
package/dist/server.cjs CHANGED
@@ -44,7 +44,7 @@ function hashCode(s) {
44
44
  class Debugger {
45
45
  dumpDir;
46
46
  initPromise;
47
- externalizeMap = new Map();
47
+ externalizeMap = /* @__PURE__ */ new Map();
48
48
  constructor(root, options) {
49
49
  this.options = options;
50
50
  if (options.dumpModules) this.dumpDir = pathe.resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
@@ -89,7 +89,7 @@ class Debugger {
89
89
  async writeInfo() {
90
90
  if (!this.dumpDir) return;
91
91
  const info = JSON.stringify({
92
- time: new Date().toLocaleString(),
92
+ time: (/* @__PURE__ */ new Date()).toLocaleString(),
93
93
  externalize: Object.fromEntries(this.externalizeMap.entries())
94
94
  }, null, 2);
95
95
  return fs.promises.writeFile(pathe.join(this.dumpDir, "info.json"), info, "utf-8");
@@ -147,7 +147,7 @@ async function isValidNodeImport(id) {
147
147
  return false;
148
148
  }
149
149
  }
150
- const _defaultExternalizeCache = new Map();
150
+ const _defaultExternalizeCache = /* @__PURE__ */ new Map();
151
151
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
152
152
  if (!cache.has(id)) cache.set(id, _shouldExternalize(id, options));
153
153
  return cache.get(id);
@@ -191,24 +191,24 @@ function patchWindowsImportPath(path) {
191
191
  const debugRequest = createDebug("vite-node:server:request");
192
192
  class ViteNodeServer {
193
193
  fetchPromiseMap = {
194
- ssr: new Map(),
195
- web: new Map()
194
+ ssr: /* @__PURE__ */ new Map(),
195
+ web: /* @__PURE__ */ new Map()
196
196
  };
197
197
  transformPromiseMap = {
198
- ssr: new Map(),
199
- web: new Map()
198
+ ssr: /* @__PURE__ */ new Map(),
199
+ web: /* @__PURE__ */ new Map()
200
200
  };
201
201
  durations = {
202
- ssr: new Map(),
203
- web: new Map()
202
+ ssr: /* @__PURE__ */ new Map(),
203
+ web: /* @__PURE__ */ new Map()
204
204
  };
205
- existingOptimizedDeps = new Set();
205
+ existingOptimizedDeps = /* @__PURE__ */ new Set();
206
206
  fetchCaches = {
207
- ssr: new Map(),
208
- web: new Map()
207
+ ssr: /* @__PURE__ */ new Map(),
208
+ web: /* @__PURE__ */ new Map()
209
209
  };
210
- fetchCache = new Map();
211
- externalizeCache = new Map();
210
+ fetchCache = /* @__PURE__ */ new Map();
211
+ externalizeCache = /* @__PURE__ */ new Map();
212
212
  debugger;
213
213
  constructor(server, options = {}) {
214
214
  var _options$deps3;
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-CWZbpOcv.js';
2
+ import { D as DebuggerOptions, c as DepsHandlingOptions, V as ViteNodeServerOptions, F as FetchResult, d as ViteNodeResolveId } from './index.d-DGmxD2U7.js';
3
3
  import { E as EncodedSourceMap } from './trace-mapping.d-DLVdEqOp.js';
4
4
 
5
5
  declare class Debugger {
package/dist/server.mjs CHANGED
@@ -23,7 +23,7 @@ function hashCode(s) {
23
23
  class Debugger {
24
24
  dumpDir;
25
25
  initPromise;
26
- externalizeMap = new Map();
26
+ externalizeMap = /* @__PURE__ */ new Map();
27
27
  constructor(root, options) {
28
28
  this.options = options;
29
29
  if (options.dumpModules) this.dumpDir = resolve(root, options.dumpModules === true ? ".vite-node/dump" : options.dumpModules);
@@ -68,7 +68,7 @@ class Debugger {
68
68
  async writeInfo() {
69
69
  if (!this.dumpDir) return;
70
70
  const info = JSON.stringify({
71
- time: new Date().toLocaleString(),
71
+ time: (/* @__PURE__ */ new Date()).toLocaleString(),
72
72
  externalize: Object.fromEntries(this.externalizeMap.entries())
73
73
  }, null, 2);
74
74
  return promises.writeFile(join(this.dumpDir, "info.json"), info, "utf-8");
@@ -126,7 +126,7 @@ async function isValidNodeImport(id) {
126
126
  return false;
127
127
  }
128
128
  }
129
- const _defaultExternalizeCache = new Map();
129
+ const _defaultExternalizeCache = /* @__PURE__ */ new Map();
130
130
  async function shouldExternalize(id, options, cache = _defaultExternalizeCache) {
131
131
  if (!cache.has(id)) cache.set(id, _shouldExternalize(id, options));
132
132
  return cache.get(id);
@@ -170,24 +170,24 @@ function patchWindowsImportPath(path) {
170
170
  const debugRequest = createDebug("vite-node:server:request");
171
171
  class ViteNodeServer {
172
172
  fetchPromiseMap = {
173
- ssr: new Map(),
174
- web: new Map()
173
+ ssr: /* @__PURE__ */ new Map(),
174
+ web: /* @__PURE__ */ new Map()
175
175
  };
176
176
  transformPromiseMap = {
177
- ssr: new Map(),
178
- web: new Map()
177
+ ssr: /* @__PURE__ */ new Map(),
178
+ web: /* @__PURE__ */ new Map()
179
179
  };
180
180
  durations = {
181
- ssr: new Map(),
182
- web: new Map()
181
+ ssr: /* @__PURE__ */ new Map(),
182
+ web: /* @__PURE__ */ new Map()
183
183
  };
184
- existingOptimizedDeps = new Set();
184
+ existingOptimizedDeps = /* @__PURE__ */ new Set();
185
185
  fetchCaches = {
186
- ssr: new Map(),
187
- web: new Map()
186
+ ssr: /* @__PURE__ */ new Map(),
187
+ web: /* @__PURE__ */ new Map()
188
188
  };
189
- fetchCache = new Map();
190
- externalizeCache = new Map();
189
+ fetchCache = /* @__PURE__ */ new Map();
190
+ externalizeCache = /* @__PURE__ */ new Map();
191
191
  debugger;
192
192
  constructor(server, options = {}) {
193
193
  var _options$deps3;
@@ -920,7 +920,6 @@ let SOURCEMAPPING_URL = "sourceMa";
920
920
  SOURCEMAPPING_URL += "ppingURL";
921
921
  const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
922
922
  const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
923
- const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
924
923
  function withInlineSourcemap(result, options) {
925
924
  const map = result.map;
926
925
  let code = result.code;
@@ -953,9 +952,12 @@ function withInlineSourcemap(result, options) {
953
952
  return result;
954
953
  }
955
954
  function extractSourceMap(code) {
956
- var _code$match;
957
- const mapString = (_code$match = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) === null || _code$match === void 0 ? void 0 : _code$match[1];
958
- if (mapString) return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
955
+ const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
956
+ let lastMatch, match;
957
+ // eslint-disable-next-line no-cond-assign
958
+ while (match = regexp.exec(code)) lastMatch = match;
959
+ // pick only the last source map keeping user strings that look like maps
960
+ if (lastMatch) return JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8"));
959
961
  return null;
960
962
  }
961
963
  function installSourcemapsSupport(options) {
@@ -918,7 +918,6 @@ let SOURCEMAPPING_URL = "sourceMa";
918
918
  SOURCEMAPPING_URL += "ppingURL";
919
919
  const VITE_NODE_SOURCEMAPPING_SOURCE = "//# sourceMappingSource=vite-node";
920
920
  const VITE_NODE_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`;
921
- const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`);
922
921
  function withInlineSourcemap(result, options) {
923
922
  const map = result.map;
924
923
  let code = result.code;
@@ -951,9 +950,12 @@ function withInlineSourcemap(result, options) {
951
950
  return result;
952
951
  }
953
952
  function extractSourceMap(code) {
954
- var _code$match;
955
- const mapString = (_code$match = code.match(VITE_NODE_SOURCEMAPPING_REGEXP)) === null || _code$match === void 0 ? void 0 : _code$match[1];
956
- if (mapString) return JSON.parse(Buffer.from(mapString, "base64").toString("utf-8"));
953
+ const regexp = new RegExp(`//# ${VITE_NODE_SOURCEMAPPING_URL};base64,(.+)`, "gm");
954
+ let lastMatch, match;
955
+ // eslint-disable-next-line no-cond-assign
956
+ while (match = regexp.exec(code)) lastMatch = match;
957
+ // pick only the last source map keeping user strings that look like maps
958
+ if (lastMatch) return JSON.parse(Buffer.from(lastMatch[1], "base64").toString("utf-8"));
957
959
  return null;
958
960
  }
959
961
  function installSourcemapsSupport(options) {
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-CWZbpOcv.js';
2
+ export { A as Arrayable, h as Awaitable, k as CreateHotContextFunction, D as DebuggerOptions, c as DepsHandlingOptions, i as FetchFunction, F as FetchResult, b as HotContext, l as ModuleCache, M as ModuleCacheMap, f as ModuleExecutionInfo, N as Nullable, R as RawSourceMap, j as ResolveIdFunction, S as StartOfSourceMap, d as ViteNodeResolveId, n as ViteNodeResolveModule, m as ViteNodeRunnerOptions, V as ViteNodeServerOptions } from './index.d-DGmxD2U7.js';
package/dist/utils.cjs CHANGED
@@ -177,7 +177,7 @@ function createImportMetaEnvProxy() {
177
177
  }
178
178
  });
179
179
  }
180
- const packageCache = new Map();
180
+ const packageCache = /* @__PURE__ */ new Map();
181
181
  async function findNearestPackageData(basedir) {
182
182
  const originalBasedir = basedir;
183
183
  while (basedir) {
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { N as Nullable, A as Arrayable } from './index.d-CWZbpOcv.js';
1
+ import { N as Nullable, A as Arrayable } from './index.d-DGmxD2U7.js';
2
2
  import './trace-mapping.d-DLVdEqOp.js';
3
3
 
4
4
  declare const isWindows: boolean;
package/dist/utils.mjs CHANGED
@@ -175,7 +175,7 @@ function createImportMetaEnvProxy() {
175
175
  }
176
176
  });
177
177
  }
178
- const packageCache = new Map();
178
+ const packageCache = /* @__PURE__ */ new Map();
179
179
  async function findNearestPackageData(basedir) {
180
180
  const originalBasedir = basedir;
181
181
  while (basedir) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "3.2.0-beta.3",
4
+ "version": "3.2.0",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",