1- import ansiColors from 'ansi-colors' ;
21import path from 'path' ;
32import { rm } from 'fs/promises' ;
43import fs from 'fs' ;
4+ import fse from 'fs-extra' ;
55import {
66 MANIFEST_EXT ,
77 Manifest ,
@@ -103,21 +103,35 @@ class DTSManager {
103103
104104 const mfTypesPath = retrieveMfTypesPath ( tsConfig , remoteOptions ) ;
105105
106- if ( hasRemotes ) {
107- const tempHostOptions = {
108- moduleFederationConfig : remoteOptions . moduleFederationConfig ,
109- typesFolder : path . join ( mfTypesPath , 'node_modules' ) ,
110- remoteTypesFolder :
111- remoteOptions ?. hostRemoteTypesFolder || remoteOptions . typesFolder ,
112- deleteTypesFolder : true ,
113- context : remoteOptions . context ,
114- implementation : remoteOptions . implementation ,
115- abortOnError : false ,
116- } ;
117- await this . consumeArchiveTypes ( tempHostOptions ) ;
106+ if ( hasRemotes && this . options . host ) {
107+ try {
108+ const { hostOptions } = retrieveHostConfig ( this . options . host ) ;
109+ const remoteTypesFolder = path . resolve (
110+ hostOptions . context ,
111+ hostOptions . typesFolder ,
112+ ) ;
113+
114+ const targetDir = path . join ( mfTypesPath , 'node_modules' ) ;
115+ if ( fs . existsSync ( remoteTypesFolder ) ) {
116+ const targetFolder = path . resolve ( remoteOptions . context , targetDir ) ;
117+ await fse . ensureDir ( targetFolder ) ;
118+ await fse . copy ( remoteTypesFolder , targetFolder , { overwrite : true } ) ;
119+ }
120+ } catch ( err ) {
121+ if ( this . options . host ?. abortOnError === false ) {
122+ fileLog (
123+ `Unable to copy remote types, ${ err } ` ,
124+ 'extractRemoteTypes' ,
125+ 'error' ,
126+ ) ;
127+ } else {
128+ throw err ;
129+ }
130+ }
118131 }
119132 }
120133
134+ // it must execute after consumeTypes
121135 async generateTypes ( ) {
122136 try {
123137 const { options } = this ;
@@ -134,6 +148,21 @@ class DTSManager {
134148 return ;
135149 }
136150
151+ if ( tsConfig . compilerOptions . tsBuildInfoFile ) {
152+ try {
153+ const tsBuildInfoFile = path . resolve (
154+ remoteOptions . context ,
155+ tsConfig . compilerOptions . tsBuildInfoFile ,
156+ ) ;
157+ const mfTypesPath = retrieveMfTypesPath ( tsConfig , remoteOptions ) ;
158+ if ( ! fs . existsSync ( mfTypesPath ) ) {
159+ fs . rmSync ( tsBuildInfoFile , { force : true } ) ;
160+ }
161+ } catch ( e ) {
162+ //noop
163+ }
164+ }
165+
137166 await this . extractRemoteTypes ( {
138167 remoteOptions,
139168 tsConfig,
@@ -150,7 +179,6 @@ class DTSManager {
150179 apiTypesPath = retrieveMfAPITypesPath ( tsConfig , remoteOptions ) ;
151180 fs . writeFileSync ( apiTypesPath , apiTypes ) ;
152181 }
153-
154182 try {
155183 if ( remoteOptions . deleteTypesFolder ) {
156184 await rm ( retrieveMfTypesPath ( tsConfig , remoteOptions ) , {
@@ -167,7 +195,7 @@ class DTSManager {
167195 } catch ( error ) {
168196 if ( this . options . remote ?. abortOnError === false ) {
169197 if ( this . options . displayErrorInTerminal ) {
170- logger . error ( `Unable to compile federated types${ error } ` ) ;
198+ logger . error ( `Unable to compile federated types ${ error } ` ) ;
171199 }
172200 } else {
173201 throw error ;
@@ -182,6 +210,9 @@ class DTSManager {
182210 if ( ! remoteInfo . url . includes ( MANIFEST_EXT ) ) {
183211 return remoteInfo as Required < RemoteInfo > ;
184212 }
213+ if ( remoteInfo . zipUrl ) {
214+ return remoteInfo as Required < RemoteInfo > ;
215+ }
185216 const url = remoteInfo . url ;
186217 const res = await axiosGet ( url ) ;
187218 const manifestJson = res . data as unknown as Manifest ;
0 commit comments