-
Notifications
You must be signed in to change notification settings - Fork 59
refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check #2611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(ng-dev/ts-circular-dependencies): reorder processing of warnings and golden existence check #2611
Changes from all commits
dcc6eea
a237354
c7a1a84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,33 @@ export function main( | |
| Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`); | ||
| } | ||
|
|
||
| if (goldenFile === undefined) { | ||
| if (approve) { | ||
| Log.error( | ||
| `x Cannot approve circular depdencies within this repository as no golden file exists.`, | ||
| ); | ||
| return 1; | ||
| } | ||
| 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; | ||
| } | ||
|
|
||
| if (approve) { | ||
| writeFileSync(goldenFile, JSON.stringify(actual, null, 2)); | ||
| Log.info(green('✔ Updated golden file.')); | ||
| return 0; | ||
| } | ||
|
|
||
| if (!existsSync(goldenFile)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't this always exist after writing before?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The file would only be guaranteed to be written to, if an approval happened. If its a regular check, then it wouldn't be written in the block above, and could technically not exist. We verify it exists because just below here we read from it to do the actual comparison. |
||
| 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; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be outside? What if there is a
goldenFileand cycles?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is within the
goldenFilebeingundefinedso there is no golden file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But shouldn't this fail? if there are cycles and
goldenFilebeing!== undefined?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it will happen automatically below with the comparison. That's the thing I missed. Very confusing :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the case where there is no golden file, and there are cycles here. This fails as it returns a
1as the exit code.For cases where there is a golden file to do the comparison to later, we check the specifics.