@@ -18,16 +18,14 @@ try {
18
18
console . error ( e ) ;
19
19
}
20
20
21
- const findPackageJson = filePath => {
21
+ const findPackageJson = ( filePath ) => {
22
22
if ( filePath . length === 0 ) {
23
23
return false ;
24
24
}
25
25
if ( fs . existsSync ( path . join ( filePath . join ( path . sep ) , "package.json" ) ) ) {
26
26
try {
27
27
return require ( path . join ( filePath . join ( path . sep ) , "package.json" ) ) ;
28
- } catch ( e ) {
29
-
30
- }
28
+ } catch ( e ) { }
31
29
}
32
30
33
31
filePath . pop ( ) ;
@@ -50,7 +48,7 @@ class AddRuntimeRequiremetToPromiseExternal {
50
48
apply ( compiler ) {
51
49
compiler . hooks . compilation . tap (
52
50
"AddRuntimeRequiremetToPromiseExternal" ,
53
- compilation => {
51
+ ( compilation ) => {
54
52
const { RuntimeGlobals } = compiler . webpack ;
55
53
if ( compilation . outputOptions . trustedTypes ) {
56
54
compilation . hooks . additionalModuleRuntimeRequirements . tap (
@@ -100,7 +98,7 @@ class FederationDashboardPlugin {
100
98
compiler . options . output . uniqueName = `v${ Date . now ( ) } ` ;
101
99
102
100
new AddRuntimeRequiremetToPromiseExternal ( ) . apply ( compiler ) ;
103
- const FederationPlugin = compiler . options . plugins . find ( plugin => {
101
+ const FederationPlugin = compiler . options . plugins . find ( ( plugin ) => {
104
102
return (
105
103
plugin . constructor . name === "ModuleFederationPlugin" ||
106
104
plugin . constructor . name === "NextFederationPlugin"
@@ -121,18 +119,16 @@ class FederationDashboardPlugin {
121
119
) ;
122
120
}
123
121
124
- this . FederationPluginOptions . name = this . FederationPluginOptions . name . replace (
125
- "__REMOTE_VERSION__" ,
126
- ""
127
- ) ;
122
+ this . FederationPluginOptions . name =
123
+ this . FederationPluginOptions . name . replace ( "__REMOTE_VERSION__" , "" ) ;
128
124
129
- compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , compilation => {
125
+ compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , ( compilation ) => {
130
126
compilation . hooks . processAssets . tapPromise (
131
127
{
132
128
name : PLUGIN_NAME ,
133
- stage : compilation . constructor . PROCESS_ASSETS_STAGE_REPORT
129
+ stage : compilation . constructor . PROCESS_ASSETS_STAGE_REPORT ,
134
130
} ,
135
- assets => {
131
+ ( assets ) => {
136
132
return this . processWebpackGraph ( compilation , assets ) ;
137
133
}
138
134
) ;
@@ -146,7 +142,7 @@ class FederationDashboardPlugin {
146
142
"process.dashboardURL" : JSON . stringify ( this . _options . dashboardURL ) ,
147
143
"process.env.CURRENT_HOST" : JSON . stringify (
148
144
this . FederationPluginOptions . name
149
- )
145
+ ) ,
150
146
} ) . apply ( compiler ) ;
151
147
}
152
148
}
@@ -182,7 +178,7 @@ class FederationDashboardPlugin {
182
178
sha : gitSha ,
183
179
modules : stats . modules ,
184
180
chunkDependencies,
185
- functionRemotes : this . allArgumentsUsed
181
+ functionRemotes : this . allArgumentsUsed ,
186
182
} ;
187
183
188
184
let graphData = null ;
@@ -196,18 +192,14 @@ class FederationDashboardPlugin {
196
192
if ( graphData ) {
197
193
const dashData = ( this . _dashData = JSON . stringify ( graphData ) ) ;
198
194
199
- if ( this . _options . skipPost ) {
200
- console . info ( 'Skipping post to dashboard' )
201
- } else {
202
- if ( this . _options . dashboardURL && ! this . _options . nextjs ) {
203
- this . postDashboardData ( dashData ) . catch ( err => {
204
- if ( err ) {
205
- curCompiler . errors . push ( err ) ;
206
- // eslint-disable-next-line promise/no-callback-in-promise
207
- throw err ;
208
- }
209
- } ) ;
210
- }
195
+ if ( this . _options . dashboardURL && ! this . _options . nextjs ) {
196
+ this . postDashboardData ( dashData ) . catch ( ( err ) => {
197
+ if ( err ) {
198
+ curCompiler . errors . push ( err ) ;
199
+ // eslint-disable-next-line promise/no-callback-in-promise
200
+ throw err ;
201
+ }
202
+ } ) ;
211
203
}
212
204
213
205
return Promise . resolve ( ) . then ( ( ) => {
@@ -219,7 +211,7 @@ class FederationDashboardPlugin {
219
211
} ,
220
212
size ( ) {
221
213
return statsBuf . length ;
222
- }
214
+ } ,
223
215
} ;
224
216
// for dashboard.json
225
217
if ( curCompiler . emitAsset && this . _options . filename ) {
@@ -306,15 +298,15 @@ class FederationDashboardPlugin {
306
298
}
307
299
308
300
getRemoteEntryChunk ( stats , FederationPluginOptions ) {
309
- return stats . chunks . find ( chunk =>
310
- chunk . names . find ( name => name === FederationPluginOptions . name )
301
+ return stats . chunks . find ( ( chunk ) =>
302
+ chunk . names . find ( ( name ) => name === FederationPluginOptions . name )
311
303
) ;
312
304
}
313
305
314
306
getChunkDependencies ( validChunkArray ) {
315
307
return validChunkArray . reduce ( ( acc , chunk ) => {
316
308
const subset = chunk . getAllReferencedChunks ( ) ;
317
- const stringifiableChunk = Array . from ( subset ) . map ( sub => {
309
+ const stringifiableChunk = Array . from ( subset ) . map ( ( sub ) => {
318
310
const cleanSet = Object . getOwnPropertyNames ( sub ) . reduce ( ( acc , key ) => {
319
311
if ( key === "_groups" ) return acc ;
320
312
return Object . assign ( acc , { [ key ] : sub [ key ] } ) ;
@@ -324,7 +316,7 @@ class FederationDashboardPlugin {
324
316
} ) ;
325
317
326
318
return Object . assign ( acc , {
327
- [ chunk . id ] : stringifiableChunk
319
+ [ chunk . id ] : stringifiableChunk ,
328
320
} ) ;
329
321
} , { } ) ;
330
322
}
@@ -346,23 +338,23 @@ class FederationDashboardPlugin {
346
338
packageJson,
347
339
// subPackages: this.directReasons(modules),
348
340
shareFrom : [ "dependencies" ] ,
349
- ignorePatchversion : false
341
+ ignorePatchversion : false ,
350
342
} ) ;
351
343
vendorFederation . devDependencies = AutomaticVendorFederation ( {
352
344
exclude : [ ] ,
353
345
ignoreVersion : false ,
354
346
packageJson,
355
347
// subPackages: this.directReasons(modules),
356
348
shareFrom : [ "devDependencies" ] ,
357
- ignorePatchversion : false
349
+ ignorePatchversion : false ,
358
350
} ) ;
359
351
vendorFederation . optionalDependencies = AutomaticVendorFederation ( {
360
352
exclude : [ ] ,
361
353
ignoreVersion : false ,
362
354
packageJson,
363
355
// subPackages: this.directReasons(modules),
364
356
shareFrom : [ "optionalDependencies" ] ,
365
- ignorePatchversion : false
357
+ ignorePatchversion : false ,
366
358
} ) ;
367
359
}
368
360
@@ -392,7 +384,7 @@ class FederationDashboardPlugin {
392
384
? namedChunkRefs . getAllReferencedChunks ( )
393
385
: [ ] ;
394
386
395
- AllReferencedChunksByRemote . forEach ( chunk => {
387
+ AllReferencedChunksByRemote . forEach ( ( chunk ) => {
396
388
if ( chunk . id !== FederationPluginOptions . name ) {
397
389
validChunkArray . push ( chunk ) ;
398
390
}
@@ -404,17 +396,19 @@ class FederationDashboardPlugin {
404
396
directReasons ( modules ) {
405
397
const directReasons = new Set ( ) ;
406
398
407
- modules . forEach ( module => {
399
+ modules . forEach ( ( module ) => {
408
400
if ( module . reasons ) {
409
- module . reasons . forEach ( reason => {
401
+ module . reasons . forEach ( ( reason ) => {
410
402
if ( reason . userRequest ) {
411
403
try {
412
404
// grab user required package.json
413
- const subsetPackage = require ( path . join ( reason . userRequest , "package.json" ) ) ;
405
+ const subsetPackage = require ( path . join (
406
+ reason . userRequest ,
407
+ "package.json"
408
+ ) ) ;
414
409
415
410
directReasons . add ( subsetPackage ) ;
416
- } catch ( e ) {
417
- }
411
+ } catch ( e ) { }
418
412
}
419
413
} ) ;
420
414
}
@@ -458,7 +452,7 @@ class FederationDashboardPlugin {
458
452
fs . mkdir (
459
453
path . join ( stats . outputPath , version ) ,
460
454
{ recursive : true } ,
461
- err => {
455
+ ( err ) => {
462
456
if ( err ) throw err ;
463
457
fs . writeFile (
464
458
path . join (
@@ -467,7 +461,7 @@ class FederationDashboardPlugin {
467
461
this . FederationPluginOptions . filename
468
462
) ,
469
463
file ,
470
- err => {
464
+ ( err ) => {
471
465
if ( this . _options . debug ) {
472
466
console . trace ( err ) ;
473
467
console . log (
@@ -492,8 +486,7 @@ class FederationDashboardPlugin {
492
486
statsPath ,
493
487
JSON . stringify ( stats ) ,
494
488
{ encoding : "utf-8" } ,
495
- ( ) => {
496
- }
489
+ ( ) => { }
497
490
) ;
498
491
}
499
492
}
@@ -506,7 +499,6 @@ class NextMedusaPlugin {
506
499
}
507
500
}
508
501
async postDashboardData ( dashData ) {
509
-
510
502
if ( ! this . _options . dashboardURL ) {
511
503
return Promise . resolve ( ) ;
512
504
}
@@ -520,13 +512,13 @@ class NextMedusaPlugin {
520
512
body : dashData ,
521
513
headers : {
522
514
Accept : "application/json" ,
523
- "Content-type" : "application/json"
524
- }
515
+ "Content-type" : "application/json" ,
516
+ } ,
525
517
} ) ;
526
518
527
519
if ( ! res . ok ) throw new Error ( res . statusText ) ;
528
520
529
- return res
521
+ return res ;
530
522
} catch ( err ) {
531
523
console . warn (
532
524
`Error posting data to dashboard URL: ${ this . _options . dashboardURL } `
@@ -566,7 +558,7 @@ class NextMedusaPlugin {
566
558
new FederationDashboardPlugin ( {
567
559
...this . _options ,
568
560
filename : compiler . options . name + "-" + filename ,
569
- nextjs : true
561
+ nextjs : true ,
570
562
} ) . apply ( compiler ) ;
571
563
572
564
const hostData = path . join (
@@ -575,33 +567,29 @@ class NextMedusaPlugin {
575
567
) ;
576
568
compiler . hooks . done . tap ( PLUGIN_NAME , ( ) => {
577
569
if ( fs . existsSync ( hostData ) ) {
578
- fs . writeFileSync (
579
- hostData ,
580
- JSON . stringify ( require ( hostData ) )
581
- ) ;
570
+ fs . writeFileSync ( hostData , JSON . stringify ( require ( hostData ) ) ) ;
582
571
}
583
572
} ) ;
584
573
585
574
compiler . hooks . afterDone . tap ( "NextMedusaPlugin" , ( stats ) => {
586
575
if ( fs . existsSync ( hostData ) ) {
587
576
const dashboardData = fs . readFileSync ( hostData , "utf8" ) ;
588
577
if ( this . _options . skipPost ) {
589
- console . info ( ' Skipping post to dashboard' )
578
+ console . info ( " Skipping post to dashboard" ) ;
590
579
} else {
591
580
this . postDashboardData ( dashboardData )
592
581
. then ( ( ) => {
593
- console . info ( ' Data has been successfully sent to the dashboard' )
582
+ console . info ( " Data has been successfully sent to the dashboard" ) ;
594
583
} )
595
584
. catch ( ( error ) => {
596
- console . error ( ' Failed to send data to the dashboard:' , error )
585
+ console . error ( " Failed to send data to the dashboard:" , error ) ;
597
586
} ) ;
598
587
}
599
588
}
600
589
} ) ;
601
-
602
590
}
603
591
}
604
592
605
593
module . exports = FederationDashboardPlugin ;
606
594
module . exports . clientVersion = require ( "./client-version" ) ;
607
- module . exports . NextMedusaPlugin = NextMedusaPlugin ;
595
+ module . exports . NextMedusaPlugin = NextMedusaPlugin ;
0 commit comments