@@ -98,30 +98,22 @@ export function rewritePathsWithExposedFederatedModules(
9898 outFile : string ,
9999 typings : string ,
100100) : void {
101- const declareRegex = / d e c l a r e m o d u l e " ( .* ) " / g;
102- const moduleImportPaths : string [ ] = [ ] ;
101+ const regexDeclareModule = / d e c l a r e m o d u l e " ( .* ) " / g;
102+ const declaredModulePaths : string [ ] = [ ] ;
103103
104+ // Collect all instances of `declare module "..."`
104105 let execResults : null | string [ ] = [ ] ;
105- while ( ( execResults = declareRegex . exec ( typings ) ) !== null ) {
106- moduleImportPaths . push ( execResults [ 1 ] ) ;
106+ while ( ( execResults = regexDeclareModule . exec ( typings ) ) !== null ) {
107+ declaredModulePaths . push ( execResults [ 1 ] ) ;
107108 }
108109
109110 let typingsUpdated : string = typings ;
110111
111- // Support aliases in paths (e.g. @/)
112- // Aliases are not included in emitted declarations thus they have to be removed from the exposed path
113- const aliasPaths = Object . values ( getTSConfigCompilerOptions ( ) . paths || { } ) . map ( alias => alias [ 0 ] ) ;
114- function substituteAliases ( modulePath : string ) : string {
115- aliasPaths . forEach ( aliasPath => {
116- modulePath = modulePath . replace ( aliasPath , '' ) ;
117- } ) ;
118- return modulePath ;
119- }
120-
121112 // Replace and prefix paths by exposed remote names
122- moduleImportPaths . forEach ( ( importPath ) => {
113+ declaredModulePaths . forEach ( ( importPath ) => {
114+ // Aliases are not included in the emitted declarations hence the need to use `endsWith`
123115 const [ exposedModuleKey , ...exposedModuleNameAliases ] = Object . keys ( federationConfig . exposes )
124- . filter ( key => federationConfig . exposes [ key ] . endsWith ( substituteAliases ( importPath ) ) )
116+ . filter ( key => federationConfig . exposes [ key ] . endsWith ( importPath ) )
125117 . map ( key => key . replace ( / ^ \. \/ / , '' ) ) ;
126118
127119 let federatedModulePath = exposedModuleKey
@@ -143,6 +135,8 @@ export function rewritePathsWithExposedFederatedModules(
143135 ] . join ( '\n' ) ;
144136 } ) ;
145137
138+ typingsUpdated = includeTypesFromNodeModules ( federationConfig , typingsUpdated ) ;
139+
146140 mkdirp . sync ( path . dirname ( outFile ) ) ;
147141 fs . writeFileSync ( outFile , typingsUpdated . replace ( / \r \n / g, '\n' ) ) ;
148142}
0 commit comments