MCPcopy Create free account
hub / github.com/angular/dev-infra / main

Function main

ng-dev/ts-circular-dependencies/index.ts:65–179  ·  view source on GitHub ↗
(
  approve: boolean,
  config: CircularDependenciesTestConfig,
  printWarnings: boolean,
)

Source from the content-addressed store, hash-verified

63 * @returns Status code.
64 */
65export function main(
66 approve: boolean,
67 config: CircularDependenciesTestConfig,
68 printWarnings: boolean,
69): number {
70 const {
71 baseDir,
72 goldenFile,
73 glob: globPattern,
74 resolveModule,
75 approveCommand,
76 ignoreTypeOnlyChecks,
77 } = config;
78 const analyzer = new Analyzer(resolveModule, ignoreTypeOnlyChecks);
79 const cycles: ReferenceChain[] = [];
80 const checkedNodes = new WeakSet<ts.SourceFile>();
81
82 glob
83 .globSync(globPattern, {absolute: true, ignore: ['**/node_modules/**']})
84 .forEach((filePath) => {
85 const sourceFile = analyzer.getSourceFile(filePath);
86 cycles.push(...analyzer.findCycles(sourceFile, checkedNodes));
87 });
88
89 const actual = convertReferenceChainToGolden(cycles, baseDir);
90
91 Log.info(green(` Current number of cycles: ${yellow(cycles.length.toString())}`));
92
93 const warningsCount = analyzer.unresolvedFiles.size + analyzer.unresolvedModules.size;
94
95 // By default, warnings for unresolved files or modules are not printed. This is because
96 // it's common that third-party modules are not resolved/visited. Also generated files
97 // from the View Engine compiler (i.e. factories, summaries) cannot be resolved.
98 if (printWarnings && warningsCount !== 0) {
99 Log.info(yellow('⚠ The following imports could not be resolved:'));
100 Array.from(analyzer.unresolvedModules)
101 .sort()
102 .forEach((specifier) => Log.info(` • ${specifier}`));
103 analyzer.unresolvedFiles.forEach((value, key) => {
104 Log.info(` • ${getRelativePath(baseDir, key)}`);
105 value.sort().forEach((specifier) => Log.info(` ${specifier}`));
106 });
107 } else {
108 Log.warn(`⚠ ${warningsCount} imports could not be resolved.`);
109 Log.warn(` Please rerun with "--warnings" to inspect unresolved imports.`);
110 }
111
112 if (goldenFile === undefined) {
113 if (approve) {
114 Log.error(
115 `x Cannot approve circular depdencies within this repository as no golden file exists.`,
116 );
117 return 1;
118 }
119 if (cycles.length > 0) {
120 Log.error(
121 `x No circular dependencies are allow within this repository, but circular dependencies were found:`,
122 );

Callers 1

Calls 10

getSourceFileMethod · 0.95
findCyclesMethod · 0.95
getRelativePathFunction · 0.85
compareGoldensFunction · 0.85
pushMethod · 0.45
toStringMethod · 0.45
errorMethod · 0.45
stringifyMethod · 0.45

Tested by

no test coverage detected