@@ -31,6 +31,11 @@ export class ViteNodeServer {
3131 web : new Map < string , Promise < TransformResult | null | undefined > > ( ) ,
3232 }
3333
34+ private durations = {
35+ ssr : new Map < string , number [ ] > ( ) ,
36+ web : new Map < string , number [ ] > ( ) ,
37+ }
38+
3439 private existingOptimizedDeps = new Set < string > ( )
3540
3641 fetchCaches = {
@@ -102,6 +107,12 @@ export class ViteNodeServer {
102107 return shouldExternalize ( id , this . options . deps , this . externalizeCache )
103108 }
104109
110+ public getTotalDuration ( ) {
111+ const ssrDurations = [ ...this . durations . ssr . values ( ) ] . flat ( )
112+ const webDurations = [ ...this . durations . web . values ( ) ] . flat ( )
113+ return [ ...ssrDurations , ...webDurations ] . reduce ( ( a , b ) => a + b , 0 )
114+ }
115+
105116 private async ensureExists ( id : string ) : Promise < boolean > {
106117 if ( this . existingOptimizedDeps . has ( id ) )
107118 return true
@@ -138,16 +149,20 @@ export class ViteNodeServer {
138149 }
139150
140151 async fetchModule ( id : string , transformMode ?: 'web' | 'ssr' ) : Promise < FetchResult > {
141- const moduleId = normalizeModuleId ( id )
142152 const mode = transformMode || this . getTransformMode ( id )
153+ return this . fetchResult ( id , mode )
154+ . then ( ( r ) => {
155+ return this . options . sourcemap !== true ? { ...r , map : undefined } : r
156+ } )
157+ }
158+
159+ async fetchResult ( id : string , mode : 'web' | 'ssr' ) {
160+ const moduleId = normalizeModuleId ( id )
143161 this . assertMode ( mode )
144162 const promiseMap = this . fetchPromiseMap [ mode ]
145163 // reuse transform for concurrent requests
146164 if ( ! promiseMap . has ( moduleId ) ) {
147165 promiseMap . set ( moduleId , this . _fetchModule ( moduleId , mode )
148- . then ( ( r ) => {
149- return this . options . sourcemap !== true ? { ...r , map : undefined } : r
150- } )
151166 . finally ( ( ) => {
152167 promiseMap . delete ( moduleId )
153168 } ) )
@@ -268,6 +283,12 @@ export class ViteNodeServer {
268283 result,
269284 }
270285
286+ const durations = this . durations [ transformMode ] . get ( filePath ) || [ ]
287+ this . durations [ transformMode ] . set (
288+ filePath ,
289+ [ ...durations , duration ?? 0 ] ,
290+ )
291+
271292 this . fetchCaches [ transformMode ] . set ( filePath , cacheEntry )
272293 this . fetchCache . set ( filePath , cacheEntry )
273294
0 commit comments