@@ -95,9 +95,8 @@ export async function bundleShared(
9595 platform,
9696 } ) ;
9797
98- const cachedFiles = bundleResult . map ( br => path . basename ( br . fileName ) ) ;
98+ const cachedFiles = bundleResult . map ( ( br ) => path . basename ( br . fileName ) ) ;
9999 copyCacheToOutput ( cachedFiles , cachePath , fullOutputPath ) ;
100-
101100 } catch ( e ) {
102101 logger . error ( 'Error bundling shared npm package ' ) ;
103102 if ( e instanceof Error ) {
@@ -131,31 +130,33 @@ export async function bundleShared(
131130 }
132131
133132 const resultCacheFile = createCacheFileName (
134- configState ,
135- sharedBundles ,
136- fedOptions ,
137- cachePath ,
133+ configState ,
134+ sharedBundles ,
135+ fedOptions ,
136+ cachePath ,
138137 platform
139138 ) ;
140139
141140 if ( fs . existsSync ( resultCacheFile ) ) {
142- const cachedResult : SharedInfo [ ] = JSON . parse ( fs . readFileSync ( resultCacheFile , 'utf-8' ) ) ;
143- const cachedFiles = cachedResult . map ( cr => cr . outFileName ) ;
144- copyCacheToOutput ( cachedFiles , cachePath , fullOutputPath )
145- return cachedResult ;
141+ const cachedResult : SharedInfo [ ] = JSON . parse (
142+ fs . readFileSync ( resultCacheFile , 'utf-8' )
143+ ) ;
144+ const cachedFiles = cachedResult . map ( ( cr ) => cr . outFileName ) ;
145+ copyCacheToOutput ( cachedFiles , cachePath , fullOutputPath ) ;
146+ return cachedResult ;
146147 }
147148
148149 const outFileNames = [ ...exptedResults ] ;
149150
150151 const result = buildResult (
151- packageInfos ,
152- sharedBundles ,
153- outFileNames ,
154- fedOptions ) ;
152+ packageInfos ,
153+ sharedBundles ,
154+ outFileNames ,
155+ fedOptions
156+ ) ;
155157
156158 const chunks = bundleResult . filter (
157- ( br ) => ! result . find ( ( r ) =>
158- r . outFileName === path . basename ( br . fileName ) )
159+ ( br ) => ! result . find ( ( r ) => r . outFileName === path . basename ( br . fileName ) )
159160 ) ;
160161
161162 addChunksToResult ( chunks , result , fedOptions . dev ) ;
@@ -169,7 +170,11 @@ export async function bundleShared(
169170 return result ;
170171}
171172
172- function copyCacheToOutput ( cachedFiles : string [ ] , cachePath : string , fullOutputPath : string ) {
173+ function copyCacheToOutput (
174+ cachedFiles : string [ ] ,
175+ cachePath : string ,
176+ fullOutputPath : string
177+ ) {
173178 for ( const fileName of cachedFiles ) {
174179 const cachedFile = path . join ( cachePath , fileName ) ;
175180 const distFileName = path . join ( fullOutputPath , fileName ) ;
@@ -178,7 +183,12 @@ function copyCacheToOutput(cachedFiles: string[], cachePath: string, fullOutputP
178183 }
179184}
180185
181- function createOutName ( pi : PackageInfo , configState : string , fedOptions : FederationOptions , encName : string ) {
186+ function createOutName (
187+ pi : PackageInfo ,
188+ configState : string ,
189+ fedOptions : FederationOptions ,
190+ encName : string
191+ ) {
182192 const hashBase = pi . version + '_' + pi . entryPoint + '_' + configState ;
183193 const hash = calcHash ( hashBase ) ;
184194
@@ -188,15 +198,29 @@ function createOutName(pi: PackageInfo, configState: string, fedOptions: Federat
188198 return outName ;
189199}
190200
191- function createCacheFileName ( configState : string , sharedBundles : Record < string , NormalizedSharedConfig > , fedOptions : FederationOptions , cachePath : string , platform : string ) {
201+ function createCacheFileName (
202+ configState : string ,
203+ sharedBundles : Record < string , NormalizedSharedConfig > ,
204+ fedOptions : FederationOptions ,
205+ cachePath : string ,
206+ platform : string
207+ ) {
192208 const resultCacheState = configState + JSON . stringify ( sharedBundles ) ;
193209 const resultHash = calcHash ( resultCacheState ) ;
194210 const dev = fedOptions . dev ? '-dev' : '' ;
195- const resultCacheFile = path . join ( cachePath , 'result-' + resultHash + '-' + platform + dev + '.json' ) ;
211+ const resultCacheFile = path . join (
212+ cachePath ,
213+ 'result-' + resultHash + '-' + platform + dev + '.json'
214+ ) ;
196215 return resultCacheFile ;
197216}
198217
199- function buildResult ( packageInfos : PackageInfo [ ] , sharedBundles : Record < string , NormalizedSharedConfig > , outFileNames : string [ ] , fedOptions : FederationOptions ) {
218+ function buildResult (
219+ packageInfos : PackageInfo [ ] ,
220+ sharedBundles : Record < string , NormalizedSharedConfig > ,
221+ outFileNames : string [ ] ,
222+ fedOptions : FederationOptions
223+ ) {
200224 return packageInfos . map ( ( pi ) => {
201225 const shared = sharedBundles [ pi . packageName ] ;
202226 return {
@@ -209,13 +233,17 @@ function buildResult(packageInfos: PackageInfo[], sharedBundles: Record<string,
209233 dev : ! fedOptions . dev
210234 ? undefined
211235 : {
212- entryPoint : normalize ( pi . entryPoint ) ,
213- } ,
236+ entryPoint : normalize ( pi . entryPoint ) ,
237+ } ,
214238 } as SharedInfo ;
215239 } ) ;
216240}
217241
218- function addChunksToResult ( chunks : BuildResult [ ] , result : SharedInfo [ ] , dev ?: boolean ) {
242+ function addChunksToResult (
243+ chunks : BuildResult [ ] ,
244+ result : SharedInfo [ ] ,
245+ dev ?: boolean
246+ ) {
219247 for ( const item of chunks ) {
220248 const fileName = path . basename ( item . fileName ) ;
221249 result . push ( {
@@ -228,8 +256,8 @@ function addChunksToResult(chunks: BuildResult[], result: SharedInfo[], dev?: bo
228256 dev : dev
229257 ? undefined
230258 : {
231- entryPoint : normalize ( fileName ) ,
232- } ,
259+ entryPoint : normalize ( fileName ) ,
260+ } ,
233261 } ) ;
234262 }
235263}
@@ -246,7 +274,6 @@ function calcHash(hashBase: string) {
246274 return hash ;
247275}
248276
249-
250277function copyFileIfExists ( cachedFile : string , fullOutputPath : string ) {
251278 fs . mkdirSync ( path . dirname ( fullOutputPath ) , { recursive : true } ) ;
252279
0 commit comments