diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 6e6e6b9eeb..dbdbb39cf8 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,7 +1,8 @@ -## 5.8.2-wip +## 5.8.2 - Added new event `Event.analyticsException` to track internal errors for this package - Redirecting the `Analytics.test` factory to return an instance of `FakeAnalytics` +- Exposing new helper function that can be used to parse the Dart SDK version ## 5.8.1 diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index 77c8892d6c..cc7137997a 100644 --- a/pkgs/unified_analytics/lib/src/constants.dart +++ b/pkgs/unified_analytics/lib/src/constants.dart @@ -82,7 +82,7 @@ const int kLogFileLength = 2500; const String kLogFileName = 'dart-flutter-telemetry.log'; /// The current version of the package, should be in line with pubspec version. -const String kPackageVersion = '5.8.2-wip'; +const String kPackageVersion = '5.8.2'; /// The minimum length for a session. const int kSessionDurationMinutes = 30; diff --git a/pkgs/unified_analytics/lib/src/utils.dart b/pkgs/unified_analytics/lib/src/utils.dart index 3044a50ad9..55b59f3502 100644 --- a/pkgs/unified_analytics/lib/src/utils.dart +++ b/pkgs/unified_analytics/lib/src/utils.dart @@ -215,6 +215,34 @@ bool legacyOptOut({required FileSystem fs, required Directory home}) { return false; } +/// Helper method that can be used to resolve the Dart SDK version for clients +/// of package:unified_analytics. +/// +/// Input [versionString] for this method should be the returned string from +/// [io.Platform.version]. +/// +/// For tools that don't already have a method for resolving the Dart +/// SDK version in semver notation, this helper can be used. This uses +/// the [io.Platform.version] to parse the semver. +/// +/// Example for stable version: +/// `3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64"` into +/// `3.3.0`. +/// +/// Example for non-stable version: +/// `2.1.0-dev.8.0.flutter-312ae32` into `2.1.0 (build 2.1.0-dev.8.0 312ae32)`. +String parseDartSDKVersion(String versionString) { + versionString = versionString.trim(); + final justVersion = versionString.split(' ')[0]; + + // For non-stable versions, this regex will include build information + return justVersion.replaceFirstMapped(RegExp(r'(\d+\.\d+\.\d+)(.+)'), + (Match match) { + final noFlutter = match[2]!.replaceAll('.flutter-', ' '); + return '${match[1]} (build ${match[1]}$noFlutter)'.trim(); + }); +} + /// Will use two strings to produce a double for applying a sampling /// rate for [Survey] to be returned to the user. double sampleRate(String string1, String string2) => diff --git a/pkgs/unified_analytics/lib/unified_analytics.dart b/pkgs/unified_analytics/lib/unified_analytics.dart index 9dc6abdc81..7cc4562b9e 100644 --- a/pkgs/unified_analytics/lib/unified_analytics.dart +++ b/pkgs/unified_analytics/lib/unified_analytics.dart @@ -8,3 +8,4 @@ export 'src/enums.dart' show DashTool; export 'src/event.dart' show Event; export 'src/log_handler.dart' show LogFileStats; export 'src/survey_handler.dart' show Survey, SurveyButton, SurveyHandler; +export 'src/utils.dart' show parseDartSDKVersion; diff --git a/pkgs/unified_analytics/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index b090399e44..eace0d02fa 100644 --- a/pkgs/unified_analytics/pubspec.yaml +++ b/pkgs/unified_analytics/pubspec.yaml @@ -4,7 +4,7 @@ description: >- to Google Analytics. # When updating this, keep the version consistent with the changelog and the # value in lib/src/constants.dart. -version: 5.8.2-wip +version: 5.8.2 repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics environment: diff --git a/pkgs/unified_analytics/test/unified_analytics_test.dart b/pkgs/unified_analytics/test/unified_analytics_test.dart index 2b794b671e..8b01e5d74c 100644 --- a/pkgs/unified_analytics/test/unified_analytics_test.dart +++ b/pkgs/unified_analytics/test/unified_analytics_test.dart @@ -1276,4 +1276,21 @@ Privacy Policy (https://policies.google.com/privacy). expect(eventList.contains(eventToMatch), true); expect(eventList.where((element) => element == eventToMatch).length, 1); }); + + group('Unit tests for util dartSDKVersion', () { + test('parses correctly for non-stable version', () { + final originalVersion = + '3.4.0-148.0.dev (dev) (Thu Feb 15 12:05:45 2024 -0800) on "macos_arm64"'; + + expect(parseDartSDKVersion(originalVersion), + '3.4.0 (build 3.4.0-148.0.dev)'); + }); + + test('parses correctly for stable version', () { + final originalVersion = + '3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64"'; + + expect(parseDartSDKVersion(originalVersion), '3.3.0'); + }); + }); }