Topological sort of packages