@@ -51,7 +51,7 @@ class AddRuntimeRequiremetToPromiseExternal {
51
51
compiler . hooks . compilation . tap (
52
52
"AddRuntimeRequiremetToPromiseExternal" ,
53
53
compilation => {
54
- const { RuntimeGlobals} = compiler . webpack ;
54
+ const { RuntimeGlobals } = compiler . webpack ;
55
55
if ( compilation . outputOptions . trustedTypes ) {
56
56
compilation . hooks . additionalModuleRuntimeRequirements . tap (
57
57
"AddRuntimeRequiremetToPromiseExternal" ,
@@ -83,7 +83,7 @@ class FederationDashboardPlugin {
83
83
*/
84
84
constructor ( options ) {
85
85
this . _options = Object . assign (
86
- { debug : false , filename : "dashboard.json" , fetchClient : false } ,
86
+ { debug : false , filename : "dashboard.json" , fetchClient : false } ,
87
87
options
88
88
) ;
89
89
this . _dashData = null ;
@@ -125,6 +125,7 @@ class FederationDashboardPlugin {
125
125
"__REMOTE_VERSION__" ,
126
126
""
127
127
) ;
128
+
128
129
compiler . hooks . thisCompilation . tap ( PLUGIN_NAME , compilation => {
129
130
compilation . hooks . processAssets . tapPromise (
130
131
{
@@ -195,14 +196,18 @@ class FederationDashboardPlugin {
195
196
if ( graphData ) {
196
197
const dashData = ( this . _dashData = JSON . stringify ( graphData ) ) ;
197
198
198
- if ( this . _options . dashboardURL && ! this . _options . nextjs ) {
199
- this . postDashboardData ( dashData ) . catch ( err => {
200
- if ( err ) {
201
- curCompiler . errors . push ( err ) ;
202
- // eslint-disable-next-line promise/no-callback-in-promise
203
- throw err ;
204
- }
205
- } ) ;
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
+ }
206
211
}
207
212
208
213
return Promise . resolve ( ) . then ( ( ) => {
@@ -248,6 +253,7 @@ class FederationDashboardPlugin {
248
253
typeof rawData . version === "string"
249
254
? `_${ rawData . version . split ( "." ) . join ( "_" ) } `
250
255
: `_${ rawData . version . toString ( ) } ` ;
256
+
251
257
let codeSource ;
252
258
if ( ! remoteEntry . source . _value && remoteEntry . source . source ) {
253
259
codeSource = remoteEntry . source . source ( ) ;
@@ -311,7 +317,7 @@ class FederationDashboardPlugin {
311
317
const stringifiableChunk = Array . from ( subset ) . map ( sub => {
312
318
const cleanSet = Object . getOwnPropertyNames ( sub ) . reduce ( ( acc , key ) => {
313
319
if ( key === "_groups" ) return acc ;
314
- return Object . assign ( acc , { [ key ] : sub [ key ] } ) ;
320
+ return Object . assign ( acc , { [ key ] : sub [ key ] } ) ;
315
321
} , { } ) ;
316
322
317
323
return this . mapToObjectRec ( cleanSet ) ;
@@ -422,9 +428,9 @@ class FederationDashboardPlugin {
422
428
if ( this . _options . filename ) {
423
429
const hashPath = path . join ( stats . outputPath , this . _options . filename ) ;
424
430
if ( ! fs . existsSync ( stats . outputPath ) ) {
425
- fs . mkdirSync ( stats . outputPath , { recursive : true } ) ;
431
+ fs . mkdirSync ( stats . outputPath , { recursive : true } ) ;
426
432
}
427
- fs . writeFileSync ( hashPath , dashData , { encoding : "utf-8" } ) ;
433
+ fs . writeFileSync ( hashPath , dashData , { encoding : "utf-8" } ) ;
428
434
}
429
435
if ( this . _options . debug ) {
430
436
console . log (
@@ -436,7 +442,7 @@ class FederationDashboardPlugin {
436
442
try {
437
443
file = assets [ this . FederationPluginOptions . filename ] . _value ;
438
444
439
- const { version} = JSON . parse ( dashData ) ;
445
+ const { version } = JSON . parse ( dashData ) ;
440
446
if ( ! version ) {
441
447
throw new Error ( "no version provided, cannot version remote" ) ;
442
448
}
@@ -451,7 +457,7 @@ class FederationDashboardPlugin {
451
457
}
452
458
fs . mkdir (
453
459
path . join ( stats . outputPath , version ) ,
454
- { recursive : true } ,
460
+ { recursive : true } ,
455
461
err => {
456
462
if ( err ) throw err ;
457
463
fs . writeFile (
@@ -485,16 +491,26 @@ class FederationDashboardPlugin {
485
491
fs . writeFile (
486
492
statsPath ,
487
493
JSON . stringify ( stats ) ,
488
- { encoding : "utf-8" } ,
494
+ { encoding : "utf-8" } ,
489
495
( ) => {
490
496
}
491
497
) ;
492
498
}
499
+ }
493
500
501
+ class NextMedusaPlugin {
502
+ constructor ( options ) {
503
+ this . _options = options ;
504
+ if ( this . _options . debug ) {
505
+ console . log ( "NextMedusaPlugin constructor" , options ) ;
506
+ }
507
+ }
494
508
async postDashboardData ( dashData ) {
509
+
495
510
if ( ! this . _options . dashboardURL ) {
496
511
return Promise . resolve ( ) ;
497
512
}
513
+
498
514
const client = this . _options . fetchClient
499
515
? this . _options . fetchClient
500
516
: fetch ;
@@ -509,22 +525,15 @@ class FederationDashboardPlugin {
509
525
} ) ;
510
526
511
527
if ( ! res . ok ) throw new Error ( res . statusText ) ;
528
+
529
+ return res
512
530
} catch ( err ) {
513
531
console . warn (
514
532
`Error posting data to dashboard URL: ${ this . _options . dashboardURL } `
515
533
) ;
516
534
console . error ( err ) ;
517
535
}
518
536
}
519
- }
520
-
521
- class NextMedusaPlugin {
522
- constructor ( options ) {
523
- this . _options = options ;
524
- if ( this . _options . debug ) {
525
- console . log ( "medusa plugin constructor" , options ) ;
526
- }
527
- }
528
537
529
538
apply ( compiler ) {
530
539
if (
@@ -560,40 +569,39 @@ class NextMedusaPlugin {
560
569
nextjs : true
561
570
} ) . apply ( compiler ) ;
562
571
563
- return ;
572
+ const hostData = path . join (
573
+ compiler . options . output . path ,
574
+ compiler . options . name + "-" + filename
575
+ ) ;
564
576
compiler . hooks . done . tap ( PLUGIN_NAME , ( ) => {
565
- const sidecarData = path . join (
566
- compiler . options . output . path ,
567
- `child-dashboard.json`
568
- ) ;
569
- const hostData = path . join (
570
- compiler . options . output . path ,
571
- "dashboard.json"
572
- ) ;
573
- console . log ( "sidecar data" , sidecarData ) ;
574
- console . log ( "host data" , hostData ) ;
575
- if ( fs . existsSync ( sidecarData ) && fs . existsSync ( hostData ) ) {
576
- console . log ( "will write merged files" ) ;
577
+ if ( fs . existsSync ( hostData ) ) {
577
578
fs . writeFileSync (
578
579
hostData ,
579
- JSON . stringify ( mergeGraphs ( require ( sidecarData ) , require ( hostData ) ) )
580
+ JSON . stringify ( require ( hostData ) )
580
581
) ;
581
582
}
582
583
} ) ;
583
584
584
- compiler . hooks . afterDone . tap ( "NextMedusaPlugin" , ( stats , done ) => {
585
- if ( fs . existsSync ( sidecarData ) && fs . existsSync ( hostData ) ) {
585
+ compiler . hooks . afterDone . tap ( "NextMedusaPlugin" , ( stats ) => {
586
+ if ( fs . existsSync ( hostData ) ) {
586
587
const dashboardData = fs . readFileSync ( hostData , "utf8" ) ;
587
- MedusaPlugin . postDashboardData ( dashboardData )
588
- . then ( done )
589
- . catch ( done ) ;
590
- } else {
591
- done ( ) ;
588
+ if ( this . _options . skipPost ) {
589
+ console . info ( 'Skipping post to dashboard' )
590
+ } else {
591
+ this . postDashboardData ( dashboardData )
592
+ . then ( ( ) => {
593
+ console . info ( 'Data has been successfully sent to the dashboard' )
594
+ } )
595
+ . catch ( ( error ) => {
596
+ console . error ( 'Failed to send data to the dashboard:' , error )
597
+ } ) ;
598
+ }
592
599
}
593
600
} ) ;
601
+
594
602
}
595
603
}
596
604
597
605
module . exports = FederationDashboardPlugin ;
598
606
module . exports . clientVersion = require ( "./client-version" ) ;
599
- module . exports . NextMedusaPlugin = NextMedusaPlugin ;
607
+ module . exports . NextMedusaPlugin = NextMedusaPlugin ;
0 commit comments