@@ -195,8 +195,6 @@ module.exports = class Inliner {
195195 continue ;
196196 }
197197
198- console . log ( "Rewriting" , relativePath , "as index re-export stub." ) ;
199-
200198 const depth = relativePath . split ( "/" ) . length - 1 ;
201199 const indexRelativePath =
202200 ( depth === 0
@@ -252,23 +250,24 @@ module.exports = class Inliner {
252250 const packageName = requireStatement [ 3 ] . replace ( "/" , "\\/" ) ;
253251
254252 const original = this . indexContents . match (
255- new RegExp ( `var import_${ variableSuffix } = require\\(\"${ packageName } \"\\);` )
253+ new RegExp ( `var ( import_${ variableSuffix } (\d+)?) = require\\(\"${ packageName } \"\\);` )
256254 ) ;
255+
257256 if ( original ) {
258257 let redundancyIndex = 0 ;
259258 let misses = 0 ;
259+ const originalVariable = original [ 1 ] ;
260260
261261 // perform an incremental replacement instead of a global (\d+) replacement
262262 // to be safe.
263263 while ( true ) {
264264 const redundantRequire = `var import_${ variableSuffix } ${ redundancyIndex } = require\\("${ packageName } "\\);` ;
265- const redundantVariable = `import_${ variableSuffix } ${ redundancyIndex } ` ;
265+ const redundantVariable = `import_${ variableSuffix } ${ redundancyIndex } (\\.) ` ;
266266
267267 if ( this . indexContents . match ( new RegExp ( redundantRequire ) ) ) {
268- console . log ( "Replacing var" , redundantVariable ) ;
269268 this . indexContents = this . indexContents
270269 . replace ( new RegExp ( redundantRequire , "g" ) , "" )
271- . replace ( new RegExp ( redundantVariable , "g" ) , `import_ ${ variableSuffix } ` ) ;
270+ . replace ( new RegExp ( redundantVariable , "g" ) , `${ originalVariable } $1 ` ) ;
272271 } else if ( misses ++ > 10 ) {
273272 break ;
274273 }
0 commit comments