| Index: sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart b/sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart
|
| index e6f9912ef96e197e6ca6605e0bdd45aaaa607918..c6906dd3f3e4c25724845bf56cded7d0e93094c3 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart
|
| @@ -4,6 +4,7 @@
|
|
|
| library pub.barback.transformer_config;
|
|
|
| +import 'package:glob/glob.dart';
|
| import 'package:path/path.dart' as p;
|
| import 'package:source_span/source_span.dart';
|
| import 'package:yaml/yaml.dart';
|
| @@ -38,7 +39,7 @@ class TransformerConfig {
|
| /// This is processed before [excludes]. If a transformer has both includes
|
| /// and excludes, then the set of included assets is determined and assets
|
| /// are excluded from that resulting set.
|
| - final Set<String> includes;
|
| + final Set<Glob> includes;
|
|
|
| /// The primary input exclusions.
|
| ///
|
| @@ -48,7 +49,7 @@ class TransformerConfig {
|
| /// This is processed after [includes]. If a transformer has both includes
|
| /// and excludes, then the set of included assets is determined and assets
|
| /// are excluded from that resulting set.
|
| - final Set<String> excludes;
|
| + final Set<Glob> excludes;
|
|
|
| /// Returns whether this config excludes certain asset ids from being
|
| /// processed.
|
| @@ -58,8 +59,17 @@ class TransformerConfig {
|
| /// the package's dependers.
|
| bool get canTransformPublicFiles {
|
| if (includes == null) return true;
|
| - return includes.any((path) =>
|
| - p.url.isWithin('lib', path) || p.url.isWithin('bin', path));
|
| + return includes.any((glob) {
|
| + // Check whether the first path component of the glob is "lib", "bin", or
|
| + // contains wildcards that may cause it to match "lib" or "bin".
|
| + var first = p.posix.split(glob.toString()).first;
|
| + if (first.contains('{') || first.contains('*') || first.contains('[') ||
|
| + first.contains('?')) {
|
| + return true;
|
| + }
|
| +
|
| + return first == 'lib' || first == 'bin';
|
| + });
|
| }
|
|
|
| /// Parses [identifier] as a [TransformerId] with [configuration].
|
| @@ -76,20 +86,23 @@ class TransformerConfig {
|
| var fieldNode = configurationNode.nodes[key];
|
| var field = fieldNode.value;
|
|
|
| - if (field is String) return new Set.from([field]);
|
| -
|
| - if (field is List) {
|
| - for (var node in field.nodes) {
|
| - if (node.value is String) continue;
|
| - throw new SourceSpanFormatException(
|
| - '"$key" field may contain only strings.', node.span);
|
| - }
|
| + if (field is String) {
|
| + return new Set.from([new Glob(field, context: p.url, recursive: true)]);
|
| + }
|
|
|
| - return new Set.from(field);
|
| - } else {
|
| + if (field is! List) {
|
| throw new SourceSpanFormatException(
|
| '"$key" field must be a string or list.', fieldNode.span);
|
| }
|
| +
|
| + return new Set.from(field.nodes.map((node) {
|
| + if (node.value is String) {
|
| + return new Glob(node.value, context: p.url, recursive: true);
|
| + }
|
| +
|
| + throw new SourceSpanFormatException(
|
| + '"$key" field may contain only strings.', node.span);
|
| + }));
|
| }
|
|
|
| var includes = null;
|
| @@ -133,13 +146,15 @@ class TransformerConfig {
|
| /// [pathWithinPackage] must be a URL-style path relative to the containing
|
| /// package's root directory.
|
| bool canTransform(String pathWithinPackage) {
|
| - // TODO(rnystrom): Support globs in addition to paths. See #17093.
|
| if (excludes != null) {
|
| // If there are any excludes, it must not match any of them.
|
| - if (excludes.contains(pathWithinPackage)) return false;
|
| + for (var exclude in excludes) {
|
| + if (exclude.matches(pathWithinPackage)) return false;
|
| + }
|
| }
|
|
|
| // If there are any includes, it must match one of them.
|
| - return includes == null || includes.contains(pathWithinPackage);
|
| + return includes == null ||
|
| + includes.any((include) => include.matches(pathWithinPackage));
|
| }
|
| }
|
|
|