vite-node 1.5.2 → 1.6.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.
package/dist/cli.cjs CHANGED
@@ -20,7 +20,7 @@ require('node:url');
20
20
  require('node:vm');
21
21
  require('node:events');
22
22
 
23
- var version = "1.5.2";
23
+ var version = "1.6.0";
24
24
 
25
25
  const cli = cac("vite-node");
26
26
  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.mjs CHANGED
@@ -18,7 +18,7 @@ import 'node:url';
18
18
  import 'node:vm';
19
19
  import 'node:events';
20
20
 
21
- var version = "1.5.2";
21
+ var version = "1.6.0";
22
22
 
23
23
  const cli = cac("vite-node");
24
24
  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/server.cjs CHANGED
@@ -243,6 +243,10 @@ class ViteNodeServer {
243
243
  ssr: /* @__PURE__ */ new Map(),
244
244
  web: /* @__PURE__ */ new Map()
245
245
  };
246
+ durations = {
247
+ ssr: /* @__PURE__ */ new Map(),
248
+ web: /* @__PURE__ */ new Map()
249
+ };
246
250
  existingOptimizedDeps = /* @__PURE__ */ new Set();
247
251
  fetchCaches = {
248
252
  ssr: /* @__PURE__ */ new Map(),
@@ -254,6 +258,11 @@ class ViteNodeServer {
254
258
  shouldExternalize(id) {
255
259
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
256
260
  }
261
+ getTotalDuration() {
262
+ const ssrDurations = [...this.durations.ssr.values()].flat();
263
+ const webDurations = [...this.durations.web.values()].flat();
264
+ return [...ssrDurations, ...webDurations].reduce((a, b) => a + b, 0);
265
+ }
257
266
  async ensureExists(id) {
258
267
  if (this.existingOptimizedDeps.has(id))
259
268
  return true;
@@ -287,14 +296,17 @@ class ViteNodeServer {
287
296
  assert(mode === "web" || mode === "ssr", `"transformMode" can only be "web" or "ssr", received "${mode}".`);
288
297
  }
289
298
  async fetchModule(id, transformMode) {
290
- const moduleId = utils.normalizeModuleId(id);
291
299
  const mode = transformMode || this.getTransformMode(id);
300
+ return this.fetchResult(id, mode).then((r) => {
301
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
302
+ });
303
+ }
304
+ async fetchResult(id, mode) {
305
+ const moduleId = utils.normalizeModuleId(id);
292
306
  this.assertMode(mode);
293
307
  const promiseMap = this.fetchPromiseMap[mode];
294
308
  if (!promiseMap.has(moduleId)) {
295
- promiseMap.set(moduleId, this._fetchModule(moduleId, mode).then((r) => {
296
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
297
- }).finally(() => {
309
+ promiseMap.set(moduleId, this._fetchModule(moduleId, mode).finally(() => {
298
310
  promiseMap.delete(moduleId);
299
311
  }));
300
312
  }
@@ -387,6 +399,11 @@ class ViteNodeServer {
387
399
  timestamp: time,
388
400
  result
389
401
  };
402
+ const durations = this.durations[transformMode].get(filePath) || [];
403
+ this.durations[transformMode].set(
404
+ filePath,
405
+ [...durations, duration ?? 0]
406
+ );
390
407
  this.fetchCaches[transformMode].set(filePath, cacheEntry);
391
408
  this.fetchCache.set(filePath, cacheEntry);
392
409
  return result;
package/dist/server.d.ts CHANGED
@@ -29,6 +29,7 @@ declare class ViteNodeServer {
29
29
  options: ViteNodeServerOptions;
30
30
  private fetchPromiseMap;
31
31
  private transformPromiseMap;
32
+ private durations;
32
33
  private existingOptimizedDeps;
33
34
  fetchCaches: {
34
35
  ssr: Map<string, FetchCache>;
@@ -39,11 +40,13 @@ declare class ViteNodeServer {
39
40
  debugger?: Debugger;
40
41
  constructor(server: ViteDevServer, options?: ViteNodeServerOptions);
41
42
  shouldExternalize(id: string): Promise<string | false>;
43
+ getTotalDuration(): number;
42
44
  private ensureExists;
43
45
  resolveId(id: string, importer?: string, transformMode?: 'web' | 'ssr'): Promise<ViteNodeResolveId | null>;
44
46
  getSourceMap(source: string): EncodedSourceMap | null;
45
47
  private assertMode;
46
48
  fetchModule(id: string, transformMode?: 'web' | 'ssr'): Promise<FetchResult>;
49
+ fetchResult(id: string, mode: 'web' | 'ssr'): Promise<FetchResult>;
47
50
  transformRequest(id: string, filepath?: string, transformMode?: 'web' | 'ssr'): Promise<TransformResult | null | undefined>;
48
51
  transformModule(id: string, transformMode?: 'web' | 'ssr'): Promise<{
49
52
  code: string | undefined;
package/dist/server.mjs CHANGED
@@ -241,6 +241,10 @@ class ViteNodeServer {
241
241
  ssr: /* @__PURE__ */ new Map(),
242
242
  web: /* @__PURE__ */ new Map()
243
243
  };
244
+ durations = {
245
+ ssr: /* @__PURE__ */ new Map(),
246
+ web: /* @__PURE__ */ new Map()
247
+ };
244
248
  existingOptimizedDeps = /* @__PURE__ */ new Set();
245
249
  fetchCaches = {
246
250
  ssr: /* @__PURE__ */ new Map(),
@@ -252,6 +256,11 @@ class ViteNodeServer {
252
256
  shouldExternalize(id) {
253
257
  return shouldExternalize(id, this.options.deps, this.externalizeCache);
254
258
  }
259
+ getTotalDuration() {
260
+ const ssrDurations = [...this.durations.ssr.values()].flat();
261
+ const webDurations = [...this.durations.web.values()].flat();
262
+ return [...ssrDurations, ...webDurations].reduce((a, b) => a + b, 0);
263
+ }
255
264
  async ensureExists(id) {
256
265
  if (this.existingOptimizedDeps.has(id))
257
266
  return true;
@@ -285,14 +294,17 @@ class ViteNodeServer {
285
294
  assert(mode === "web" || mode === "ssr", `"transformMode" can only be "web" or "ssr", received "${mode}".`);
286
295
  }
287
296
  async fetchModule(id, transformMode) {
288
- const moduleId = normalizeModuleId(id);
289
297
  const mode = transformMode || this.getTransformMode(id);
298
+ return this.fetchResult(id, mode).then((r) => {
299
+ return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
300
+ });
301
+ }
302
+ async fetchResult(id, mode) {
303
+ const moduleId = normalizeModuleId(id);
290
304
  this.assertMode(mode);
291
305
  const promiseMap = this.fetchPromiseMap[mode];
292
306
  if (!promiseMap.has(moduleId)) {
293
- promiseMap.set(moduleId, this._fetchModule(moduleId, mode).then((r) => {
294
- return this.options.sourcemap !== true ? { ...r, map: void 0 } : r;
295
- }).finally(() => {
307
+ promiseMap.set(moduleId, this._fetchModule(moduleId, mode).finally(() => {
296
308
  promiseMap.delete(moduleId);
297
309
  }));
298
310
  }
@@ -385,6 +397,11 @@ class ViteNodeServer {
385
397
  timestamp: time,
386
398
  result
387
399
  };
400
+ const durations = this.durations[transformMode].get(filePath) || [];
401
+ this.durations[transformMode].set(
402
+ filePath,
403
+ [...durations, duration ?? 0]
404
+ );
388
405
  this.fetchCaches[transformMode].set(filePath, cacheEntry);
389
406
  this.fetchCache.set(filePath, cacheEntry);
390
407
  return result;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-node",
3
3
  "type": "module",
4
- "version": "1.5.2",
4
+ "version": "1.6.0",
5
5
  "description": "Vite as Node.js runtime",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",