Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
feat(transformers): Allow more complicated package uris
Browse files Browse the repository at this point in the history
Allow /packages/ identifier to appear anywhere in a uri and parse the AssetId correctly.
  • Loading branch information
Ted Sander authored and rkirov committed Mar 19, 2015
1 parent 16e8e14 commit 161cf82
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/tools/transformer/referenced_uris.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class _Processor {
static const String cacheAnnotationName =
'angular.template_cache_annotation.NgTemplateCache';
static const String componentAnnotationName = 'angular.core.annotation_src.Component';
static final RegExp pkgRegex = new RegExp(r'.*\/packages\/([^\/]*)(\/.*)');

_Processor(this.transform, this.resolver, this.options, this.skipNonCached,
this.templatesOnly, this.urlResolver) {
Expand Down Expand Up @@ -209,13 +210,13 @@ class _Processor {
return null;
}
if (path.url.isAbsolute(uri)) {
var parts = path.posix.split(uri);
if (parts[1] == 'packages') {
var pkgPath = path.url.join('lib', path.url.joinAll(parts.skip(3)));
return new _CacheEntry(uri, reference, new AssetId(parts[2], pkgPath));
var match = pkgRegex.firstMatch(uri);
if (match == null) {
warn('Cannot cache non-package absolute URIs. $uri', reference);
return null;
}
warn('Cannot cache non-package absolute URIs. $uri', reference);
return null;
var assetId = new AssetId(match.group(1), 'lib/${match.group(2)}');
return new _CacheEntry(uri, reference, assetId);
}
// Everything else is a resource in the web directory according to pub;
// as all packages URIs were handled above. As specified in this
Expand Down
38 changes: 38 additions & 0 deletions test/tools/transformer/template_cache_generator_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,44 @@ main() {
'angular|lib/template_cache.dart': libCacheAnnotation,
});
});

it('should cache complicated URLs', () {
return generates(setupPhases(),
inputs: {
'a|web/main.dart': '''
import 'package:angular/angular.dart';
import 'dir/foo.dart';
// Packages can be anywhere in the uri.
@Component(templateUrl: "/x/y/z/packages/a.b.c/test1.html",
cssUrl: "/packages/b/test1.css")
class A {}
main() {}
''',
'a|web/dir/foo.dart': '''
import 'package:angular/angular.dart';
// Packages may show up multiple times. Only the last value
// will be an identifier. Deeper paths after packages work.
@Component(
templateUrl: "/a/packages/z/packages/a/dir/test2.html",
cssUrl: "/packages/y/dir/dir2/dir3/test2.css")
class B {}
''',
'a.b.c|lib/test1.html': htmlContent1,
'a|lib/dir/test2.html': htmlContent2,
'angular|lib/angular.dart': libAngular,
'b|lib/test1.css': cssContent1,
'y|lib/dir/dir2/dir3/test2.css': cssContent2,
},
cacheContent: {
'/x/y/z/packages/a.b.c/test1.html': htmlContent1,
'/packages/b/test1.css': cssContent1,
'/a/packages/z/packages/a/dir/test2.html': htmlContent2,
'/packages/y/dir/dir2/dir3/test2.css': cssContent2,
});
});
});
}

Expand Down

0 comments on commit 161cf82

Please sign in to comment.