Cycles In Imports

A monorepo has 400 modules and an import edge u → v when u imports v. You run Kahn's algorithm to get a compile order and it emits only 260 modules before the ready set goes empty, so the remaining 140 sit in import cycles.

You still need an order the compiler can follow. What do you do?

A

Condense the components, then break the cycles that remain in the condensation by hand when two components import each other.

B

Compute the strongly connected components and build the condensation, one vertex per component. The condensation is always acyclic, so topologically sort it and compile each component as a single unit.

C

Delete one edge from each cycle to make the graph acyclic, then run Kahn's algorithm again on the result.

D

Keep the 260 modules Kahn's emitted, then append the remaining 140 in any order at the end.