Skip to content

Commit 02543da

Browse files
authored
Merge pull request microsoft#390 from Microsoft/pgonzal/rush-stack-overflow
Fix "rush rebuild" a stack overflow error when a cyclic dependency is encountered
2 parents b8cce0c + 87bfe8d commit 02543da

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎apps/rush/src/taskRunner/TaskRunner.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)