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

Unified Diff: pkg/polymer/lib/src/loader.dart

Issue 148913003: Improve how we handle packages/ HTML imports. This resolves better any valid (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 | « pkg/polymer/lib/src/build/import_inliner.dart ('k') | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/polymer/lib/src/loader.dart
diff --git a/pkg/polymer/lib/src/loader.dart b/pkg/polymer/lib/src/loader.dart
index 48085e35a313b82f275f19df80a9c7fa504f98e4..28adf3dcf6832c511c0cb8c6125e50bf0b46e3f0 100644
--- a/pkg/polymer/lib/src/loader.dart
+++ b/pkg/polymer/lib/src/loader.dart
@@ -138,12 +138,17 @@ final _libs = currentMirrorSystem().libraries;
// root library (see dartbug.com/12612)
final _rootUri = currentMirrorSystem().isolate.rootLibrary.uri;
-final String _packageRoot =
- path.url.join(path.url.dirname(Uri.parse(window.location.href).path),
- 'packages') + '/';
-
final Logger _loaderLog = new Logger('polymer.loader');
+bool _isHttpStylePackageUrl(Uri uri) {
+ var uriPath = uri.path;
+ return uri.scheme == _rootUri.scheme &&
+ // Don't process cross-domain uris.
+ uri.authority == _rootUri.authority &&
+ uriPath.endsWith('.dart') &&
+ (uriPath.contains('/packages/') || uriPath.startsWith('packages/'));
+}
+
/**
* Reads the library at [uriString] (which can be an absolute URI or a relative
* URI from the root library), and:
@@ -157,10 +162,17 @@ final Logger _loaderLog = new Logger('polymer.loader');
void _loadLibrary(String uriString) {
var uri = _rootUri.resolve(uriString);
var lib = _libs[uri];
- if (uri.path.startsWith(_packageRoot) && uri.path.endsWith('.dart')) {
- var packageUri =
- Uri.parse('package:${uri.path.substring(_packageRoot.length)}');
- var canonicalLib = _libs[packageUri];
+ if (_isHttpStylePackageUrl(uri)) {
+ // Use package: urls if available. This rule here is more permissive than
+ // how we translate urls in polymer-build, but we expect Dartium to limit
+ // the cases where there are differences. The polymer-build issues an error
+ // when using packages/ inside lib without properly stepping out all the way
+ // to the packages folder. If users don't create symlinks in the source
+ // tree, then Dartium will also complain because it won't find the file seen
+ // in an HTML import.
+ var packagePath = uri.path.substring(
+ uri.path.lastIndexOf('packages/') + 'packages/'.length);
+ var canonicalLib = _libs[Uri.parse('package:$packagePath')];
if (canonicalLib != null) {
lib = canonicalLib;
}
« no previous file with comments | « pkg/polymer/lib/src/build/import_inliner.dart ('k') | pkg/polymer/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698