| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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'; | 7 import 'package:pub_semver/pub_semver.dart'; |
| 8 | 8 |
| 9 import '../entrypoint.dart'; | 9 import '../entrypoint.dart'; |
| 10 import '../log.dart' as log; | 10 import '../log.dart' as log; |
| 11 import '../package.dart'; | 11 import '../package.dart'; |
| 12 import '../source/hosted.dart'; |
| 13 import '../source/path.dart'; |
| 12 import '../validator.dart'; | 14 import '../validator.dart'; |
| 13 | 15 |
| 14 /// The range of all pub versions that don't support `^` version constraints. | 16 /// The range of all pub versions that don't support `^` version constraints. |
| 15 /// | 17 /// |
| 16 /// This is the actual range of pub versions, whereas [_postCaretPubVersions] is | 18 /// This is the actual range of pub versions, whereas [_postCaretPubVersions] is |
| 17 /// the nicer-looking range that doesn't include a prerelease tag. | 19 /// the nicer-looking range that doesn't include a prerelease tag. |
| 18 final _preCaretPubVersions = new VersionConstraint.parse("<1.8.0-dev.3.0"); | 20 final _preCaretPubVersions = new VersionConstraint.parse("<1.8.0-dev.3.0"); |
| 19 | 21 |
| 20 /// The range of all pub versions that do support `^` version constraints. | 22 /// The range of all pub versions that do support `^` version constraints. |
| 21 /// | 23 /// |
| 22 /// This is intersected with the user's SDK constraint to provide a suggested | 24 /// This is intersected with the user's SDK constraint to provide a suggested |
| 23 /// constraint. | 25 /// constraint. |
| 24 final _postCaretPubVersions = new VersionConstraint.parse("^1.8.0"); | 26 final _postCaretPubVersions = new VersionConstraint.parse("^1.8.0"); |
| 25 | 27 |
| 26 /// A validator that validates a package's dependencies. | 28 /// A validator that validates a package's dependencies. |
| 27 class DependencyValidator extends Validator { | 29 class DependencyValidator extends Validator { |
| 28 /// Whether the SDK constraint guarantees that `^` version constraints are | 30 /// Whether the SDK constraint guarantees that `^` version constraints are |
| 29 /// safe. | 31 /// safe. |
| 30 bool get _caretAllowed => entrypoint.root.pubspec.environment.sdkVersion | 32 bool get _caretAllowed => entrypoint.root.pubspec.environment.sdkVersion |
| 31 .intersect(_preCaretPubVersions).isEmpty; | 33 .intersect(_preCaretPubVersions).isEmpty; |
| 32 | 34 |
| 33 DependencyValidator(Entrypoint entrypoint) | 35 DependencyValidator(Entrypoint entrypoint) |
| 34 : super(entrypoint); | 36 : super(entrypoint); |
| 35 | 37 |
| 36 Future validate() async { | 38 Future validate() async { |
| 37 var caretDeps = []; | 39 var caretDeps = []; |
| 38 | 40 |
| 39 for (var dependency in entrypoint.root.pubspec.dependencies) { | 41 for (var dependency in entrypoint.root.pubspec.dependencies) { |
| 40 if (dependency.source != "hosted") { | 42 if (dependency.source is! HostedSource) { |
| 41 await _warnAboutSource(dependency); | 43 await _warnAboutSource(dependency); |
| 42 } else if (dependency.constraint.isAny) { | 44 } else if (dependency.constraint.isAny) { |
| 43 _warnAboutNoConstraint(dependency); | 45 _warnAboutNoConstraint(dependency); |
| 44 } else if (dependency.constraint is Version) { | 46 } else if (dependency.constraint is Version) { |
| 45 _warnAboutSingleVersionConstraint(dependency); | 47 _warnAboutSingleVersionConstraint(dependency); |
| 46 } else if (dependency.constraint is VersionRange) { | 48 } else if (dependency.constraint is VersionRange) { |
| 47 if (dependency.constraint.min == null) { | 49 if (dependency.constraint.min == null) { |
| 48 _warnAboutNoConstraintLowerBound(dependency); | 50 _warnAboutNoConstraintLowerBound(dependency); |
| 49 } else if (dependency.constraint.max == null) { | 51 } else if (dependency.constraint.max == null) { |
| 50 _warnAboutNoConstraintUpperBound(dependency); | 52 _warnAboutNoConstraintUpperBound(dependency); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 77 if (primary != null) { | 79 if (primary != null) { |
| 78 constraint = _constraintForVersion(primary); | 80 constraint = _constraintForVersion(primary); |
| 79 } else { | 81 } else { |
| 80 constraint = dep.constraint.toString(); | 82 constraint = dep.constraint.toString(); |
| 81 if (!dep.constraint.isAny && dep.constraint is! Version) { | 83 if (!dep.constraint.isAny && dep.constraint is! Version) { |
| 82 constraint = '"$constraint"'; | 84 constraint = '"$constraint"'; |
| 83 } | 85 } |
| 84 } | 86 } |
| 85 | 87 |
| 86 // Path sources are errors. Other sources are just warnings. | 88 // Path sources are errors. Other sources are just warnings. |
| 87 var messages = warnings; | 89 var messages = dep.source is PathSource ? errors : warnings; |
| 88 if (dep.source == "path") { | |
| 89 messages = errors; | |
| 90 } | |
| 91 | 90 |
| 92 messages.add('Don\'t depend on "${dep.name}" from the ${dep.source} ' | 91 messages.add('Don\'t depend on "${dep.name}" from the ${dep.source} ' |
| 93 'source. Use the hosted source instead. For example:\n' | 92 'source. Use the hosted source instead. For example:\n' |
| 94 '\n' | 93 '\n' |
| 95 'dependencies:\n' | 94 'dependencies:\n' |
| 96 ' ${dep.name}: $constraint\n' | 95 ' ${dep.name}: $constraint\n' |
| 97 '\n' | 96 '\n' |
| 98 'Using the hosted source ensures that everyone can download your ' | 97 'Using the hosted source ensures that everyone can download your ' |
| 99 'package\'s dependencies along with your package.'); | 98 'package\'s dependencies along with your package.'); |
| 100 } | 99 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 errors.add(buffer.toString().trim()); | 205 errors.add(buffer.toString().trim()); |
| 207 } | 206 } |
| 208 | 207 |
| 209 /// Returns the suggested version constraint for a dependency that was tested | 208 /// Returns the suggested version constraint for a dependency that was tested |
| 210 /// against [version]. | 209 /// against [version]. |
| 211 String _constraintForVersion(Version version) { | 210 String _constraintForVersion(Version version) { |
| 212 if (_caretAllowed) return "^$version"; | 211 if (_caretAllowed) return "^$version"; |
| 213 return '">=$version <${version.nextBreaking}"'; | 212 return '">=$version <${version.nextBreaking}"'; |
| 214 } | 213 } |
| 215 } | 214 } |
| OLD | NEW |