parse method
Parses the pubspec.yaml at filePath and returns a PubspecInfo.
Throws a FileSystemException when the file does not exist.
Implementation
Future<PubspecInfo> parse(String filePath) async {
final file = File(filePath);
if (!file.existsSync()) throw FileSystemException('not found', filePath);
final yaml = loadYaml(await file.readAsString()) as YamlMap;
final name = yaml['name'] as String? ?? 'unknown';
final lockPath = filePath.replaceFirst('pubspec.yaml', 'pubspec.lock');
final locked = await _readLock(lockPath);
final deps = _block(yaml['dependencies'], locked);
final devDeps = _block(yaml['dev_dependencies'], locked);
VersionConstraint? sdk;
final env = yaml['environment'];
if (env is YamlMap) {
try {
sdk = VersionConstraint.parse(env['sdk'] as String? ?? '');
} catch (_) {}
}
return PubspecInfo(
name: name,
dependencies: deps,
devDependencies: devDeps,
sdkConstraint: sdk,
path: filePath,
);
}