Skip to content

Commit 4def209

Browse files
authored
fix: Fixed versioning for nested version fields (#831)
<!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Description As discussed in Discord I have modified the `_setPubspecVersionForPackage` method to allow for nested versions to be updated. Context: https://discord.com/channels/295953187817521152/1059839794760392734/1326708821808119870 ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [ ] ✨ `feat` -- New feature (non-breaking change which adds functionality) - [x] 🛠️ `fix` -- Bug fix (non-breaking change which fixes an issue) - [ ] ❌ `!` -- Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 `refactor` -- Code refactor - [ ] ✅ `ci` -- Build configuration change - [ ] 📝 `docs` -- Documentation - [ ] 🗑️ `chore` -- Chore
1 parent 1e33cb4 commit 4def209

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

packages/melos/lib/src/commands/version.dart

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,35 @@ mixin _VersionMixin on _RunMixin {
432432
final pubspec = pubspecPathForDirectory(package.path);
433433
final contents = await readTextFileAsync(pubspec);
434434

435-
final updatedContents =
436-
contents.replaceAllMapped(versionReplaceRegex, (match) {
437-
return '${match.group(1)}$version${match.group(3)}';
438-
});
435+
final editor = YamlEditor(contents);
436+
437+
var updatedContents = contents;
438+
439+
for (final dependencyType in ['dependencies', 'dev_dependencies']) {
440+
final dependencySection = editor.parseAt(
441+
[dependencyType],
442+
orElse: () => wrapAsYamlNode(null),
443+
);
444+
445+
if (dependencySection.value == null) continue;
446+
447+
final packageNode = editor.parseAt(
448+
[dependencyType, package.name],
449+
orElse: () => wrapAsYamlNode(null),
450+
);
451+
452+
if (packageNode.value == null) continue;
453+
454+
if (packageNode is YamlMap) {
455+
// Handle nested version case.
456+
editor.update([dependencyType, package.name, 'version'], version);
457+
} else {
458+
// Handle inline version case.
459+
editor.update([dependencyType, package.name], version);
460+
}
461+
462+
updatedContents = editor.toString();
463+
}
439464

440465
// Sanity check that contents actually changed.
441466
if (contents == updatedContents) {

0 commit comments

Comments
 (0)