@@ -135,22 +135,22 @@ export class Bundler {
135135 found : false ,
136136 ignored : imp . ignored
137137 } ;
138- } else if ( this . fileRegistry [ imp . fullPath ] == null ) {
138+ } else if ( this . usedImports [ imp . fullPath ] == null ) {
139+ // Add it to used imports
140+ this . usedImports [ imp . fullPath ] = 1 ;
141+
139142 // If file is not yet in the registry
140143 // Read
141- const impContent = await fs . readFile ( imp . fullPath , "utf-8" ) ;
144+ const impContent = this . fileRegistry [ imp . fullPath ] == null
145+ ? await fs . readFile ( imp . fullPath , "utf-8" )
146+ : this . fileRegistry [ imp . fullPath ] as string ;
142147
143148 // and bundle it
144149 const bundledImport = await this . _bundle ( imp . fullPath , impContent , dedupeFiles , includePaths , ignoredImports ) ;
145150
146151 // Then add its bundled content to the registry
147152 this . fileRegistry [ imp . fullPath ] = bundledImport . bundledContent ;
148153
149- // Add it to used imports, if it's not there
150- if ( this . usedImports != null && this . usedImports [ imp . fullPath ] == null ) {
151- this . usedImports [ imp . fullPath ] = 1 ;
152- }
153-
154154 // And whole BundleResult to current imports
155155 currentImport = bundledImport ;
156156 } else {
@@ -236,6 +236,11 @@ export class Bundler {
236236 }
237237
238238 private async resolveImport ( importData : ImportData , includePaths : string [ ] ) : Promise < ImportData > {
239+ if ( this . fileRegistry [ importData . fullPath ] ) {
240+ importData . found = true ;
241+ return importData ;
242+ }
243+
239244 try {
240245 await fs . access ( importData . fullPath ) ;
241246 importData . found = true ;
0 commit comments