Skip to content

Commit dcc6eea

Browse files
committed
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.
1 parent 89fd28e commit dcc6eea

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

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

Lines changed: 28 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,34 @@ export function main(
119107
Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
120108
}
121109

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

0 commit comments

Comments
 (0)