Skip to content

Commit a1e7450

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 a1e7450

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-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: 6 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,12 @@ 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.`);
9597
} else if (!existsSync(goldenFile)) {
9698
Log.error(`x Could not find golden file: ${goldenFile}`);
9799
return 1;
@@ -116,7 +118,7 @@ export function main(
116118
Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
117119
}
118120

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

@@ -143,7 +145,7 @@ export function main(
143145

144146
if (approveCommand) {
145147
Log.info(yellow(` Please approve the new golden with: ${approveCommand}`));
146-
} else {
148+
} else if (goldenFile) {
147149
Log.info(
148150
yellow(
149151
` Please update the golden. The following command can be ` +

0 commit comments

Comments
 (0)