Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Unified Diff: sdk/lib/_internal/pub/lib/src/barback/transformer_config.dart

Issue 686363002: Support globs in $include and $exclude. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/transformer/exclusion/exclude_asset_glob_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
}
}
« no previous file with comments | « no previous file | sdk/lib/_internal/pub/test/transformer/exclusion/exclude_asset_glob_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698