| 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.barback.transformer_config; | 5 library pub.barback.transformer_config; |
| 6 | 6 |
| 7 import 'package:path/path.dart' as p; |
| 7 import 'package:source_maps/source_maps.dart'; | 8 import 'package:source_maps/source_maps.dart'; |
| 8 import 'package:yaml/yaml.dart'; | 9 import 'package:yaml/yaml.dart'; |
| 9 | 10 |
| 10 import 'transformer_id.dart'; | 11 import 'transformer_id.dart'; |
| 11 | 12 |
| 12 /// The configuration for a transformer. | 13 /// The configuration for a transformer. |
| 13 /// | 14 /// |
| 14 /// This corresponds to the transformers listed in a pubspec, which have both an | 15 /// This corresponds to the transformers listed in a pubspec, which have both an |
| 15 /// [id] indicating the location of the transformer and configuration specific | 16 /// [id] indicating the location of the transformer and configuration specific |
| 16 /// to that use of the transformer. | 17 /// to that use of the transformer. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 /// | 47 /// |
| 47 /// This is processed after [includes]. If a transformer has both includes | 48 /// This is processed after [includes]. If a transformer has both includes |
| 48 /// and excludes, then the set of included assets is determined and assets | 49 /// and excludes, then the set of included assets is determined and assets |
| 49 /// are excluded from that resulting set. | 50 /// are excluded from that resulting set. |
| 50 final Set<String> excludes; | 51 final Set<String> excludes; |
| 51 | 52 |
| 52 /// Returns whether this config excludes certain asset ids from being | 53 /// Returns whether this config excludes certain asset ids from being |
| 53 /// processed. | 54 /// processed. |
| 54 bool get hasExclusions => includes != null || excludes != null; | 55 bool get hasExclusions => includes != null || excludes != null; |
| 55 | 56 |
| 57 /// Returns whether this transformer might transform a file that's visible to |
| 58 /// the package's dependers. |
| 59 bool get canTransformPublicFiles { |
| 60 if (includes == null) return true; |
| 61 return includes.any((path) => |
| 62 p.url.isWithin('lib', path) || p.url.isWithin('bin', path)); |
| 63 } |
| 64 |
| 56 /// Parses [identifier] as a [TransformerId] with [configuration]. | 65 /// Parses [identifier] as a [TransformerId] with [configuration]. |
| 57 /// | 66 /// |
| 58 /// [identifierSpan] is the source span for [identifier]. | 67 /// [identifierSpan] is the source span for [identifier]. |
| 59 factory TransformerConfig.parse(String identifier, Span identifierSpan, | 68 factory TransformerConfig.parse(String identifier, Span identifierSpan, |
| 60 YamlMap configuration) => | 69 YamlMap configuration) => |
| 61 new TransformerConfig(new TransformerId.parse(identifier, identifierSpan), | 70 new TransformerConfig(new TransformerId.parse(identifier, identifierSpan), |
| 62 configuration); | 71 configuration); |
| 63 | 72 |
| 64 factory TransformerConfig(TransformerId id, YamlMap configurationNode) { | 73 factory TransformerConfig(TransformerId id, YamlMap configurationNode) { |
| 65 parseField(key) { | 74 parseField(key) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // TODO(rnystrom): Support globs in addition to paths. See #17093. | 136 // TODO(rnystrom): Support globs in addition to paths. See #17093. |
| 128 if (excludes != null) { | 137 if (excludes != null) { |
| 129 // If there are any excludes, it must not match any of them. | 138 // If there are any excludes, it must not match any of them. |
| 130 if (excludes.contains(pathWithinPackage)) return false; | 139 if (excludes.contains(pathWithinPackage)) return false; |
| 131 } | 140 } |
| 132 | 141 |
| 133 // If there are any includes, it must match one of them. | 142 // If there are any includes, it must match one of them. |
| 134 return includes == null || includes.contains(pathWithinPackage); | 143 return includes == null || includes.contains(pathWithinPackage); |
| 135 } | 144 } |
| 136 } | 145 } |
| OLD | NEW |