From d962ff9155e98288c9314428d14c30d1590d0ac2 Mon Sep 17 00:00:00 2001 From: eliasyishak <42216813+eliasyishak@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:04:25 -0500 Subject: [PATCH 1/4] Helper method added to parse dart version --- pkgs/unified_analytics/lib/src/utils.dart | 26 +++++++++++++++++++ .../test/unified_analytics_test.dart | 17 ++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pkgs/unified_analytics/lib/src/utils.dart b/pkgs/unified_analytics/lib/src/utils.dart index 3044a50a..b0a23208 100644 --- a/pkgs/unified_analytics/lib/src/utils.dart +++ b/pkgs/unified_analytics/lib/src/utils.dart @@ -215,6 +215,32 @@ 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]; + 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/test/unified_analytics_test.dart b/pkgs/unified_analytics/test/unified_analytics_test.dart index 2b794b67..8b01e5d7 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'); + }); + }); } From 6a1d60706fdb77b2090620a471b152f766616d04 Mon Sep 17 00:00:00 2001 From: eliasyishak <42216813+eliasyishak@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:05:49 -0500 Subject: [PATCH 2/4] Additional documentation --- pkgs/unified_analytics/lib/src/utils.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/unified_analytics/lib/src/utils.dart b/pkgs/unified_analytics/lib/src/utils.dart index b0a23208..18f7c8a4 100644 --- a/pkgs/unified_analytics/lib/src/utils.dart +++ b/pkgs/unified_analytics/lib/src/utils.dart @@ -234,6 +234,8 @@ bool legacyOptOut({required FileSystem fs, required Directory home}) { 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-', ' '); From 45ac0a64c9c2dbe2a7701b0d93ceae73f3bad49b Mon Sep 17 00:00:00 2001 From: eliasyishak <42216813+eliasyishak@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:11:53 -0500 Subject: [PATCH 3/4] Export helper + update changelog --- pkgs/unified_analytics/CHANGELOG.md | 1 + pkgs/unified_analytics/lib/src/utils.dart | 2 +- pkgs/unified_analytics/lib/unified_analytics.dart | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 6e6e6b9e..26a08a9b 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -2,6 +2,7 @@ - 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/utils.dart b/pkgs/unified_analytics/lib/src/utils.dart index 18f7c8a4..55b59f35 100644 --- a/pkgs/unified_analytics/lib/src/utils.dart +++ b/pkgs/unified_analytics/lib/src/utils.dart @@ -235,7 +235,7 @@ String parseDartSDKVersion(String versionString) { versionString = versionString.trim(); final justVersion = versionString.split(' ')[0]; - // For non-stable versions, this regex will include build information + // 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-', ' '); diff --git a/pkgs/unified_analytics/lib/unified_analytics.dart b/pkgs/unified_analytics/lib/unified_analytics.dart index 9dc6abdc..7cc4562b 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; From 4f27563ddf6ace2d51acecac660780e7fa568c57 Mon Sep 17 00:00:00 2001 From: eliasyishak <42216813+eliasyishak@users.noreply.github.com> Date: Fri, 16 Feb 2024 13:19:23 -0500 Subject: [PATCH 4/4] Prepare to publish --- pkgs/unified_analytics/CHANGELOG.md | 2 +- pkgs/unified_analytics/lib/src/constants.dart | 2 +- pkgs/unified_analytics/pubspec.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/unified_analytics/CHANGELOG.md b/pkgs/unified_analytics/CHANGELOG.md index 26a08a9b..dbdbb39c 100644 --- a/pkgs/unified_analytics/CHANGELOG.md +++ b/pkgs/unified_analytics/CHANGELOG.md @@ -1,4 +1,4 @@ -## 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` diff --git a/pkgs/unified_analytics/lib/src/constants.dart b/pkgs/unified_analytics/lib/src/constants.dart index 77c8892d..cc713799 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/pubspec.yaml b/pkgs/unified_analytics/pubspec.yaml index b090399e..eace0d02 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: