Skip to content

Commit 0ad6a37

Browse files
committed
refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check (#2611)
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. PR Close #2611
1 parent 25e3ba3 commit 0ad6a37

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

ng-dev/ts-circular-dependencies/index.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,6 @@ export function main(
8888

8989
Log.info(green(` Current number of cycles: ${yellow(cycles.length.toString())}`));
9090

91-
if (goldenFile && approve) {
92-
writeFileSync(goldenFile, JSON.stringify(actual, null, 2));
93-
Log.info(green('✔ Updated golden file.'));
94-
return 0;
95-
} else if (!goldenFile) {
96-
Log.error(`x Circular dependency goldens are not allowed.`);
97-
return 1;
98-
} else if (!existsSync(goldenFile)) {
99-
Log.error(`x Could not find golden file: ${goldenFile}`);
100-
return 1;
101-
}
102-
10391
const warningsCount = analyzer.unresolvedFiles.size + analyzer.unresolvedModules.size;
10492

10593
// By default, warnings for unresolved files or modules are not printed. This is because
@@ -119,6 +107,33 @@ export function main(
119107
Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
120108
}
121109

110+
if (goldenFile === undefined) {
111+
if (approve) {
112+
Log.error(
113+
`x Cannot approve circular depdencies within this repository as no golden file exists.`,
114+
);
115+
return 1;
116+
}
117+
if (cycles.length > 0) {
118+
Log.error(`x No circular dependencies are allow within this repository.`);
119+
return 1;
120+
}
121+
122+
Log.info(green('✔ No circular dependencies found in this repository.'));
123+
return 0;
124+
}
125+
126+
if (approve) {
127+
writeFileSync(goldenFile, JSON.stringify(actual, null, 2));
128+
Log.info(green('✔ Updated golden file.'));
129+
return 0;
130+
}
131+
132+
if (!existsSync(goldenFile)) {
133+
Log.error(`x Could not find golden file: ${goldenFile}`);
134+
return 1;
135+
}
136+
122137
const expected = goldenFile ? (JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden) : [];
123138
const {fixedCircularDeps, newCircularDeps} = compareGoldens(actual, expected);
124139
const isMatching = fixedCircularDeps.length === 0 && newCircularDeps.length === 0;

0 commit comments

Comments
 (0)