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
This commit is contained in:
parent
4059a72710
commit
fce7ae16f5
|
@ -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 =
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue