Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon authored Jan 9, 2025
2 parents 2544d8d + 4def209 commit 8c7084a
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions packages/melos/lib/src/commands/version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,35 @@ mixin _VersionMixin on _RunMixin {
final pubspec = pubspecPathForDirectory(package.path);
final contents = await readTextFileAsync(pubspec);

final updatedContents =
contents.replaceAllMapped(versionReplaceRegex, (match) {
return '${match.group(1)}$version${match.group(3)}';
});
final editor = YamlEditor(contents);

var updatedContents = contents;

for (final dependencyType in ['dependencies', 'dev_dependencies']) {
final dependencySection = editor.parseAt(
[dependencyType],
orElse: () => wrapAsYamlNode(null),
);

if (dependencySection.value == null) continue;

final packageNode = editor.parseAt(
[dependencyType, package.name],
orElse: () => wrapAsYamlNode(null),
);

if (packageNode.value == null) continue;

if (packageNode is YamlMap) {
// Handle nested version case.
editor.update([dependencyType, package.name, 'version'], version);
} else {
// Handle inline version case.
editor.update([dependencyType, package.name], version);
}

updatedContents = editor.toString();
}

// Sanity check that contents actually changed.
if (contents == updatedContents) {
Expand Down

0 comments on commit 8c7084a

Please sign in to comment.