getPackageGraph function

Future<DirectedGraph<Package>> getPackageGraph(
  1. Directory root
)

Implementation

Future<DirectedGraph<Package>> getPackageGraph(Directory root) async {
  final vertices = await findPackages(root)
      .map((package) => Vertex<Package>(package))
      .toList();

  return DirectedGraph<Package>(
    {
      for (var vertex in vertices)
        vertex: vertex.data.pubspec.allDependencies.keys
            .map(
              (dep) => vertices.firstWhere(
                (v) => v.data.name == dep,
                orElse: () => null,
              ),
            )
            .where((v) => v != null)
            .toList(),
    },
    comparator: (
      Vertex<Package> vertex1,
      Vertex<Package> vertex2,
    ) =>
        vertex1.data.name.compareTo(vertex2.data.name),
  );
}