From 189b230031a505e7172f5dcf8fff98c54f198917 Mon Sep 17 00:00:00 2001 From: Dillon Nys Date: Tue, 27 Jun 2023 18:07:59 -0700 Subject: [PATCH] Clean up --- .../lib/src/commands/bootstrap_command.dart | 8 ++----- packages/aft/lib/src/models/config.dart | 21 ++++++++++++++++++- packages/aft/lib/src/repo.dart | 18 ++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/packages/aft/lib/src/commands/bootstrap_command.dart b/packages/aft/lib/src/commands/bootstrap_command.dart index f982ab2cb6..5de7afda28 100644 --- a/packages/aft/lib/src/commands/bootstrap_command.dart +++ b/packages/aft/lib/src/commands/bootstrap_command.dart @@ -79,12 +79,8 @@ const amplifyEnvironments = {}; // command is significantly newer/older than the embedded one. (pkg) => pkg.name != 'aft', ) - .expand( - (pkg) => [ - pkg, - if (pkg.example case final example?) example, - ], - ); + .expand((pkg) => [pkg, pkg.example]) + .nonNulls; for (final package in bootstrapPackages) { await pubAction( arguments: [if (upgrade) 'upgrade' else 'get'], diff --git a/packages/aft/lib/src/models/config.dart b/packages/aft/lib/src/models/config.dart index 9e1cd9aa40..d565b875a0 100644 --- a/packages/aft/lib/src/models/config.dart +++ b/packages/aft/lib/src/models/config.dart @@ -116,7 +116,10 @@ class AftComponent with AWSSerializable>, AWSDebuggable { /// {@endtemplate} @yamlSerializable class PackageInfo - with AWSSerializable>, AWSDebuggable + with + AWSEquatable, + AWSSerializable>, + AWSDebuggable implements Comparable { /// {@macro amplify_tools.package_info} const PackageInfo({ @@ -237,6 +240,19 @@ class PackageInfo return found; } + /// Whether [package] has `this` as a direct or transitive dependency. + bool isDependedOnBy(PackageInfo package, Repo repo) { + var found = false; + dfs( + repo.getReversedPackageGraph(includeDevDependencies: true), + root: this, + (pkg) { + if (pkg == package) found = true; + }, + ); + return found; + } + /// The parsed `CHANGELOG.md`. Changelog get changelog { final changelogMd = File(p.join(path, 'CHANGELOG.md')).readAsStringSync(); @@ -261,6 +277,9 @@ class PackageInfo flavor == PackageFlavor.flutter; } + @override + List get props => [name]; + @override int compareTo(PackageInfo other) { return path.compareTo(other.path); diff --git a/packages/aft/lib/src/repo.dart b/packages/aft/lib/src/repo.dart index 0245c2a924..0d3ba0139b 100644 --- a/packages/aft/lib/src/repo.dart +++ b/packages/aft/lib/src/repo.dart @@ -90,7 +90,7 @@ class Repo { /// Returns the directed graph of packages to the packages it depends on. /// - /// Will include dev dependencies if [includeDevDependencies] is true. + /// Will include dev dependencies if [includeDevDependencies] is `true`. Map> getPackageGraph({ bool includeDevDependencies = false, }) => @@ -114,8 +114,18 @@ class Repo { /// /// Provides a mapping from each packages to the packages which directly /// depend on it. - late final Map> reversedPackageGraph = () { - final packageGraph = this.packageGraph; + late final Map> reversedPackageGraph = + getReversedPackageGraph(); + + /// Returns the directed graph of packages to the packages which depend on it. + /// + /// Will include dev dependencies if [includeDevDependencies] is `true`. + Map> getReversedPackageGraph({ + bool includeDevDependencies = false, + }) { + final packageGraph = getPackageGraph( + includeDevDependencies: includeDevDependencies, + ); final reversedPackageGraph = >{ for (final package in allPackages.values) package: [], }; @@ -125,7 +135,7 @@ class Repo { } } return UnmodifiableMapView(reversedPackageGraph); - }(); + } /// The git diff between [oldTree] and [newTree]. ///