@@ -38,6 +38,7 @@ import {
38
38
import { RebuildEvents , RebuildHubs } from './rebuild-events' ;
39
39
40
40
import JSON5 from 'json5' ;
41
+ import { isDeepStrictEqual } from 'node:util' ;
41
42
42
43
export type MemResultHandler = (
43
44
outfiles : esbuild . OutputFile [ ] ,
@@ -352,13 +353,37 @@ function createTsConfigForFederation(
352
353
353
354
const tsconfigFedPath = path . join ( tsconfigDir , 'tsconfig.federation.json' ) ;
354
355
355
- if ( ! doesFileExist ( tsconfigFedPath , content ) ) {
356
+ if ( ! doesFileExistAndJsonEqual ( tsconfigFedPath , content ) ) {
356
357
fs . writeFileSync ( tsconfigFedPath , JSON . stringify ( tsconfig , null , 2 ) ) ;
357
358
}
358
359
tsConfigPath = tsconfigFedPath ;
359
360
return tsConfigPath ;
360
361
}
361
362
363
+ /**
364
+ * Checks if a file exists and if its content is equal to the provided content.
365
+ * If the file does not exist, it returns false.
366
+ * If the file or its content is invalid JSON, it returns false.
367
+ * @param {string } path - The path to the file
368
+ * @param {string } content - The content to compare with
369
+ * @returns {boolean } - Returns true if the file exists and its content is equal to the provided content
370
+ */
371
+ function doesFileExistAndJsonEqual ( path : string , content : string ) {
372
+ if ( ! fs . existsSync ( path ) ) {
373
+ return false ;
374
+ }
375
+
376
+ try {
377
+ const currentContent = fs . readFileSync ( path , 'utf-8' ) ;
378
+ const currentJson = JSON5 . parse ( currentContent ) ;
379
+ const newJson = JSON5 . parse ( content ) ;
380
+
381
+ return isDeepStrictEqual ( currentJson , newJson ) ;
382
+ } catch ( _error ) {
383
+ return false ;
384
+ }
385
+ }
386
+
362
387
function doesFileExist ( path : string , content : string ) : boolean {
363
388
if ( ! fs . existsSync ( path ) ) {
364
389
return false ;
0 commit comments