| 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 package; | 5 library package; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import '../../pkg/pathos/lib/path.dart' as path; | 9 import '../../pkg/pathos/lib/path.dart' as path; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 /// specified in the pubspec when this package depends on another. | 38 /// specified in the pubspec when this package depends on another. |
| 39 List<PackageRef> get dependencies => pubspec.dependencies; | 39 List<PackageRef> get dependencies => pubspec.dependencies; |
| 40 | 40 |
| 41 /// Returns the path to the README file at the root of the entrypoint, or null | 41 /// Returns the path to the README file at the root of the entrypoint, or null |
| 42 /// if no README file is found. If multiple READMEs are found, this uses the | 42 /// if no README file is found. If multiple READMEs are found, this uses the |
| 43 /// same conventions as pub.dartlang.org for choosing the primary one: the | 43 /// same conventions as pub.dartlang.org for choosing the primary one: the |
| 44 /// README with the fewest extensions that is lexically ordered first is | 44 /// README with the fewest extensions that is lexically ordered first is |
| 45 /// chosen. | 45 /// chosen. |
| 46 Future<String> get readmePath { | 46 Future<String> get readmePath { |
| 47 return listDir(dir).then((entries) { | 47 return listDir(dir).then((entries) { |
| 48 var readmes = entries.where((entry) => entry.contains(_README_REGEXP)); | 48 var readmes = entries.map(path.basename). |
| 49 where((entry) => entry.contains(_README_REGEXP)); |
| 49 if (readmes.isEmpty) return; | 50 if (readmes.isEmpty) return; |
| 50 | 51 |
| 51 return readmes.min((readme1, readme2) { | 52 return path.join(dir, readmes.min((readme1, readme2) { |
| 52 var extensions1 = ".".allMatches(readme1).length; | 53 var extensions1 = ".".allMatches(readme1).length; |
| 53 var extensions2 = ".".allMatches(readme2).length; | 54 var extensions2 = ".".allMatches(readme2).length; |
| 54 var comparison = extensions1.compareTo(extensions2); | 55 var comparison = extensions1.compareTo(extensions2); |
| 55 if (comparison != 0) return comparison; | 56 if (comparison != 0) return comparison; |
| 56 return readme1.compareTo(readme2); | 57 return readme1.compareTo(readme2); |
| 57 }); | 58 })); |
| 58 }); | 59 }); |
| 59 } | 60 } |
| 60 | 61 |
| 61 /// Loads the package whose root directory is [packageDir]. [name] is the | 62 /// Loads the package whose root directory is [packageDir]. [name] is the |
| 62 /// expected name of that package (e.g. the name given in the dependency), or | 63 /// expected name of that package (e.g. the name given in the dependency), or |
| 63 /// `null` if the package being loaded is the entrypoint package. | 64 /// `null` if the package being loaded is the entrypoint package. |
| 64 Package.load(String name, String packageDir, SourceRegistry sources) | 65 Package.load(String name, String packageDir, SourceRegistry sources) |
| 65 : dir = packageDir, | 66 : dir = packageDir, |
| 66 pubspec = new Pubspec.load(name, packageDir, sources); | 67 pubspec = new Pubspec.load(name, packageDir, sources); |
| 67 | 68 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 207 |
| 207 class PubspecNameMismatchException implements Exception { | 208 class PubspecNameMismatchException implements Exception { |
| 208 final String expectedName; | 209 final String expectedName; |
| 209 final String actualName; | 210 final String actualName; |
| 210 | 211 |
| 211 PubspecNameMismatchException(this.expectedName, this.actualName); | 212 PubspecNameMismatchException(this.expectedName, this.actualName); |
| 212 | 213 |
| 213 String toString() => 'The name you specified for your dependency, ' | 214 String toString() => 'The name you specified for your dependency, ' |
| 214 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.'; | 215 '"$expectedName", doesn\'t match the name "$actualName" in its pubspec.'; |
| 215 } | 216 } |
| OLD | NEW |