Skip to content

Commit

Permalink
fix(compiler): treat absolute imports as package imports (#18912)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tbosch authored and jasonaden committed Aug 31, 2017
1 parent 4059a72 commit fce7ae1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion packages/compiler-cli/src/transformers/compiler_host.ts
Expand Up @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions packages/compiler-cli/test/transformers/compiler_host_spec.ts
Expand Up @@ -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': '<div>'}}}}});
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': '<div>'}}}}});
expect(ngHost.resourceNameToFileName('/a/child.html', ''))
.toBe('/tmp/node_modules/a/child.html');
});
});
});

0 comments on commit fce7ae1

Please sign in to comment.