@@ -38,38 +38,39 @@ export class TraceLoader {
3838 constructor ( ) {
3939 }
4040
41- async load ( backend : TraceLoaderBackend , unzipProgress : ( done : number , total : number ) => void ) {
41+ async load ( backend : TraceLoaderBackend , traceFile ?: string , unzipProgress ? : ( done : number , total : number ) => void ) {
4242 this . _backend = backend ;
4343
44- const ordinals : string [ ] = [ ] ;
44+ const prefix = traceFile ?. match ( / ( .+ ) \. t r a c e $ / ) ?. [ 1 ] ;
45+ const prefixes : string [ ] = [ ] ;
4546 let hasSource = false ;
4647 for ( const entryName of await this . _backend . entryNames ( ) ) {
4748 const match = entryName . match ( / ( .+ ) \. t r a c e $ / ) ;
48- if ( match )
49- ordinals . push ( match [ 1 ] || '' ) ;
49+ if ( match && ( ! prefix || prefix === match [ 1 ] ) )
50+ prefixes . push ( match [ 1 ] || '' ) ;
5051 if ( entryName . includes ( 'src@' ) )
5152 hasSource = true ;
5253 }
53- if ( ! ordinals . length )
54+ if ( ! prefixes . length )
5455 throw new Error ( 'Cannot find .trace file' ) ;
5556
5657 this . _snapshotStorage = new SnapshotStorage ( ) ;
5758
5859 // 3 * ordinals progress increments below.
59- const total = ordinals . length * 3 ;
60+ const total = prefixes . length * 3 ;
6061 let done = 0 ;
61- for ( const ordinal of ordinals ) {
62+ for ( const prefix of prefixes ) {
6263 const contextEntry = createEmptyContext ( ) ;
6364 contextEntry . hasSource = hasSource ;
6465 const modernizer = new TraceModernizer ( contextEntry , this . _snapshotStorage ) ;
6566
66- const trace = await this . _backend . readText ( ordinal + '.trace' ) || '' ;
67+ const trace = await this . _backend . readText ( prefix + '.trace' ) || '' ;
6768 modernizer . appendTrace ( trace ) ;
68- unzipProgress ( ++ done , total ) ;
69+ unzipProgress ?. ( ++ done , total ) ;
6970
70- const network = await this . _backend . readText ( ordinal + '.network' ) || '' ;
71+ const network = await this . _backend . readText ( prefix + '.network' ) || '' ;
7172 modernizer . appendTrace ( network ) ;
72- unzipProgress ( ++ done , total ) ;
73+ unzipProgress ?. ( ++ done , total ) ;
7374
7475 contextEntry . actions = modernizer . actions ( ) . sort ( ( a1 , a2 ) => a1 . startTime - a2 . startTime ) ;
7576
@@ -87,13 +88,13 @@ export class TraceLoader {
8788 }
8889 }
8990
90- const stacks = await this . _backend . readText ( ordinal + '.stacks' ) ;
91+ const stacks = await this . _backend . readText ( prefix + '.stacks' ) ;
9192 if ( stacks ) {
9293 const callMetadata = parseClientSideCallMetadata ( JSON . parse ( stacks ) ) ;
9394 for ( const action of contextEntry . actions )
9495 action . stack = action . stack || callMetadata . get ( action . callId ) ;
9596 }
96- unzipProgress ( ++ done , total ) ;
97+ unzipProgress ?. ( ++ done , total ) ;
9798
9899 for ( const resource of contextEntry . resources ) {
99100 if ( resource . request . postData ?. _sha1 )
0 commit comments