Skip to content

Commit

Permalink
fix!: avoid false negatives when the current version is a pre-release…
Browse files Browse the repository at this point in the history
… and there is a prior stable release on pub (#42)

Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
  • Loading branch information
renancaraujo and wolfenrain committed Apr 11, 2023
1 parent 21bfe5a commit 0a14ccd
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/src/pub_updater.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:io';

import 'package:http/http.dart' as http;
import 'package:process/process.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:pub_updater/src/models/models.dart';

/// Exception thrown when the HTTP request fails.
Expand Down Expand Up @@ -36,6 +37,15 @@ class PubUpdater {
}) async {
final latestVersion = await getLatestVersion(packageName);

final currentVersionDesc = Version.parse(currentVersion);
final latestVersionDesc = Version.parse(latestVersion);

if (!latestVersionDesc.isPreRelease && currentVersionDesc.isPreRelease) {
// If the current version is a pre-release but the latest isn't,
// skip the version checking.
return true;
}

return currentVersion == latestVersion;
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies:
http: ^0.13.3
json_annotation: ^4.1.0
process: ^4.2.3
pub_semver: ^2.1.3

dev_dependencies:
build_runner: ^2.1.2
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/fixtures.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export 'pre_release_package_info_response.dart';
export 'valid_package_info_response.dart';

0 comments on commit 0a14ccd

Please sign in to comment.