read static method
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 = resolvedPubFile(projectRoot, 'package_graph.json');
if (file == null) return null;
final json = readJsonFile(file);
if (json is! Map) return null;
final nodes = <String, GraphNode>{};
for (final p in jsonList(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 jsonList(p['dependencies'])) '$d'],
[for (final d in jsonList(p['devDependencies'])) '$d'],
);
}
return PackageGraph([for (final r in jsonList(json['roots'])) '$r'], nodes);
}