fix(ngcc): handle deep imports that already have an extension (#32181)
During the dependency analysis phase of ngcc, imports are resolved to files on disk according to certain module resolution rules. Since module specifiers are typically missing extensions, or can refer to index.js barrel files within a directory, the module resolver attempts several postfixes when searching for a module import on disk. Module specifiers that already include an extension, however, would fail to be resolved as ngcc's module resolver failed to check the location on disk without adding any postfixes. Closes #32097 PR Close #32181
This commit is contained in:
parent
ae142a6827
commit
4bbf16e654
|
@ -25,7 +25,7 @@ export class ModuleResolver {
|
|||
private pathMappings: ProcessedPathMapping[];
|
||||
|
||||
constructor(private fs: FileSystem, pathMappings?: PathMappings, private relativeExtensions = [
|
||||
'.js', '/index.js'
|
||||
'', '.js', '/index.js'
|
||||
]) {
|
||||
this.pathMappings = pathMappings ? this.processPathMappings(pathMappings) : [];
|
||||
}
|
||||
|
|
|
@ -83,6 +83,12 @@ runInEachFileSystem(() => {
|
|||
const resolver = new ModuleResolver(getFileSystem());
|
||||
expect(resolver.resolveModuleImport('./y', _('/libs/local-package/index.js'))).toBe(null);
|
||||
});
|
||||
|
||||
it('should resolve modules that already include an extension', () => {
|
||||
const resolver = new ModuleResolver(getFileSystem());
|
||||
expect(resolver.resolveModuleImport('./x.js', _('/libs/local-package/index.js')))
|
||||
.toEqual(new ResolvedRelativeModule(_('/libs/local-package/x.js')));
|
||||
});
|
||||
});
|
||||
|
||||
describe('with non-mapped external paths', () => {
|
||||
|
|
Loading…
Reference in New Issue