Skip to content

Commit 80cd383

Browse files
committed
chore(aft): Follow Dart SemVer strategy
Use build tag (`+`) for patch releases.
1 parent a48bab8 commit 80cd383

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

packages/aft/lib/src/models.dart

+32-9
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,11 @@ extension AmplifyVersion on Version {
227227

228228
/// The next version according to Amplify rules for incrementing.
229229
Version nextAmplifyVersion(VersionBumpType type) {
230+
final newBuild = (build.singleOrNull as int? ?? 0) + 1;
230231
if (preRelease.isEmpty) {
231232
switch (type) {
232233
case VersionBumpType.patch:
233-
return nextPatch;
234+
return major == 0 ? replace(build: [newBuild]) : nextPatch;
234235
case VersionBumpType.nonBreaking:
235236
return major == 0 ? nextPatch : nextMinor;
236237
case VersionBumpType.breaking:
@@ -240,14 +241,7 @@ extension AmplifyVersion on Version {
240241
if (type == VersionBumpType.breaking) {
241242
return nextPreRelease;
242243
}
243-
final newBuild = (build.singleOrNull as int? ?? 0) + 1;
244-
return Version(
245-
major,
246-
minor,
247-
patch,
248-
pre: preRelease.join('.'),
249-
build: '$newBuild',
250-
);
244+
return replace(build: [newBuild]);
251245
}
252246

253247
/// The constraint to use for this version in pubspecs.
@@ -269,6 +263,35 @@ extension AmplifyVersion on Version {
269263
}
270264
return '>=$minVersion <$maxVersion';
271265
}
266+
267+
/// Creates a copy of this version with the given fields replaced.
268+
Version replace({
269+
int? major,
270+
int? minor,
271+
int? patch,
272+
List<Object>? preRelease,
273+
List<Object>? build,
274+
}) {
275+
String? pre;
276+
if (preRelease != null) {
277+
pre = preRelease.join('.');
278+
} else if (this.preRelease.isNotEmpty) {
279+
pre = this.preRelease.join('.');
280+
}
281+
String? buildString;
282+
if (build != null) {
283+
buildString = build.join('.');
284+
} else if (this.build.isNotEmpty) {
285+
buildString = this.build.join('.');
286+
}
287+
return Version(
288+
major ?? this.major,
289+
minor ?? this.minor,
290+
patch ?? this.patch,
291+
pre: pre,
292+
build: buildString,
293+
);
294+
}
272295
}
273296

274297
enum DependencyType {

packages/aft/test/model_test.dart

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ void main() {
2424
final version = Version(0, 1, 0);
2525

2626
final patch = version.nextAmplifyVersion(VersionBumpType.patch);
27-
expect(patch, Version(0, 1, 1));
27+
expect(patch, Version(0, 1, 0, build: '1'));
2828
expect(proagation.propagateToComponent(version, patch), false);
2929

30+
final nextPatch = patch.nextAmplifyVersion(VersionBumpType.patch);
31+
expect(nextPatch, Version(0, 1, 0, build: '2'));
32+
expect(proagation.propagateToComponent(version, nextPatch), false);
33+
3034
final nonBreaking =
3135
version.nextAmplifyVersion(VersionBumpType.nonBreaking);
3236
expect(nonBreaking, Version(0, 1, 1));

0 commit comments

Comments
 (0)