From fce7ae16f5aeaebfc6497f89afd4830f356c1126 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Wed, 30 Aug 2017 16:08:55 -0700 Subject: [PATCH] fix(compiler): treat absolute imports as package imports (#18912) This is a corner case, and converting them is what was expected in G3. This also fits the fact that we already convert package paths into relative paths. PR Close #18912 --- packages/compiler-cli/src/transformers/compiler_host.ts | 5 ++++- .../compiler-cli/test/transformers/compiler_host_spec.ts | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index 9d07cbfc4f..e2ae268f25 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -142,7 +142,10 @@ class CompilerHostMixin { resourceNameToFileName(resourceName: string, containingFile: string): string|null { // Note: we convert package paths into relative paths to be compatible with the the // previous implementation of UrlResolver. - if (resourceName && resourceName.charAt(0) !== '.' && !path.isAbsolute(resourceName)) { + const firstChar = resourceName[0]; + if (firstChar === '/') { + resourceName = resourceName.slice(1); + } else if (firstChar !== '.') { resourceName = `./${resourceName}`; } const filePathWithNgResource = diff --git a/packages/compiler-cli/test/transformers/compiler_host_spec.ts b/packages/compiler-cli/test/transformers/compiler_host_spec.ts index 9d86f460c6..10f5450e07 100644 --- a/packages/compiler-cli/test/transformers/compiler_host_spec.ts +++ b/packages/compiler-cli/test/transformers/compiler_host_spec.ts @@ -117,10 +117,10 @@ describe('NgCompilerHost', () => { .toBe('/tmp/src/a/child.html'); }); - it('should resolve absolute paths', () => { - const ngHost = createHost({files: {'tmp': {'src': {'a': {'child.html': '
'}}}}}); - expect(ngHost.resourceNameToFileName('/tmp/src/a/child.html', '/tmp/src/index.ts')) - .toBe('/tmp/src/a/child.html'); + it('should resolve absolute paths as package paths', () => { + const ngHost = createHost({files: {'tmp': {'node_modules': {'a': {'child.html': '
'}}}}}); + expect(ngHost.resourceNameToFileName('/a/child.html', '')) + .toBe('/tmp/node_modules/a/child.html'); }); }); });