@@ -95,9 +95,8 @@ export async function bundleShared(
95
95
platform,
96
96
} ) ;
97
97
98
- const cachedFiles = bundleResult . map ( br => path . basename ( br . fileName ) ) ;
98
+ const cachedFiles = bundleResult . map ( ( br ) => path . basename ( br . fileName ) ) ;
99
99
copyCacheToOutput ( cachedFiles , cachePath , fullOutputPath ) ;
100
-
101
100
} catch ( e ) {
102
101
logger . error ( 'Error bundling shared npm package ' ) ;
103
102
if ( e instanceof Error ) {
@@ -131,31 +130,33 @@ export async function bundleShared(
131
130
}
132
131
133
132
const resultCacheFile = createCacheFileName (
134
- configState ,
135
- sharedBundles ,
136
- fedOptions ,
137
- cachePath ,
133
+ configState ,
134
+ sharedBundles ,
135
+ fedOptions ,
136
+ cachePath ,
138
137
platform
139
138
) ;
140
139
141
140
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 ;
146
147
}
147
148
148
149
const outFileNames = [ ...exptedResults ] ;
149
150
150
151
const result = buildResult (
151
- packageInfos ,
152
- sharedBundles ,
153
- outFileNames ,
154
- fedOptions ) ;
152
+ packageInfos ,
153
+ sharedBundles ,
154
+ outFileNames ,
155
+ fedOptions
156
+ ) ;
155
157
156
158
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 ) )
159
160
) ;
160
161
161
162
addChunksToResult ( chunks , result , fedOptions . dev ) ;
@@ -169,7 +170,11 @@ export async function bundleShared(
169
170
return result ;
170
171
}
171
172
172
- function copyCacheToOutput ( cachedFiles : string [ ] , cachePath : string , fullOutputPath : string ) {
173
+ function copyCacheToOutput (
174
+ cachedFiles : string [ ] ,
175
+ cachePath : string ,
176
+ fullOutputPath : string
177
+ ) {
173
178
for ( const fileName of cachedFiles ) {
174
179
const cachedFile = path . join ( cachePath , fileName ) ;
175
180
const distFileName = path . join ( fullOutputPath , fileName ) ;
@@ -178,7 +183,12 @@ function copyCacheToOutput(cachedFiles: string[], cachePath: string, fullOutputP
178
183
}
179
184
}
180
185
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
+ ) {
182
192
const hashBase = pi . version + '_' + pi . entryPoint + '_' + configState ;
183
193
const hash = calcHash ( hashBase ) ;
184
194
@@ -188,15 +198,29 @@ function createOutName(pi: PackageInfo, configState: string, fedOptions: Federat
188
198
return outName ;
189
199
}
190
200
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
+ ) {
192
208
const resultCacheState = configState + JSON . stringify ( sharedBundles ) ;
193
209
const resultHash = calcHash ( resultCacheState ) ;
194
210
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
+ ) ;
196
215
return resultCacheFile ;
197
216
}
198
217
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
+ ) {
200
224
return packageInfos . map ( ( pi ) => {
201
225
const shared = sharedBundles [ pi . packageName ] ;
202
226
return {
@@ -209,13 +233,17 @@ function buildResult(packageInfos: PackageInfo[], sharedBundles: Record<string,
209
233
dev : ! fedOptions . dev
210
234
? undefined
211
235
: {
212
- entryPoint : normalize ( pi . entryPoint ) ,
213
- } ,
236
+ entryPoint : normalize ( pi . entryPoint ) ,
237
+ } ,
214
238
} as SharedInfo ;
215
239
} ) ;
216
240
}
217
241
218
- function addChunksToResult ( chunks : BuildResult [ ] , result : SharedInfo [ ] , dev ?: boolean ) {
242
+ function addChunksToResult (
243
+ chunks : BuildResult [ ] ,
244
+ result : SharedInfo [ ] ,
245
+ dev ?: boolean
246
+ ) {
219
247
for ( const item of chunks ) {
220
248
const fileName = path . basename ( item . fileName ) ;
221
249
result . push ( {
@@ -228,8 +256,8 @@ function addChunksToResult(chunks: BuildResult[], result: SharedInfo[], dev?: bo
228
256
dev : dev
229
257
? undefined
230
258
: {
231
- entryPoint : normalize ( fileName ) ,
232
- } ,
259
+ entryPoint : normalize ( fileName ) ,
260
+ } ,
233
261
} ) ;
234
262
}
235
263
}
@@ -246,7 +274,6 @@ function calcHash(hashBase: string) {
246
274
return hash ;
247
275
}
248
276
249
-
250
277
function copyFileIfExists ( cachedFile : string , fullOutputPath : string ) {
251
278
fs . mkdirSync ( path . dirname ( fullOutputPath ) , { recursive : true } ) ;
252
279
0 commit comments