Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ng-dev/ts-circular-dependencies/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface CircularDependenciesTestConfig extends CircularDependenciesPars
/** Base directory used for shortening paths in the golden file. */
baseDir: string;
/** Path to the golden file that is used for checking and approving. */
goldenFile: string;
goldenFile?: string;
/** Glob that resolves source files which should be checked. */
glob: string;
/**
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function loadTestConfig(configPath: string): Promise<CircularDepend
if (!isAbsolute(config.baseDir)) {
config.baseDir = resolveRelativePath(config.baseDir);
}
if (!isAbsolute(config.goldenFile)) {
if (config.goldenFile && !isAbsolute(config.goldenFile)) {
config.goldenFile = resolveRelativePath(config.goldenFile);
}
if (!isAbsolute(config.glob)) {
Expand Down
11 changes: 7 additions & 4 deletions ng-dev/ts-circular-dependencies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {existsSync, readFileSync, writeFileSync} from 'fs';
import {isAbsolute, relative, resolve} from 'path';
import {Argv} from 'yargs';

import ts from 'typescript';
import {globSync} from 'fast-glob';
import ts from 'typescript';

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

Expand Down Expand Up @@ -88,10 +88,13 @@ export function main(

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

if (approve) {
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;
Expand All @@ -116,7 +119,7 @@ export function main(
Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
}

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

Expand All @@ -143,7 +146,7 @@ export function main(

if (approveCommand) {
Log.info(yellow(` Please approve the new golden with: ${approveCommand}`));
} else {
} else if (goldenFile) {
Log.info(
yellow(
` Please update the golden. The following command can be ` +
Expand Down
Loading