Skip to content

Commit b52f05e

Browse files
committed
feat(ng-dev/ts-circular-dependencies): make golden file optional
The framework repo currently has no circular dependencies and does not allow new ones. This change makes the golden file optional so that framework can remove its empty golden file & associated pullapprove config
1 parent c3f52e5 commit b52f05e

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface CircularDependenciesTestConfig extends CircularDependenciesPars
2323
/** Base directory used for shortening paths in the golden file. */
2424
baseDir: string;
2525
/** Path to the golden file that is used for checking and approving. */
26-
goldenFile: string;
26+
goldenFile?: string;
2727
/** Glob that resolves source files which should be checked. */
2828
glob: string;
2929
/**
@@ -81,7 +81,7 @@ export async function loadTestConfig(configPath: string): Promise<CircularDepend
8181
if (!isAbsolute(config.baseDir)) {
8282
config.baseDir = resolveRelativePath(config.baseDir);
8383
}
84-
if (!isAbsolute(config.goldenFile)) {
84+
if (config.goldenFile && !isAbsolute(config.goldenFile)) {
8585
config.goldenFile = resolveRelativePath(config.goldenFile);
8686
}
8787
if (!isAbsolute(config.glob)) {

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {existsSync, readFileSync, writeFileSync} from 'fs';
1010
import {isAbsolute, relative, resolve} from 'path';
1111
import {Argv} from 'yargs';
1212

13-
import ts from 'typescript';
1413
import {globSync} from 'fast-glob';
14+
import ts from 'typescript';
1515

1616
import {green, Log, yellow} from '../utils/logging.js';
1717

@@ -88,10 +88,13 @@ export function main(
8888

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

91-
if (approve) {
91+
if (goldenFile && approve) {
9292
writeFileSync(goldenFile, JSON.stringify(actual, null, 2));
9393
Log.info(green('✔ Updated golden file.'));
9494
return 0;
95+
} else if (!goldenFile) {
96+
Log.error(`x Circular dependency goldens are not allowed.`);
97+
return 1;
9598
} else if (!existsSync(goldenFile)) {
9699
Log.error(`x Could not find golden file: ${goldenFile}`);
97100
return 1;
@@ -116,7 +119,7 @@ export function main(
116119
Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
117120
}
118121

119-
const expected = JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden;
122+
const expected = goldenFile ? (JSON.parse(readFileSync(goldenFile, 'utf8')) as Golden) : [];
120123
const {fixedCircularDeps, newCircularDeps} = compareGoldens(actual, expected);
121124
const isMatching = fixedCircularDeps.length === 0 && newCircularDeps.length === 0;
122125

@@ -143,7 +146,7 @@ export function main(
143146

144147
if (approveCommand) {
145148
Log.info(yellow(` Please approve the new golden with: ${approveCommand}`));
146-
} else {
149+
} else if (goldenFile) {
147150
Log.info(
148151
yellow(
149152
` Please update the golden. The following command can be ` +

0 commit comments

Comments
 (0)