Skip to content

Commit 24b9ba8

Browse files
authored
fix(repo_manage): increment patch version when transitioning to -wip (#474)
Fixes the version downgrade that occurs when transitioning from a stable version to a WIP version. Previously, appended directly to a stable version string (e.g., -> ). Because pub considers pre-release suffixes strictly older than their stable counterparts, this caused the version to downgrade in pub's view. Now, it increments the patch version first (e.g., -> ) before appending .
1 parent e1d4a04 commit 24b9ba8

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

‎pkgs/repo_manage/lib/changelog_updater.dart‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@ import 'package:path/path.dart' as path;
99

1010
import 'src/common.dart';
1111

12+
String _incrementPatch(String version) {
13+
final parts = version.split('.');
14+
if (parts.length >= 3) {
15+
final patchStr = parts[2].split('-').first.split('+').first;
16+
if (int.tryParse(patchStr) case final patchNum?) {
17+
final newPatchStr = (patchNum + 1).toString();
18+
parts[2] = parts[2].replaceFirst(patchStr, newPatchStr);
19+
return parts.join('.');
20+
}
21+
}
22+
return version;
23+
}
24+
1225
void updatePubspecVersion(File pubspecFile, String newVersion) {
1326
final content = pubspecFile.readAsStringSync();
1427
final lines = LineSplitter.split(content).toList();
@@ -64,7 +77,7 @@ void updateChangelog({
6477
output.addAll(lines.skip(sectionEnd));
6578
} else {
6679
output.addAll([
67-
'## $currentVersion-wip',
80+
'## ${_incrementPatch(currentVersion)}-wip',
6881
'',
6982
'- $message',
7083
'',
@@ -75,7 +88,7 @@ void updateChangelog({
7588
changelogFile.writeAsStringSync('${output.join('\n')}\n');
7689

7790
if (!isWip) {
78-
final newVersion = '$currentVersion-wip';
91+
final newVersion = '${_incrementPatch(currentVersion)}-wip';
7992
final changelogDir = path.dirname(changelogFile.path);
8093
final pubspecFile = File(path.join(changelogDir, 'pubspec.yaml'));
8194
if (pubspecFile.existsSync()) {

‎pkgs/repo_manage/test/changelog_updater_test.dart‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
@TestOn('vm')
2+
library;
3+
14
// Copyright (c) 2026, the Dart project authors. Please see the AUTHORS file
25
// for details. All rights reserved. Use of this source code is governed by a
36
// BSD-style license that can be found in the LICENSE file.
@@ -94,7 +97,7 @@ version: 1.0.0
9497
updateChangelog(changelogFile: changelogFile, message: 'New WIP change');
9598

9699
expect(changelogFile.readAsStringSync(), '''
97-
## 1.0.0-wip
100+
## 1.0.1-wip
98101
99102
- New WIP change
100103
@@ -105,7 +108,7 @@ version: 1.0.0
105108

106109
expect(pubspecFile.readAsStringSync(), '''
107110
name: my_package
108-
version: 1.0.0-wip
111+
version: 1.0.1-wip
109112
''');
110113
});
111114

@@ -116,7 +119,7 @@ version: 1.0.0-wip
116119
final pubspecFile = File('${tempDir.path}/pubspec.yaml');
117120

118121
changelogFile.writeAsStringSync('''
119-
## 1.0.0-wip
122+
## 1.0.1-wip
120123
121124
- WIP change
122125
@@ -126,14 +129,14 @@ version: 1.0.0-wip
126129
''');
127130
pubspecFile.writeAsStringSync('''
128131
name: my_package
129-
version: 1.0.0-wip
132+
version: 1.0.1-wip
130133
''');
131134

132135
updateChangelog(
133136
changelogFile: changelogFile, message: 'Another WIP change');
134137

135138
expect(changelogFile.readAsStringSync(), '''
136-
## 1.0.0-wip
139+
## 1.0.1-wip
137140
138141
- WIP change
139142
- Another WIP change
@@ -145,7 +148,7 @@ version: 1.0.0-wip
145148

146149
expect(pubspecFile.readAsStringSync(), '''
147150
name: my_package
148-
version: 1.0.0-wip
151+
version: 1.0.1-wip
149152
''');
150153
});
151154
});

‎pkgs/repo_manage/test/data/golden/changelog_complex_timezone.golden‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.11.1-wip
1+
## 0.11.2-wip
22

33
- Add new feature
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.0.1-wip
1+
## 0.0.2-wip
22

33
- Initial entry
44

‎pkgs/repo_manage/test/data/golden/changelog_release.golden‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.2.3-wip
1+
## 1.2.4-wip
22

33
- Fix regression
44

0 commit comments

Comments
 (0)