Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mzdm committed Jun 4, 2024
1 parent 7f42a86 commit d2cda00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
19 changes: 8 additions & 11 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ mixin _VersionMixin on _RunMixin {
);

for (final package in dependentPackagesToVersion) {
// If updateDependentsVersions is set to false, we do not perform updates.
if (!updateDependentsVersions) {
continue;
}

final packageHasPendingUpdate = pendingPackageUpdates.any(
(packageToVersion) => packageToVersion.package.name == package.name,
);
Expand Down Expand Up @@ -309,15 +314,10 @@ mixin _VersionMixin on _RunMixin {
return;
}

final pendingPackageUpdatesCount = updateDependentsVersions
? pendingPackageUpdates.length
: pendingPackageUpdates
.where((update) => update.reason != PackageUpdateReason.dependency)
.length;
logger.log(
AnsiStyles.magentaBright(
'The following '
'${packageNameStyle(pendingPackageUpdatesCount.toString())} '
'${packageNameStyle(pendingPackageUpdates.length.toString())} '
'packages will be updated:\n',
),
);
Expand Down Expand Up @@ -704,7 +704,6 @@ mixin _VersionMixin on _RunMixin {
workspace,
changelogConfig,
pendingPackageUpdates,
updateDependentsVersions: updateDependentsVersions,
);
}),
);
Expand All @@ -714,9 +713,8 @@ mixin _VersionMixin on _RunMixin {
Future<void> _writeAggregateChangelog(
MelosWorkspace workspace,
AggregateChangelogConfig config,
List<MelosPendingPackageUpdate> pendingPackageUpdates, {
required bool updateDependentsVersions,
}) async {
List<MelosPendingPackageUpdate> pendingPackageUpdates,
) async {
final today = DateTime.now();
final dateSlug = [
today.year.toString(),
Expand All @@ -738,7 +736,6 @@ mixin _VersionMixin on _RunMixin {
pendingPackageUpdates,
logger,
config.path,
updateDependentsVersions: updateDependentsVersions,
);

await changelog.write();
Expand Down
21 changes: 6 additions & 15 deletions packages/melos/lib/src/common/aggregate_changelog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@ class AggregateChangelog {
this.newEntryTitle,
this.pendingPackageUpdates,
this.logger,
this.path, {
required this.updateDependentsVersions,
});
this.path,
);

final MelosWorkspace workspace;
final String? description;
final String newEntryTitle;
final MelosLogger logger;
final List<MelosPendingPackageUpdate> pendingPackageUpdates;
final String path;
final bool updateDependentsVersions;

String get _changelogFileHeader => '''
# Change Log
Expand All @@ -46,21 +44,14 @@ ${description?.withoutTrailing('\n') ?? ''}

String get markdown {
final body = StringBuffer();
final dependencyOnlyPackages = updateDependentsVersions
? pendingPackageUpdates
.where((update) => update.reason == PackageUpdateReason.dependency)
: <MelosPendingPackageUpdate>[];
final dependencyOnlyPackages = pendingPackageUpdates
.where((update) => update.reason == PackageUpdateReason.dependency);
final graduatedPackages = pendingPackageUpdates
.where((update) => update.reason == PackageUpdateReason.graduate);
final packagesWithBreakingChanges =
pendingPackageUpdates.where((update) => update.hasBreakingChanges);
final packagesWithOtherChanges = pendingPackageUpdates.where((update) {
if (update.reason == PackageUpdateReason.dependency &&
!updateDependentsVersions) {
return false;
}
return !update.hasBreakingChanges;
});
final packagesWithOtherChanges =
pendingPackageUpdates.where((update) => !update.hasBreakingChanges);

body.writeln(_changelogFileHeader);
body.writeln('## $newEntryTitle');
Expand Down

0 comments on commit d2cda00

Please sign in to comment.