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:io'; | 5 import 'dart:io'; |
6 | 6 |
7 import 'package:barback/barback.dart'; | 7 import 'package:barback/barback.dart'; |
8 import 'package:path/path.dart' as p; | 8 import 'package:path/path.dart' as p; |
9 import 'package:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
10 | 10 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 /// The immediate dev dependencies this package specifies in its pubspec. | 54 /// The immediate dev dependencies this package specifies in its pubspec. |
55 List<PackageDep> get devDependencies => pubspec.devDependencies; | 55 List<PackageDep> get devDependencies => pubspec.devDependencies; |
56 | 56 |
57 /// The dependency overrides this package specifies in its pubspec. | 57 /// The dependency overrides this package specifies in its pubspec. |
58 List<PackageDep> get dependencyOverrides => pubspec.dependencyOverrides; | 58 List<PackageDep> get dependencyOverrides => pubspec.dependencyOverrides; |
59 | 59 |
60 /// All immediate dependencies this package specifies. | 60 /// All immediate dependencies this package specifies. |
61 /// | 61 /// |
62 /// This includes regular, dev dependencies, and overrides. | 62 /// This includes regular, dev dependencies, and overrides. |
63 Set<PackageDep> get immediateDependencies { | 63 List<PackageDep> get immediateDependencies { |
64 var deps = {}; | 64 var deps = <String, PackageDep>{}; |
65 | 65 |
66 addToMap(dep) { | 66 addToMap(dep) { |
67 deps[dep.name] = dep; | 67 deps[dep.name] = dep; |
68 } | 68 } |
69 | 69 |
70 dependencies.forEach(addToMap); | 70 dependencies.forEach(addToMap); |
71 devDependencies.forEach(addToMap); | 71 devDependencies.forEach(addToMap); |
72 | 72 |
73 // Make sure to add these last so they replace normal dependencies. | 73 // Make sure to add these last so they replace normal dependencies. |
74 dependencyOverrides.forEach(addToMap); | 74 dependencyOverrides.forEach(addToMap); |
75 | 75 |
76 return deps.values.toSet(); | 76 return deps.values.toList(); |
77 } | 77 } |
78 | 78 |
79 /// Returns a list of asset ids for all Dart executables in this package's bin | 79 /// Returns a list of asset ids for all Dart executables in this package's bin |
80 /// directory. | 80 /// directory. |
81 List<AssetId> get executableIds { | 81 List<AssetId> get executableIds { |
82 return ordered(listFiles(beneath: "bin", recursive: false)) | 82 return ordered(listFiles(beneath: "bin", recursive: false)) |
83 .where((executable) => p.extension(executable) == '.dart') | 83 .where((executable) => p.extension(executable) == '.dart') |
84 .map((executable) { | 84 .map((executable) { |
85 return new AssetId( | 85 return new AssetId( |
86 name, p.toUri(p.relative(executable, from: dir)).toString()); | 86 name, p.toUri(p.relative(executable, from: dir)).toString()); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 beneath = p.join(dir, beneath); | 216 beneath = p.join(dir, beneath); |
217 } | 217 } |
218 | 218 |
219 if (!dirExists(beneath)) return []; | 219 if (!dirExists(beneath)) return []; |
220 | 220 |
221 // This is used in some performance-sensitive paths and can list many, many | 221 // This is used in some performance-sensitive paths and can list many, many |
222 // files. As such, it leans more havily towards optimization as opposed to | 222 // files. As such, it leans more havily towards optimization as opposed to |
223 // readability than most code in pub. In particular, it avoids using the | 223 // readability than most code in pub. In particular, it avoids using the |
224 // path package, since re-parsing a path is very expensive relative to | 224 // path package, since re-parsing a path is very expensive relative to |
225 // string operations. | 225 // string operations. |
226 var files; | 226 Iterable<String> files; |
227 if (useGitIgnore && _inGitRepo) { | 227 if (useGitIgnore && _inGitRepo) { |
228 // Later versions of git do not allow a path for ls-files that appears to | 228 // Later versions of git do not allow a path for ls-files that appears to |
229 // be outside of the repo, so make sure we give it a relative path. | 229 // be outside of the repo, so make sure we give it a relative path. |
230 var relativeBeneath = p.relative(beneath, from: dir); | 230 var relativeBeneath = p.relative(beneath, from: dir); |
231 | 231 |
232 // List all files that aren't gitignored, including those not checked in | 232 // List all files that aren't gitignored, including those not checked in |
233 // to Git. | 233 // to Git. |
234 files = git.runSync( | 234 files = git.runSync( |
235 ["ls-files", "--cached", "--others", "--exclude-standard", | 235 ["ls-files", "--cached", "--others", "--exclude-standard", |
236 relativeBeneath], | 236 relativeBeneath], |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 /// Creates an ID for a package with the given [name], [source], [version], | 432 /// Creates an ID for a package with the given [name], [source], [version], |
433 /// and [description]. | 433 /// and [description]. |
434 /// | 434 /// |
435 /// Since an ID's description is an implementation detail of its source, this | 435 /// Since an ID's description is an implementation detail of its source, this |
436 /// should generally not be called outside of [Source] subclasses. | 436 /// should generally not be called outside of [Source] subclasses. |
437 PackageId(String name, Source source, this.version, description) | 437 PackageId(String name, Source source, this.version, description) |
438 : super._(name, source, description); | 438 : super._(name, source, description); |
439 | 439 |
440 /// Creates an ID for a magic package (see [isMagic]). | 440 /// Creates an ID for a magic package (see [isMagic]). |
441 PackageId.magic(String name) | 441 PackageId.magic(String name) |
442 : super._magic(name), | 442 : version = Version.none, |
443 version = Version.none; | 443 super._magic(name); |
444 | 444 |
445 /// Creates an ID for the given root package. | 445 /// Creates an ID for the given root package. |
446 PackageId.root(Package package) | 446 PackageId.root(Package package) |
447 : version = package.version, | 447 : version = package.version, |
448 super._(package.name, null, package.name); | 448 super._(package.name, null, package.name); |
449 | 449 |
450 int get hashCode => super.hashCode ^ version.hashCode; | 450 int get hashCode => super.hashCode ^ version.hashCode; |
451 | 451 |
452 bool operator ==(other) => | 452 bool operator ==(other) => |
453 other is PackageId && samePackage(other) && other.version == version; | 453 other is PackageId && samePackage(other) && other.version == version; |
(...skipping 12 matching lines...) Expand all Loading... |
466 | 466 |
467 /// Creates a reference to package with the given [name], [source], | 467 /// Creates a reference to package with the given [name], [source], |
468 /// [constraint], and [description]. | 468 /// [constraint], and [description]. |
469 /// | 469 /// |
470 /// Since an ID's description is an implementation detail of its source, this | 470 /// Since an ID's description is an implementation detail of its source, this |
471 /// should generally not be called outside of [Source] subclasses. | 471 /// should generally not be called outside of [Source] subclasses. |
472 PackageDep(String name, Source source, this.constraint, description) | 472 PackageDep(String name, Source source, this.constraint, description) |
473 : super._(name, source, description); | 473 : super._(name, source, description); |
474 | 474 |
475 PackageDep.magic(String name) | 475 PackageDep.magic(String name) |
476 : super._magic(name), | 476 : constraint = Version.none, |
477 constraint = Version.none; | 477 super._magic(name); |
478 | 478 |
479 String toString() { | 479 String toString() { |
480 if (isRoot) return "$name $constraint (root)"; | 480 if (isRoot) return "$name $constraint (root)"; |
481 if (isMagic) return name; | 481 if (isMagic) return name; |
482 return "$name $constraint from $source ($description)"; | 482 return "$name $constraint from $source ($description)"; |
483 } | 483 } |
484 | 484 |
485 /// Whether [id] satisfies this dependency. | 485 /// Whether [id] satisfies this dependency. |
486 /// | 486 /// |
487 /// Specifically, whether [id] refers to the same package as [this] *and* | 487 /// Specifically, whether [id] refers to the same package as [this] *and* |
488 /// [constraint] allows `id.version`. | 488 /// [constraint] allows `id.version`. |
489 bool allows(PackageId id) => | 489 bool allows(PackageId id) => |
490 samePackage(id) && constraint.allows(id.version); | 490 samePackage(id) && constraint.allows(id.version); |
491 | 491 |
492 int get hashCode => super.hashCode ^ constraint.hashCode; | 492 int get hashCode => super.hashCode ^ constraint.hashCode; |
493 | 493 |
494 bool operator ==(other) => | 494 bool operator ==(other) => |
495 other is PackageDep && | 495 other is PackageDep && |
496 samePackage(other) && | 496 samePackage(other) && |
497 other.constraint == constraint; | 497 other.constraint == constraint; |
498 } | 498 } |
OLD | NEW |