read static method
Implementation
static Pubspec? read(String packageDir) {
final file = File(p.join(packageDir, 'pubspec.yaml'));
if (!file.existsSync()) return null;
final doc = loadYaml(file.readAsStringSync());
if (doc is! YamlMap) return null;
final names = <String>{};
final runtime = <String>{};
final sdk = <String>{};
final paths = <String, String>{};
for (final block in const [
'dependencies',
'dev_dependencies',
'dependency_overrides',
]) {
final section = doc[block];
if (section is! YamlMap) continue;
for (final entry in section.entries) {
final name = entry.key.toString();
names.add(name);
if (block == 'dependencies') runtime.add(name);
final spec = entry.value;
if (spec is YamlMap && spec['path'] != null) {
paths[name] = p.normalize(
p.join(packageDir, spec['path'].toString()),
);
}
if (spec is YamlMap && spec['sdk'] != null) sdk.add(name);
}
}
return Pubspec._(
doc['name'].toString(),
packageDir,
names,
paths,
runtime,
sdk,
);
}