resolve method
Future<List<CascadingImpact> >
resolve({
- required String packageName,
- required String targetVersion,
- required PubspecData currentPubspec,
Check for cascading impacts of upgrading packageName to
targetVersion.
Process:
- Fetch the target version's pubspec from pub.dev.
- Collect its declared dependencies and their version constraints.
- Compare each constraint against the version currently resolved in the project's lockfile / pubspec.
- Report any dependency whose current resolved version does not satisfy the target's constraint as a CascadingImpact.
Implementation
Future<List<CascadingImpact>> resolve({
required String packageName,
required String targetVersion,
required PubspecData currentPubspec,
}) async {
final impacts = <CascadingImpact>[];
try {
// Fetch the pubspec of the version we want to upgrade to.
final targetPubspec = await _pubApi.getVersionPubspec(
packageName,
targetVersion,
);
if (targetPubspec == null) {
Logger.warn(
'CascadeResolver: could not fetch pubspec for '
'$packageName@$targetVersion',
);
return impacts;
}
final targetDeps =
targetPubspec['dependencies'] as Map<String, dynamic>? ?? {};
for (final entry in targetDeps.entries) {
final depName = entry.key;
final constraint = _extractConstraint(entry.value);
if (constraint == null) continue;
// Look up the dependency in the current project.
final currentDep = currentPubspec.dependencies[depName] ??
currentPubspec.devDependencies[depName];
// If the project does not use this dependency at all it will be
// pulled in transitively — no conflict.
if (currentDep == null || currentDep.resolvedVersion == null) continue;
final currentVersion = currentDep.resolvedVersion!;
// Check if the currently resolved version satisfies the target's
// constraint.
if (!_versionResolver.satisfies(currentVersion, constraint)) {
impacts.add(CascadingImpact(
dependencyName: depName,
requiredBy: '$packageName@$targetVersion',
currentConstraint: currentVersion,
conflictReason:
'Requires $depName $constraint but current version '
'is $currentVersion',
));
}
}
} catch (e, st) {
Logger.warn(
'Failed to resolve cascading impacts for $packageName: $e',
);
Logger.debug('Stack trace: $st');
}
if (impacts.isNotEmpty) {
Logger.info(
'CascadeResolver: found ${impacts.length} cascading impact(s) '
'for $packageName@$targetVersion',
);
}
return impacts;
}