@@ -46,17 +46,18 @@ let rootPackageJson = Object.assign({}, pkg, {
4646 typings : './Rx.d.ts'
4747} ) ;
4848
49- // Create an object of key/value pairs resolving the "from" side
50- // of an import/require to the file name.
51- const importTargets = klawSync ( CJS_ROOT , {
49+ // Get a list of the file names
50+ const fileNames = klawSync ( CJS_ROOT , {
5251 nodir : true ,
5352 filter : function ( item ) {
5453 return item . path . endsWith ( '.js' ) ;
5554 }
5655} )
5756. map ( item => item . path )
58- . map ( path => path . slice ( ( `${ __dirname } /${ CJS_ROOT } ` ) . length ) )
59- . map ( fileName => {
57+ . map ( path => path . slice ( ( `${ __dirname } /${ CJS_ROOT } ` ) . length ) ) ;
58+
59+ // Execute build optimizer transforms on ESM5 files
60+ fileNames . map ( fileName => {
6061 if ( ! bo ) return fileName ;
6162 let fullPath = path . resolve ( __dirname , ESM5_ROOT , fileName ) ;
6263 let content = fs . readFileSync ( fullPath ) . toString ( ) ;
@@ -66,12 +67,21 @@ const importTargets = klawSync(CJS_ROOT, {
6667 } ) ;
6768 fs . writeFileSync ( fullPath , transformed . content ) ;
6869 return fileName ;
69- } )
70- . reduce ( ( acc , fileName ) => {
70+ } ) ;
71+
72+ // Create an object hash mapping imports to file names
73+ const fileMappings = fileNames . reduce ( ( acc , fileName ) => {
7174 // Get the name of the file to be the new directory
7275 const directory = fileName . slice ( 0 , fileName . length - 3 ) ;
7376
7477 acc [ directory ] = fileName ;
78+ return acc ;
79+ } , { } ) ;
80+
81+ // For node-resolved imports (rxjs/operators resolves to rxjs/operators/index.js), Webpack's "alias"
82+ // functionality requires that the most broad mapping (rxjs/operators) be at the end of the alias
83+ // mapping object. Created Webpack issue: https://github.com/webpack/webpack/issues/5870
84+ const importTargets = Object . assign ( { } , fileMappings , fileNames . reduce ( ( acc , fileName ) => {
7585 // If the fileName is index.js (re-export file), create another entry
7686 // for the root of the export. Example:
7787 // fileName = 'rxjs/operators/index.js'
@@ -81,7 +91,7 @@ const importTargets = klawSync(CJS_ROOT, {
8191 acc [ fileName . slice ( 0 , EXPORT_FILE . length + 1 ) ] = fileName ;
8292 }
8393 return acc ;
84- } , { } ) ;
94+ } , { } ) ) ;
8595
8696createImportTargets ( importTargets , "_esm5/" , ESM5_PKG ) ;
8797createImportTargets ( importTargets , "_esm2015/" , ESM2015_PKG ) ;
0 commit comments