fix(ivy): resolve resources using TS module resolution semantics (#27357)
Previously ngtsc assumed resource files (templateUrl, styleUrls) would be physically present in the file system relative to the .ts file which referenced them. However, ngc previously resolved such references in the context of ts.CompilerOptions.rootDirs. Material depends on this functionality in its build. This commit introduces resolution of resources by leveraging the TypeScript module resolver, ts.resolveModuleName(). This resolver is used in a way which will never succeed, but on failure will return a list of locations checked. This list is then filtered to obtain the correct potential locations of the resource. PR Close #27357
This commit is contained in:

committed by
Igor Minar

parent
cfb67edd85
commit
159788685a
@ -48,9 +48,11 @@ export class NgtscProgram implements api.Program {
|
||||
this.rootDirs.push(host.getCurrentDirectory());
|
||||
}
|
||||
this.closureCompilerEnabled = !!options.annotateForClosureCompiler;
|
||||
this.resourceLoader = host.readResource !== undefined ?
|
||||
new HostResourceLoader(host.readResource.bind(host)) :
|
||||
new FileResourceLoader();
|
||||
this.resourceLoader =
|
||||
host.readResource !== undefined && host.resourceNameToFileName !== undefined ?
|
||||
new HostResourceLoader(
|
||||
host.resourceNameToFileName.bind(host), host.readResource.bind(host)) :
|
||||
new FileResourceLoader(host, this.options);
|
||||
const shouldGenerateShims = options.allowEmptyCodegenFiles || false;
|
||||
this.host = host;
|
||||
let rootFiles = [...rootNames];
|
||||
|
Reference in New Issue
Block a user