Chromium Code Reviews| 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 library pub.validator.dependency; | 5 library pub.validator.dependency; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
| 10 | 10 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 ' ${dep.name}: $constraint\n'; | 147 ' ${dep.name}: $constraint\n'; |
| 148 } | 148 } |
| 149 warnings.add("$message\n" | 149 warnings.add("$message\n" |
| 150 'Without a constraint, you\'re promising to support ${log.bold("all")} ' | 150 'Without a constraint, you\'re promising to support ${log.bold("all")} ' |
| 151 'previous versions of "${dep.name}".'); | 151 'previous versions of "${dep.name}".'); |
| 152 } | 152 } |
| 153 | 153 |
| 154 /// Warn that dependencies should have upper bounds on their constraints. | 154 /// Warn that dependencies should have upper bounds on their constraints. |
| 155 void _warnAboutNoConstraintUpperBound(PackageDep dep) { | 155 void _warnAboutNoConstraintUpperBound(PackageDep dep) { |
| 156 var constraint; | 156 var constraint; |
| 157 if ((dep.constraint as VersionRange).includeMin) { | 157 if ((dep.constraint as VersionRange).includeMin) { |
|
Bob Nystrom
2014/11/06 17:14:20
What if it isn't a range? What if it's just a Vers
nweiz
2014/11/06 21:11:39
We can only get to this method if the constraint d
| |
| 158 constraint = _constraintForVersion(dep.constraint.min); | 158 constraint = _constraintForVersion((dep.constraint as VersionRange).min); |
| 159 } else { | 159 } else { |
| 160 constraint = '"${dep.constraint} ' | 160 constraint = '"${dep.constraint} ' |
| 161 '<${(dep.constraint as VersionRange).min.nextBreaking}"'; | 161 '<${(dep.constraint as VersionRange).min.nextBreaking}"'; |
| 162 } | 162 } |
| 163 | 163 |
| 164 warnings.add( | 164 warnings.add( |
| 165 'Your dependency on "${dep.name}" should have an upper bound. For ' | 165 'Your dependency on "${dep.name}" should have an upper bound. For ' |
| 166 'example:\n' | 166 'example:\n' |
| 167 '\n' | 167 '\n' |
| 168 'dependencies:\n' | 168 'dependencies:\n' |
| 169 ' ${dep.name}: $constraint\n' | 169 ' ${dep.name}: $constraint\n' |
| 170 '\n' | 170 '\n' |
| 171 'Without an upper bound, you\'re promising to support ' | 171 'Without an upper bound, you\'re promising to support ' |
| 172 '${log.bold("all")} future versions of ${dep.name}.'); | 172 '${log.bold("all")} future versions of ${dep.name}.'); |
| 173 } | 173 } |
| 174 | 174 |
| 175 /// Emits an error for any version constraints that use `^` without an | 175 /// Emits an error for any version constraints that use `^` without an |
| 176 /// appropriate SDK constraint. | 176 /// appropriate SDK constraint. |
| 177 void _errorAboutCaretConstraints(List<PackageDeps> caretDeps) { | 177 void _errorAboutCaretConstraints(List<PackageDep> caretDeps) { |
| 178 var newSdkConstraint = entrypoint.root.pubspec.environment.sdkVersion | 178 var newSdkConstraint = entrypoint.root.pubspec.environment.sdkVersion |
| 179 .intersect(_postCaretPubVersions); | 179 .intersect(_postCaretPubVersions); |
| 180 | 180 |
| 181 if (newSdkConstraint.isEmpty) newSdkConstraint = _postCaretPubVersions; | 181 if (newSdkConstraint.isEmpty) newSdkConstraint = _postCaretPubVersions; |
| 182 | 182 |
| 183 var buffer = new StringBuffer( | 183 var buffer = new StringBuffer( |
| 184 "Older versions of pub don't support ^ version constraints.\n" | 184 "Older versions of pub don't support ^ version constraints.\n" |
| 185 "Make sure your SDK constraint excludes those old versions:\n" | 185 "Make sure your SDK constraint excludes those old versions:\n" |
| 186 "\n" | 186 "\n" |
| 187 "environment:\n" | 187 "environment:\n" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 206 errors.add(buffer.toString().trim()); | 206 errors.add(buffer.toString().trim()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 /// Returns the suggested version constraint for a dependency that was tested | 209 /// Returns the suggested version constraint for a dependency that was tested |
| 210 /// against [version]. | 210 /// against [version]. |
| 211 String _constraintForVersion(Version version) { | 211 String _constraintForVersion(Version version) { |
| 212 if (_caretAllowed) return "^$version"; | 212 if (_caretAllowed) return "^$version"; |
| 213 return '">=$version <${version.nextBreaking}"'; | 213 return '">=$version <${version.nextBreaking}"'; |
| 214 } | 214 } |
| 215 } | 215 } |
| OLD | NEW |