Skip to content

Commit b69317b

Browse files
Merge pull request #820 from kettei-sproutty/fix/tailwindv4-loop
fix: compare tsconfig.federation.json using isDeepStrictEqual
2 parents 8d166c8 + dd6f013 commit b69317b

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

libs/native-federation/src/utils/angular-esbuild-adapter.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
import { RebuildEvents, RebuildHubs } from './rebuild-events';
3939

4040
import JSON5 from 'json5';
41+
import { isDeepStrictEqual } from 'node:util';
4142

4243
export type MemResultHandler = (
4344
outfiles: esbuild.OutputFile[],
@@ -352,13 +353,37 @@ function createTsConfigForFederation(
352353

353354
const tsconfigFedPath = path.join(tsconfigDir, 'tsconfig.federation.json');
354355

355-
if (!doesFileExist(tsconfigFedPath, content)) {
356+
if (!doesFileExistAndJsonEqual(tsconfigFedPath, content)) {
356357
fs.writeFileSync(tsconfigFedPath, JSON.stringify(tsconfig, null, 2));
357358
}
358359
tsConfigPath = tsconfigFedPath;
359360
return tsConfigPath;
360361
}
361362

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+
362387
function doesFileExist(path: string, content: string): boolean {
363388
if (!fs.existsSync(path)) {
364389
return false;

0 commit comments

Comments
 (0)