Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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.package_graph; | 5 library pub.package_graph; |
| 6 | 6 |
| 7 import 'barback/transformer_cache.dart'; | 7 import 'barback/transformer_cache.dart'; |
| 8 import 'entrypoint.dart'; | 8 import 'entrypoint.dart'; |
| 9 import 'lock_file.dart'; | 9 import 'lock_file.dart'; |
| 10 import 'package.dart'; | 10 import 'package.dart'; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 if (_transitiveDependencies == null) { | 65 if (_transitiveDependencies == null) { |
| 66 var closure = transitiveClosure(mapMap(packages, | 66 var closure = transitiveClosure(mapMap(packages, |
| 67 value: (_, package) => package.dependencies.map((dep) => dep.name))); | 67 value: (_, package) => package.dependencies.map((dep) => dep.name))); |
| 68 _transitiveDependencies = mapMap(closure, | 68 _transitiveDependencies = mapMap(closure, |
| 69 value: (_, names) => names.map((name) => packages[name]).toSet()); | 69 value: (_, names) => names.map((name) => packages[name]).toSet()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 return _transitiveDependencies[package]; | 72 return _transitiveDependencies[package]; |
| 73 } | 73 } |
| 74 | 74 |
| 75 /// Returns whether [package], or any of its transitive dependencies, have | |
| 76 /// transformers that run on any of their public assets. | |
| 77 /// | |
| 78 /// This is pessimistic; if any package can't be determined to be transformed, | |
| 79 /// this returns `true`. | |
| 80 bool isPackageTransformed(String packageName) { | |
| 81 if (_isIndividualPackageTransformed(packages[packageName])) return true; | |
| 82 | |
| 83 return transitiveDependencies(packageName) | |
| 84 .any(_isIndividualPackageTransformed); | |
| 85 } | |
| 86 | |
| 87 /// Returns whether [package] itself has transformers that run on any of its | |
| 88 /// public assets. | |
| 89 bool _isIndividualPackageTransformed(Package package) { | |
| 90 if (package == null) return true; | |
|
Bob Nystrom
2015/06/09 00:15:33
Document when this case comes into play.
nweiz
2015/06/09 00:37:34
Done.
| |
| 91 | |
| 92 if (package.name == entrypoint.root.name) { | |
| 93 return package.pubspec.transformers.isNotEmpty; | |
| 94 } | |
| 95 | |
| 96 return package.pubspec.transformers.any((phase) { | |
| 97 return phase.any((config) => config.canTransformPublicFiles); | |
| 98 }); | |
| 99 } | |
| 100 | |
| 75 /// Returns whether [package] is mutable. | 101 /// Returns whether [package] is mutable. |
| 76 /// | 102 /// |
| 77 /// A package is considered to be mutable if it or any of its dependencies | 103 /// A package is considered to be mutable if it or any of its dependencies |
| 78 /// don't come from a cached source, since the user can change its contents | 104 /// don't come from a cached source, since the user can change its contents |
| 79 /// without modifying the pub cache. Information generated from mutable | 105 /// without modifying the pub cache. Information generated from mutable |
| 80 /// packages is generally not safe to cache, since it may change frequently. | 106 /// packages is generally not safe to cache, since it may change frequently. |
| 81 bool isPackageMutable(String package) { | 107 bool isPackageMutable(String package) { |
| 82 var id = lockFile.packages[package]; | 108 var id = lockFile.packages[package]; |
| 83 if (id == null) return true; | 109 if (id == null) return true; |
| 84 | 110 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 107 bool isPackageStatic(String package) { | 133 bool isPackageStatic(String package) { |
| 108 var id = lockFile.packages[package]; | 134 var id = lockFile.packages[package]; |
| 109 if (id == null) return false; | 135 if (id == null) return false; |
| 110 | 136 |
| 111 var source = entrypoint.cache.sources[id.source]; | 137 var source = entrypoint.cache.sources[id.source]; |
| 112 if (source is! CachedSource) return false; | 138 if (source is! CachedSource) return false; |
| 113 | 139 |
| 114 return packages[package].pubspec.transformers.isEmpty; | 140 return packages[package].pubspec.transformers.isEmpty; |
| 115 } | 141 } |
| 116 } | 142 } |
| OLD | NEW |