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 the caller passed in an unknown package name to isPackageTransformed, |
| 91 // the package will be null. |
| 92 if (package == null) return true; |
| 93 |
| 94 if (package.name == entrypoint.root.name) { |
| 95 return package.pubspec.transformers.isNotEmpty; |
| 96 } |
| 97 |
| 98 return package.pubspec.transformers.any((phase) { |
| 99 return phase.any((config) => config.canTransformPublicFiles); |
| 100 }); |
| 101 } |
| 102 |
75 /// Returns whether [package] is mutable. | 103 /// Returns whether [package] is mutable. |
76 /// | 104 /// |
77 /// A package is considered to be mutable if it or any of its dependencies | 105 /// 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 | 106 /// don't come from a cached source, since the user can change its contents |
79 /// without modifying the pub cache. Information generated from mutable | 107 /// without modifying the pub cache. Information generated from mutable |
80 /// packages is generally not safe to cache, since it may change frequently. | 108 /// packages is generally not safe to cache, since it may change frequently. |
81 bool isPackageMutable(String package) { | 109 bool isPackageMutable(String package) { |
82 var id = lockFile.packages[package]; | 110 var id = lockFile.packages[package]; |
83 if (id == null) return true; | 111 if (id == null) return true; |
84 | 112 |
(...skipping 22 matching lines...) Expand all Loading... |
107 bool isPackageStatic(String package) { | 135 bool isPackageStatic(String package) { |
108 var id = lockFile.packages[package]; | 136 var id = lockFile.packages[package]; |
109 if (id == null) return false; | 137 if (id == null) return false; |
110 | 138 |
111 var source = entrypoint.cache.sources[id.source]; | 139 var source = entrypoint.cache.sources[id.source]; |
112 if (source is! CachedSource) return false; | 140 if (source is! CachedSource) return false; |
113 | 141 |
114 return packages[package].pubspec.transformers.isEmpty; | 142 return packages[package].pubspec.transformers.isEmpty; |
115 } | 143 } |
116 } | 144 } |
OLD | NEW |