Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flutter-candidate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c2ea27002b9c4ab1aff1db6eb1960e4299aca369
a9f310a4c91a523c42495a4e528dad76048c01a5
18 changes: 16 additions & 2 deletions packages/devtools_shared/lib/src/utils/semantic_version.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ class SemanticVersion with CompareMixin<SemanticVersion> {
// 2.15.0-233.0.dev (dev) (Mon Oct 18 14:06:26 2021 -0700) on "ios_x64"
// 2.15.0-178.1.beta
// 2.6.0-12.0.pre.443
// 2.6.0-12.0.pre-443
//
// So split on the spaces to the version, and then on the dash char to
// First canonicalize the version string to convert any prerelease suffix
// with a "-" to a prerelease suffix with a ".".
final canonicalized = _canonicalizeVersion(versionString);
// Then split on the spaces to the version, and then on the dash char to
// separate the main semantic version from the pre release version.
final splitOnSpaces = versionString.split(' ');
final splitOnSpaces = canonicalized.split(' ');
final version = splitOnSpaces.first;
final splitOnDash = version.split('-');
assert(splitOnDash.length <= 2, 'version: $version');
Expand Down Expand Up @@ -115,6 +119,16 @@ class SemanticVersion with CompareMixin<SemanticVersion> {

int? preReleaseMinor;

static final _nonStandardPreReleaseVersionRegex = RegExp(r'(\.pre)-(\d+)$');

/// Canonicalizes a [semanticVersion] with a prerelease version suffix to use
/// a "." instead of a "-".
///
/// e.g. 2.6.0-12.0.pre-443 -> 2.6.0-12.0.pre.443
static String _canonicalizeVersion(String semanticVersion) =>
semanticVersion.replaceFirstMapped(_nonStandardPreReleaseVersionRegex,
(match) => '${match[1]}.${match[2]}');

bool get isPreRelease => preReleaseMajor != null || preReleaseMinor != null;

bool isSupported({required SemanticVersion minSupportedVersion}) =>
Expand Down
6 changes: 4 additions & 2 deletions packages/devtools_shared/test/semantic_version_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ void main() {
SemanticVersion.parse('2.6.0-12.0.pre.443').toString(),
equals('2.6.0-12.0'),
);

expect(
SemanticVersion.parse('2.6.0-1.2.dev+build.metadata').toString(),
equals('2.6.0-1.2'),
);

expect(
SemanticVersion.parse('2.6.0+build.metadata').toString(),
equals('2.6.0'),
);
expect(
SemanticVersion.parse('3.33.0-1.0.pre-1156').toString(),
equals('3.33.0-1.0'),
);
});

test('downgrade', () {
Expand Down
Loading