@@ -9,7 +9,7 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
99 name : 'instrument-bundler-plugin' ,
1010 setup ( build ) {
1111 const namespaces = { bundle : 'bundle' } ;
12- const legacyScripts : string [ ] = [ ] ;
12+ const legacyScripts = new Map < string , string > ( ) ;
1313 build . onResolve ( { filter : / .* / } , ( args ) => {
1414 // css @import statement
1515 if ( args . kind === 'import-rule' ) {
@@ -56,7 +56,7 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
5656 ]
5757 } ;
5858 }
59- legacyScripts . push ( input . content as string ) ;
59+ legacyScripts . set ( args . path , input . content as string ) ;
6060 return { contents : input . content , loader : 'empty' } ;
6161 } ) ;
6262 build . onLoad ( { filter : / ^ \/ r u n t i m e \/ v 1 \/ .* .c s s $ / , namespace : namespaces . bundle } , ( args ) => {
@@ -84,7 +84,14 @@ export const plugin = (options: { inputs: BundlerInput[] }): Plugin => {
8484 return { contents, loader } ;
8585 } ) ;
8686 build . onEnd ( ( result ) => {
87- result . legacyScripts = legacyScripts ;
87+ result . legacyScripts = [ ] ;
88+ Object . keys ( result . metafile ! . inputs ) . forEach ( ( path ) => {
89+ const script = legacyScripts . get ( path . replace ( 'bundle:' , '' ) ) ;
90+ if ( ! script ) {
91+ return ;
92+ }
93+ result . legacyScripts ! . push ( script ) ;
94+ } ) ;
8895 } ) ;
8996 }
9097 } ;
0 commit comments