@@ -101,6 +101,8 @@ export default class TaskRunner {
101101 this . _currentActiveTasks = 0 ;
102102 console . log ( `Executing a maximum of ${ this . _parallelism } simultaneous processes...${ os . EOL } ` ) ;
103103
104+ this . _checkForCyclicDependencies ( this . _tasks . values ( ) , [ ] ) ;
105+
104106 // Precalculate the number of dependent packages
105107 this . _tasks . forEach ( ( task : ITask ) => {
106108 this . _calculateCriticalPaths ( task ) ;
@@ -280,10 +282,27 @@ export default class TaskRunner {
280282 }
281283
282284 /**
283- * Calculate the number of packages which must be build before we reach
285+ * Checks for projects that indirectly depend on themselves.
286+ */
287+ private _checkForCyclicDependencies ( tasks : Iterable < ITask > , dependencyChain : string [ ] ) : void {
288+ for ( const task of tasks ) {
289+ if ( dependencyChain . indexOf ( task . name ) >= 0 ) {
290+ throw new Error ( 'A cyclic dependency was encountered:\n'
291+ + ' ' + [ ...dependencyChain , task . name ] . reverse ( ) . join ( '\n -> ' )
292+ + '\nConsider using the cyclicDependencyProjects option for rush.json.' ) ;
293+ }
294+ dependencyChain . push ( task . name ) ;
295+ this . _checkForCyclicDependencies ( task . dependents , dependencyChain ) ;
296+ dependencyChain . pop ( ) ;
297+ }
298+ }
299+
300+ /**
301+ * Calculate the number of packages which must be built before we reach
284302 * the furthest away "root" node
285303 */
286304 private _calculateCriticalPaths ( task : ITask ) : number {
305+
287306 // Return the memoized value
288307 if ( task . criticalPathLength !== undefined ) {
289308 return task . criticalPathLength ;
0 commit comments