getOutdatedDependencies function
list outdated dependencies and ignores minor patch updates
Implementation
Future<OutdatedDependencies> getOutdatedDependencies(String pubspecPath) async {
File file = File(pubspecPath);
if (!file.existsSync()) {
throw Exception('File not found: $pubspecPath');
}
String yamlString = file.readAsStringSync();
Map yaml = loadYaml(yamlString);
YamlMap dependencies = yaml['dependencies'];
final outdated = <String, DependencyVersion>{};
for (final dependency in dependencies.keys) {
print('checking dependency: $dependency');
if (dependencies[dependency] is YamlMap) {
continue;
}
var isUpToDate = await _isUpToDate(
dependency,
dependencies[dependency],
);
final lastVersion = await pubUpdater.getLatestVersion(dependency);
final currentVersion = dependencies[dependency];
final currentVersionDesc = Version.parse(parseVersion(currentVersion));
final latestVersionDesc = Version.parse(parseVersion(lastVersion));
final hasMinorPatchOnly =
latestVersionDesc.major == currentVersionDesc.major &&
latestVersionDesc.minor == currentVersionDesc.minor &&
latestVersionDesc.patch != currentVersionDesc.patch &&
currentVersion.startsWith('^');
if (hasMinorPatchOnly) {
isUpToDate = true;
}
if (!isUpToDate) {
outdated.putIfAbsent(
dependency,
() => DependencyVersion(
current: currentVersion,
latest: lastVersion,
),
);
}
}
return OutdatedDependencies(
dependencies: outdated,
);
}