Open jart opened 8 years ago
I use TopoSort for this in closure-maven-plugin.
Oh my gosh thank you for sharing this @mikesamuel! That and CssDepGraph are really going to save me a lot of time.
Out of curiosity, is your checkForCycles() function guaranteed to halt? I'm not sure considering the way it's going back in there to try and find shorter cycles. But even if it weren't for that, I think the algorithm might still be O(2^|V|). I wrote a very elegant implementation last year of Tarjan's algorithm for finding strongly connected components. It's O(|V| + |E|) and returns the set of all cycles in the graph. Although in all fairness, SCC's are intuitively more like "tangled clusters" rather than cycles. You could display them all, or just the smallest one.
Edit: O(2^|V|) not O(|V|^2)
Ooh also you could probably use Sets.newIdentityHashSet()
for your seen
variable.
If stylesheets use
@provide
and@require
then it is possible for the compiler to put them back in the correct order. Closure Compiler has been able to do this with JS sources for at least a few years. I feel like this is important because it allows the build system to be more forgiving, if you do things like sort yoursrcs
list, or useglob(["*.css"])
rather than have a separateclosure_css_library
for each and every CSS file.I might be able to contribute this as a 20%er at some point in the future.