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 49 matching lines...) Loading... |
60 | 60 |
61 if (caretDeps.isNotEmpty && !_caretAllowed) { | 61 if (caretDeps.isNotEmpty && !_caretAllowed) { |
62 _errorAboutCaretConstraints(caretDeps); | 62 _errorAboutCaretConstraints(caretDeps); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 /// Warn that dependencies should use the hosted source. | 66 /// Warn that dependencies should use the hosted source. |
67 Future _warnAboutSource(PackageDep dep) async { | 67 Future _warnAboutSource(PackageDep dep) async { |
68 var versions; | 68 var versions; |
69 try { | 69 try { |
70 var pubspecs = await entrypoint.cache.sources['hosted'] | 70 var ref = new PackageRef(dep.name, 'hosted', dep.name); |
71 .getVersions(dep.name, dep.name); | 71 var ids = await entrypoint.cache.sources['hosted'].getVersions(ref); |
72 versions = pubspecs.map((pubspec) => pubspec.version).toList(); | 72 versions = ids.map((id) => id.version).toList(); |
73 } catch (error) { | 73 } catch (error) { |
74 versions = []; | 74 versions = []; |
75 } | 75 } |
76 | 76 |
77 var constraint; | 77 var constraint; |
78 var primary = Version.primary(versions); | 78 var primary = Version.primary(versions); |
79 if (primary != null) { | 79 if (primary != null) { |
80 constraint = _constraintForVersion(primary); | 80 constraint = _constraintForVersion(primary); |
81 } else { | 81 } else { |
82 constraint = dep.constraint.toString(); | 82 constraint = dep.constraint.toString(); |
(...skipping 125 matching lines...) Loading... |
208 errors.add(buffer.toString().trim()); | 208 errors.add(buffer.toString().trim()); |
209 } | 209 } |
210 | 210 |
211 /// Returns the suggested version constraint for a dependency that was tested | 211 /// Returns the suggested version constraint for a dependency that was tested |
212 /// against [version]. | 212 /// against [version]. |
213 String _constraintForVersion(Version version) { | 213 String _constraintForVersion(Version version) { |
214 if (_caretAllowed) return "^$version"; | 214 if (_caretAllowed) return "^$version"; |
215 return '">=$version <${version.nextBreaking}"'; | 215 return '">=$version <${version.nextBreaking}"'; |
216 } | 216 } |
217 } | 217 } |
OLD | NEW |