@@ -31,6 +31,11 @@ export class ViteNodeServer {
31
31
web : new Map < string , Promise < TransformResult | null | undefined > > ( ) ,
32
32
}
33
33
34
+ private durations = {
35
+ ssr : new Map < string , number [ ] > ( ) ,
36
+ web : new Map < string , number [ ] > ( ) ,
37
+ }
38
+
34
39
private existingOptimizedDeps = new Set < string > ( )
35
40
36
41
fetchCaches = {
@@ -102,6 +107,12 @@ export class ViteNodeServer {
102
107
return shouldExternalize ( id , this . options . deps , this . externalizeCache )
103
108
}
104
109
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
+
105
116
private async ensureExists ( id : string ) : Promise < boolean > {
106
117
if ( this . existingOptimizedDeps . has ( id ) )
107
118
return true
@@ -138,16 +149,20 @@ export class ViteNodeServer {
138
149
}
139
150
140
151
async fetchModule ( id : string , transformMode ?: 'web' | 'ssr' ) : Promise < FetchResult > {
141
- const moduleId = normalizeModuleId ( id )
142
152
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 )
143
161
this . assertMode ( mode )
144
162
const promiseMap = this . fetchPromiseMap [ mode ]
145
163
// reuse transform for concurrent requests
146
164
if ( ! promiseMap . has ( moduleId ) ) {
147
165
promiseMap . set ( moduleId , this . _fetchModule ( moduleId , mode )
148
- . then ( ( r ) => {
149
- return this . options . sourcemap !== true ? { ...r , map : undefined } : r
150
- } )
151
166
. finally ( ( ) => {
152
167
promiseMap . delete ( moduleId )
153
168
} ) )
@@ -268,6 +283,12 @@ export class ViteNodeServer {
268
283
result,
269
284
}
270
285
286
+ const durations = this . durations [ transformMode ] . get ( filePath ) || [ ]
287
+ this . durations [ transformMode ] . set (
288
+ filePath ,
289
+ [ ...durations , duration ?? 0 ] ,
290
+ )
291
+
271
292
this . fetchCaches [ transformMode ] . set ( filePath , cacheEntry )
272
293
this . fetchCache . set ( filePath , cacheEntry )
273
294
0 commit comments