diff --git a/json_serializable/lib/src/check_dependencies.dart b/json_serializable/lib/src/check_dependencies.dart index 0e5ef307..13117f26 100644 --- a/json_serializable/lib/src/check_dependencies.dart +++ b/json_serializable/lib/src/check_dependencies.dart @@ -13,7 +13,7 @@ import 'constants.dart'; const _productionDirectories = {'lib', 'bin'}; const _annotationPkgName = 'json_annotation'; final _supportLanguageRange = - VersionConstraint.parse(supportLanguageConstraint); + VersionConstraint.parse(supportedLanguageConstraint); final requiredJsonAnnotationMinVersion = Version.parse('4.9.0'); Future pubspecHasRightVersion(BuildStep buildStep) async { @@ -52,23 +52,25 @@ Future _validatePubspec(bool production, BuildStep buildStep) async { // // Ensure the current package language version is at least the minimum. // - final currentPackageName = pubspec.name; - final packageConfig = await buildStep.packageConfig; - final thisPackage = packageConfig[currentPackageName]!; - // build_runner will error out without an SDK version - so this "should" be - // fine. + // build_runner will error out without an SDK version - so assuming + // `languageVersion` is not null. final thisPackageVersion = thisPackage.languageVersion!; final thisPackageVer = Version.parse('$thisPackageVersion.0'); if (!_supportLanguageRange.allows(thisPackageVer)) { log.warning( - 'The language version ($thisPackageVer) of this package ' - '($currentPackageName) does not match the required range ' - '`$supportLanguageConstraint`.', + ''' +The language version ($thisPackageVer) of this package ($currentPackageName) does not match the required range `$supportedLanguageConstraint`. + +Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. + +environment: + sdk: $supportedLanguageConstraint +''', ); } } diff --git a/json_serializable/lib/src/constants.dart b/json_serializable/lib/src/constants.dart index b28cf1fd..70e85216 100644 --- a/json_serializable/lib/src/constants.dart +++ b/json_serializable/lib/src/constants.dart @@ -16,4 +16,4 @@ const converterOrKeyInstructions = r''' /// This package generates code that uses case statements, which were introduced /// in Dart 3.0. -const supportLanguageConstraint = '^3.0.0'; +const supportedLanguageConstraint = '^3.0.0'; diff --git a/json_serializable/test/annotation_version_test.dart b/json_serializable/test/annotation_version_test.dart index 0ccb8487..f28cb0d5 100644 --- a/json_serializable/test/annotation_version_test.dart +++ b/json_serializable/test/annotation_version_test.dart @@ -36,13 +36,18 @@ void main() { await _structurePackage( environment: const {'sdk': '^$sdkLowerBound'}, dependencies: {'json_annotation': _annotationLowerBound}, - message: 'The language version ($sdkLowerBound) of this package ' - '($_testPkgName) does not match the required range ' - '`$supportLanguageConstraint`.', + message: ''' +The language version ($sdkLowerBound) of this package ($_testPkgName) does not match the required range `$supportedLanguageConstraint`. + +Edit pubspec.yaml to include an SDK constraint of at least $supportedLanguageConstraint. + +environment: + sdk: $supportedLanguageConstraint +''', ); }); - test('is at least the required `$supportLanguageConstraint`', () async { + test('is at least the required `$supportedLanguageConstraint`', () async { await _structurePackage( dependencies: {'json_annotation': _annotationLowerBound}, message: null, @@ -135,7 +140,7 @@ const _testPkgName = '_test_pkg'; Future _structurePackage({ String sourceDirectory = 'lib', required String? message, - Map environment = const {'sdk': supportLanguageConstraint}, + Map environment = const {'sdk': supportedLanguageConstraint}, Map dependencies = const {}, Map devDependencies = const {}, }) async {