fix relative @HtmlImport paths in deep folders in deployment mode

R=sigmund@google.com

Review URL: https://codereview.chromium.org//981273002
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6f0c931..f1be1f8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,6 @@
+#### 0.10.5+1
+  * Fix @HtmlImport with relative paths from within folders in deployment mode.
+
 #### 0.10.5
   * Update `ImportCrawler` with support for pre-parsed initial documents. This
     allows it to work better with other transformers in the same step (you can
diff --git a/lib/build/html_import_annotation_recorder.dart b/lib/build/html_import_annotation_recorder.dart
index 336ee7c..e517e33 100644
--- a/lib/build/html_import_annotation_recorder.dart
+++ b/lib/build/html_import_annotation_recorder.dart
@@ -79,7 +79,7 @@
           path.url.joinAll(segments.getRange(1, segments.length)),
           from: path.url.dirname(path.url.join(bootstrapId.path)));
     } else if (segments[1] == 'lib') {
-      libPath = path.url.joinAll(segments.getRange(1, segments.length));
+      libPath = path.url.joinAll(segments.getRange(2, segments.length));
     } else {
       logger.error('Unable to import `${element.source.uri.path}` from '
           '${bootstrapId}.');
diff --git a/lib/src/normalize_path.dart b/lib/src/normalize_path.dart
index bac6b8b..129dfe6 100644
--- a/lib/src/normalize_path.dart
+++ b/lib/src/normalize_path.dart
@@ -13,16 +13,13 @@
   }
 
   var dartFileDir = path.url.dirname(dartFilePath);
-  var segments = path.url.split(dartFileDir);
-  // The dartFileDir without the leading dir (web, lib, test, etc).
-  var dartFileSubDir = path.url.joinAll(segments.getRange(1, segments.length));
 
   // Relative paths have no package supplied.
   if (dartFilePackage == null) {
-    return path.url.normalize(path.url.join(dartFileSubDir, filePath));
+    return path.url.normalize(path.url.join(dartFileDir, filePath));
   }
 
   // Only option left is a packages/ path.
   return path.url.normalize(
-      path.url.join('packages/', dartFilePackage, dartFileSubDir, filePath));
+      path.url.join('packages/', dartFilePackage, dartFileDir, filePath));
 }
diff --git a/pubspec.yaml b/pubspec.yaml
index d11d54e..ebc2995 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
 name: web_components
-version: 0.10.5
+version: 0.10.5+1
 author: Polymer.dart Authors <web-ui-dev@dartlang.org>
 homepage: https://www.dartlang.org/polymer-dart/
 description: >
diff --git a/test/foo/bar.dart b/test/foo/bar.dart
new file mode 100644
index 0000000..6784550
--- /dev/null
+++ b/test/foo/bar.dart
@@ -0,0 +1,7 @@
+// Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+@HtmlImport('bar.html')
+library web_components.test.foo.bar;
+
+import 'package:web_components/web_components.dart';
diff --git a/test/foo/bar.html b/test/foo/bar.html
new file mode 100644
index 0000000..5716ca5
--- /dev/null
+++ b/test/foo/bar.html
@@ -0,0 +1 @@
+bar
diff --git a/test/html_import_annotation_test.dart b/test/html_import_annotation_test.dart
index cae624a..09a3ffd 100644
--- a/test/html_import_annotation_test.dart
+++ b/test/html_import_annotation_test.dart
@@ -11,6 +11,7 @@
 import 'package:unittest/html_config.dart';
 import 'package:unittest/unittest.dart';
 import 'package:web_components/html_import_annotation.dart';
+import 'foo/bar.dart';
 
 const String importPath = 'my_import.html';
 
@@ -19,8 +20,14 @@
 
   test('adds import to head', () {
     return init.run().then((_) {
-      var good = document.head.querySelector('link[href="$importPath"]');
-      expect(good.import.body.text, 'Hello world!\n');
+      var my_import = document.head.querySelector('link[href="$importPath"]');
+      expect(my_import, isNotNull);
+      expect(my_import.import.body.text, 'Hello world!\n');
+
+      var bar = document.head.querySelector('link[href="foo/bar.html"]');
+      expect(bar, isNotNull);
+      expect(bar.import.body.text, 'bar\n');
+
       var bad = document.head.querySelector('link[href="bad_import.html"]');
       expect(bad.import, isNull);
     });