Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Dillon Nys committed Jun 28, 2023
1 parent 2640ad0 commit 189b230
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
8 changes: 2 additions & 6 deletions packages/aft/lib/src/commands/bootstrap_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ const amplifyEnvironments = <String, String>{};
// 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'],
Expand Down
21 changes: 20 additions & 1 deletion packages/aft/lib/src/models/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ class AftComponent with AWSSerializable<Map<String, Object?>>, AWSDebuggable {
/// {@endtemplate}
@yamlSerializable
class PackageInfo
with AWSSerializable<Map<String, Object?>>, AWSDebuggable
with
AWSEquatable<PackageInfo>,
AWSSerializable<Map<String, Object?>>,
AWSDebuggable
implements Comparable<PackageInfo> {
/// {@macro amplify_tools.package_info}
const PackageInfo({
Expand Down Expand Up @@ -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();
Expand All @@ -261,6 +277,9 @@ class PackageInfo
flavor == PackageFlavor.flutter;
}

@override
List<Object?> get props => [name];

@override
int compareTo(PackageInfo other) {
return path.compareTo(other.path);
Expand Down
18 changes: 14 additions & 4 deletions packages/aft/lib/src/repo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PackageInfo, List<PackageInfo>> getPackageGraph({
bool includeDevDependencies = false,
}) =>
Expand All @@ -114,8 +114,18 @@ class Repo {
///
/// Provides a mapping from each packages to the packages which directly
/// depend on it.
late final Map<PackageInfo, List<PackageInfo>> reversedPackageGraph = () {
final packageGraph = this.packageGraph;
late final Map<PackageInfo, List<PackageInfo>> reversedPackageGraph =
getReversedPackageGraph();

/// Returns the directed graph of packages to the packages which depend on it.
///
/// Will include dev dependencies if [includeDevDependencies] is `true`.
Map<PackageInfo, List<PackageInfo>> getReversedPackageGraph({
bool includeDevDependencies = false,
}) {
final packageGraph = getPackageGraph(
includeDevDependencies: includeDevDependencies,
);
final reversedPackageGraph = <PackageInfo, List<PackageInfo>>{
for (final package in allPackages.values) package: [],
};
Expand All @@ -125,7 +135,7 @@ class Repo {
}
}
return UnmodifiableMapView(reversedPackageGraph);
}();
}

/// The git diff between [oldTree] and [newTree].
///
Expand Down

0 comments on commit 189b230

Please sign in to comment.