From dcc6eeaf8aba0f5097a8cf20f64cb7c14c7517a0 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Wed, 19 Feb 2025 17:49:05 +0000 Subject: [PATCH 1/3] refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check Move the warnings processing before the initial processing of golden file and approval to always include its output. Additionally, provide alternate text output for approval attempts when no golden exists. --- ng-dev/ts-circular-dependencies/index.ts | 40 +++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/ng-dev/ts-circular-dependencies/index.ts b/ng-dev/ts-circular-dependencies/index.ts index 7ac05908e..809271b56 100644 --- a/ng-dev/ts-circular-dependencies/index.ts +++ b/ng-dev/ts-circular-dependencies/index.ts @@ -88,18 +88,6 @@ export function main( Log.info(green(` Current number of cycles: ${yellow(cycles.length.toString())}`)); - if (goldenFile && approve) { - writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); - Log.info(green('✔ Updated golden file.')); - return 0; - } else if (!goldenFile) { - Log.error(`x Circular dependency goldens are not allowed.`); - return 1; - } else if (!existsSync(goldenFile)) { - Log.error(`x Could not find golden file: ${goldenFile}`); - return 1; - } - const warningsCount = analyzer.unresolvedFiles.size + analyzer.unresolvedModules.size; // By default, warnings for unresolved files or modules are not printed. This is because @@ -119,6 +107,34 @@ export function main( Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`); } + if (goldenFile) { + // Golden file exists + if (approve) { + writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); + Log.info(green('✔ Updated golden file.')); + return 0; + } + if (!existsSync(goldenFile)) { + Log.error(`x Could not find golden file: ${goldenFile}`); + return 1; + } + } else { + if (approve) { + Log.error( + `x Cannot approve circular depdencies within this repository as no golden file exists.`, + ); + return 1; + } + // No golden file exists + if (cycles.length > 0) { + Log.error(`x No circular dependencies are allow within this repository.`); + return 1; + } + + Log.info(green('✔ No circular dependencies found in this repository.')); + return 0; + } + const expected = goldenFile ? (JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden) : []; const {fixedCircularDeps, newCircularDeps} = compareGoldens(actual, expected); const isMatching = fixedCircularDeps.length === 0 && newCircularDeps.length === 0; From a237354dbe9f970ea9e6a1669582fa7c079d36bb Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Wed, 19 Feb 2025 18:20:26 +0000 Subject: [PATCH 2/3] fixup! refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check --- ng-dev/ts-circular-dependencies/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-dev/ts-circular-dependencies/index.ts b/ng-dev/ts-circular-dependencies/index.ts index 809271b56..36dcdb565 100644 --- a/ng-dev/ts-circular-dependencies/index.ts +++ b/ng-dev/ts-circular-dependencies/index.ts @@ -119,13 +119,13 @@ export function main( return 1; } } else { + // No golden file exists if (approve) { Log.error( `x Cannot approve circular depdencies within this repository as no golden file exists.`, ); return 1; } - // No golden file exists if (cycles.length > 0) { Log.error(`x No circular dependencies are allow within this repository.`); return 1; From c7a1a848f0abafebe754e6abe1f751e206fd2715 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Wed, 19 Feb 2025 18:23:29 +0000 Subject: [PATCH 3/3] fixup! refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check --- ng-dev/ts-circular-dependencies/index.ts | 25 ++++++++++++------------ 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/ng-dev/ts-circular-dependencies/index.ts b/ng-dev/ts-circular-dependencies/index.ts index 36dcdb565..79dfe1225 100644 --- a/ng-dev/ts-circular-dependencies/index.ts +++ b/ng-dev/ts-circular-dependencies/index.ts @@ -107,19 +107,7 @@ export function main( Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`); } - if (goldenFile) { - // Golden file exists - if (approve) { - writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); - Log.info(green('✔ Updated golden file.')); - return 0; - } - if (!existsSync(goldenFile)) { - Log.error(`x Could not find golden file: ${goldenFile}`); - return 1; - } - } else { - // No golden file exists + if (goldenFile === undefined) { if (approve) { Log.error( `x Cannot approve circular depdencies within this repository as no golden file exists.`, @@ -135,6 +123,17 @@ export function main( return 0; } + if (approve) { + writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); + Log.info(green('✔ Updated golden file.')); + return 0; + } + + if (!existsSync(goldenFile)) { + Log.error(`x Could not find golden file: ${goldenFile}`); + return 1; + } + const expected = goldenFile ? (JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden) : []; const {fixedCircularDeps, newCircularDeps} = compareGoldens(actual, expected); const isMatching = fixedCircularDeps.length === 0 && newCircularDeps.length === 0;