diff --git a/packages/shorebird_cli/lib/src/command.dart b/packages/shorebird_cli/lib/src/command.dart index 00b10891..438a45a4 100644 --- a/packages/shorebird_cli/lib/src/command.dart +++ b/packages/shorebird_cli/lib/src/command.dart @@ -27,7 +27,6 @@ typedef StartProcess = Future Function( }); List _defaultValidators() => [ - ShorebirdFlutterValidator(), AndroidInternetPermissionValidator(), ]; diff --git a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart index f5098e0a..27d4e451 100644 --- a/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart +++ b/packages/shorebird_cli/lib/src/validators/shorebird_flutter_validator.dart @@ -1,6 +1,7 @@ import 'package:shorebird_cli/src/shorebird_environment.dart'; import 'package:shorebird_cli/src/shorebird_process.dart'; import 'package:shorebird_cli/src/validators/validators.dart'; +import 'package:version/version.dart'; class FlutterValidationException implements Exception { const FlutterValidationException(this.message); @@ -58,9 +59,9 @@ class ShorebirdFlutterValidator extends Validator { ); } - String? shorebirdFlutterVersion; + String? shorebirdFlutterVersionString; try { - shorebirdFlutterVersion = await _shorebirdFlutterVersion(process); + shorebirdFlutterVersionString = await _shorebirdFlutterVersion(process); } catch (error) { issues.add( ValidationIssue( @@ -70,9 +71,9 @@ class ShorebirdFlutterValidator extends Validator { ); } - String? pathFlutterVersion; + String? pathFlutterVersionString; try { - pathFlutterVersion = await _pathFlutterVersion(process); + pathFlutterVersionString = await _pathFlutterVersion(process); } catch (error) { issues.add( ValidationIssue( @@ -82,21 +83,26 @@ class ShorebirdFlutterValidator extends Validator { ); } - if (shorebirdFlutterVersion != null && - pathFlutterVersion != null && - shorebirdFlutterVersion != pathFlutterVersion) { - final message = ''' + if (shorebirdFlutterVersionString != null && + pathFlutterVersionString != null) { + final shorebirdFlutterVersion = + Version.parse(shorebirdFlutterVersionString); + final pathFlutterVersion = Version.parse(pathFlutterVersionString); + if (shorebirdFlutterVersion.major != pathFlutterVersion.major || + shorebirdFlutterVersion.minor != pathFlutterVersion.minor) { + final message = ''' The version of Flutter that Shorebird includes and the Flutter on your path are different. -\tShorebird Flutter: $shorebirdFlutterVersion -\tSystem Flutter: $pathFlutterVersion +\tShorebird Flutter: $shorebirdFlutterVersionString +\tSystem Flutter: $pathFlutterVersionString This can cause unexpected behavior if you are switching between the tools and the version gap is wide. If you have any trouble, please let us know on Shorebird discord.'''; - issues.add( - ValidationIssue( - severity: ValidationIssueSeverity.warning, - message: message, - ), - ); + issues.add( + ValidationIssue( + severity: ValidationIssueSeverity.warning, + message: message, + ), + ); + } } final flutterStorageEnvironmentValue = diff --git a/packages/shorebird_cli/pubspec.yaml b/packages/shorebird_cli/pubspec.yaml index d608ecf9..fd2df4a3 100644 --- a/packages/shorebird_cli/pubspec.yaml +++ b/packages/shorebird_cli/pubspec.yaml @@ -28,6 +28,7 @@ dependencies: pubspec_parse: ^1.2.2 shorebird_code_push_client: path: ../shorebird_code_push_client + version: ^3.0.2 xml: ^6.2.2 yaml: ^3.1.1 yaml_edit: ^2.1.0 diff --git a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart index d3811743..69228b3f 100644 --- a/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart +++ b/packages/shorebird_cli/test/src/validators/shorebird_flutter_validator_test.dart @@ -160,8 +160,8 @@ Tools • Dart 2.19.6 • DevTools 2.20.1 }); test( - 'warns when path flutter version does not match shorebird flutter' - ' version', + 'does not warn if flutter version and shorebird flutter version have same' + ' major and minor but different patch versions', () async { when(() => pathFlutterVersionProcessResult.stdout).thenReturn( pathFlutterVersionMessage.replaceAll('3.7.9', '3.7.10'), @@ -169,6 +169,20 @@ Tools • Dart 2.19.6 • DevTools 2.20.1 final results = await validator.validate(shorebirdProcess); + expect(results, isEmpty); + }, + ); + + test( + 'warns when path flutter version has different major or minor version ' + 'than shorebird flutter', + () async { + when(() => pathFlutterVersionProcessResult.stdout).thenReturn( + pathFlutterVersionMessage.replaceAll('3.7.9', '3.8.9'), + ); + + final results = await validator.validate(shorebirdProcess); + expect(results, hasLength(1)); expect(results.first.severity, ValidationIssueSeverity.warning); expect(