@@ -227,10 +227,11 @@ extension AmplifyVersion on Version {
227
227
228
228
/// The next version according to Amplify rules for incrementing.
229
229
Version nextAmplifyVersion (VersionBumpType type) {
230
+ final newBuild = (build.singleOrNull as int ? ?? 0 ) + 1 ;
230
231
if (preRelease.isEmpty) {
231
232
switch (type) {
232
233
case VersionBumpType .patch:
233
- return nextPatch;
234
+ return major == 0 ? replace (build : [newBuild]) : nextPatch;
234
235
case VersionBumpType .nonBreaking:
235
236
return major == 0 ? nextPatch : nextMinor;
236
237
case VersionBumpType .breaking:
@@ -240,14 +241,7 @@ extension AmplifyVersion on Version {
240
241
if (type == VersionBumpType .breaking) {
241
242
return nextPreRelease;
242
243
}
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]);
251
245
}
252
246
253
247
/// The constraint to use for this version in pubspecs.
@@ -269,6 +263,35 @@ extension AmplifyVersion on Version {
269
263
}
270
264
return '>=$minVersion <$maxVersion ' ;
271
265
}
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
+ }
272
295
}
273
296
274
297
enum DependencyType {
0 commit comments