parsePackageConfig function
Parse the package config of the given directory.
Throws if the parsing fails, such as if the file is badly formatted or does not exists.
Implementation
Future<PackageConfig> parsePackageConfig(Directory directory) async {
var packageConfigFile = directory.packageConfig;
if (!packageConfigFile.existsSync()) {
final workspaceRefFile = directory.workspaceRef;
final content = workspaceRefFile.readAsStringSync();
final json = jsonDecode(content) as Map<String, dynamic>;
final workspaceRoot = json['workspaceRoot'] as String;
final workspacePath =
normalize(join(workspaceRefFile.parent.path, workspaceRoot));
final workspaceDir = Directory(workspacePath);
packageConfigFile = workspaceDir.packageConfig;
}
return PackageConfig.parseBytes(
await packageConfigFile.readAsBytes(),
packageConfigFile.uri,
);
}