read static method

PackageGraph? read(
  1. String projectRoot
)

The project's graph, or null when pub has not written one. For a member of a pub workspace it is the workspace's.

Implementation

static PackageGraph? read(String projectRoot) {
  final file = _resolvedFile(projectRoot, 'package_graph.json');
  if (file == null) return null;
  final json = _readJson(file);
  if (json is! Map) return null;
  final nodes = <String, GraphNode>{};
  for (final p in _list(json['packages'])) {
    if (p is! Map || p['name'] is! String) continue;
    final name = p['name'] as String;
    nodes[name] = GraphNode(
      name,
      Version.tryParse('${p['version'] ?? ''}'),
      [for (final d in _list(p['dependencies'])) '$d'],
      [for (final d in _list(p['devDependencies'])) '$d'],
    );
  }
  return PackageGraph._([for (final r in _list(json['roots'])) '$r'], nodes);
}