OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import 'dart:async'; | 5 import 'dart:async'; |
6 | 6 |
| 7 import 'package:pub_semver/pub_semver.dart'; |
| 8 |
7 import '../entrypoint.dart'; | 9 import '../entrypoint.dart'; |
8 import '../validator.dart'; | 10 import '../validator.dart'; |
9 | 11 |
| 12 /// The range of all Dart SDK versions that don't support Flutter SDK |
| 13 /// constraints. |
| 14 final _preFlutterSupport = new VersionConstraint.parse("<1.19.0"); |
| 15 |
10 /// A validator that validates that a package's SDK constraint doesn't use the | 16 /// A validator that validates that a package's SDK constraint doesn't use the |
11 /// "^" syntax. | 17 /// "^" syntax. |
12 class SdkConstraintValidator extends Validator { | 18 class SdkConstraintValidator extends Validator { |
13 SdkConstraintValidator(Entrypoint entrypoint) | 19 SdkConstraintValidator(Entrypoint entrypoint) |
14 : super(entrypoint); | 20 : super(entrypoint); |
15 | 21 |
16 Future validate() async { | 22 Future validate() async { |
17 var constraint = entrypoint.root.pubspec.dartSdkConstraint; | 23 var dartConstraint = entrypoint.root.pubspec.dartSdkConstraint; |
18 if (!constraint.toString().startsWith("^")) return; | 24 if (dartConstraint.toString().startsWith("^")) { |
| 25 errors.add( |
| 26 "^ version constraints aren't allowed for SDK constraints since " |
| 27 "older versions of pub don't support them.\n" |
| 28 "Expand it manually instead:\n" |
| 29 "\n" |
| 30 "environment:\n" |
| 31 " sdk: \">=${dartConstraint.min} <${dartConstraint.max}\""); |
| 32 } |
19 | 33 |
20 errors.add( | 34 if (entrypoint.root.pubspec.flutterSdkConstraint != null && |
21 "^ version constraints aren't allowed for SDK constraints since " | 35 dartConstraint.allowsAny(_preFlutterSupport)) { |
22 "older versions of pub don't support them.\n" | 36 var newDartConstraint = dartConstraint.difference(_preFlutterSupport); |
23 "Expand it manually instead:\n" | 37 if (newDartConstraint.isEmpty || |
24 "\n" | 38 newDartConstraint == |
25 "environment:\n" | 39 VersionConstraint.any.difference(_preFlutterSupport)) { |
26 " sdk: \">=${constraint.min} <${constraint.max}\""); | 40 newDartConstraint = new VersionConstraint.parse("<2.0.0") |
| 41 .difference(_preFlutterSupport); |
| 42 } |
| 43 |
| 44 errors.add( |
| 45 "Older versions of pub don't support Flutter SDK constraints.\n" |
| 46 "Make sure your SDK constraint excludes those old versions:\n" |
| 47 "\n" |
| 48 "environment:\n" |
| 49 " sdk: \"$newDartConstraint\""); |
| 50 } |
27 } | 51 } |
28 } | 52 } |
OLD | NEW |