feat(compiler): use typescript for resolving resource paths
This can also be customized via the new method `resourceNameToFileName` in the `CompilerHost`.
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AotCompilerHost, StaticSymbol, syntaxError} from '@angular/compiler';
|
||||
import {AotCompilerHost, StaticSymbol, UrlResolver, createOfflineCompileUrlResolver, syntaxError} from '@angular/compiler';
|
||||
import {AngularCompilerOptions, CollectorOptions, MetadataCollector, ModuleMetadata} from '@angular/tsc-wrapped';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
@ -40,6 +40,8 @@ export abstract class BaseAotCompilerHost<C extends BaseAotCompilerHostContext>
|
||||
|
||||
abstract moduleNameToFileName(m: string, containingFile: string): string|null;
|
||||
|
||||
abstract resourceNameToFileName(m: string, containingFile: string): string|null;
|
||||
|
||||
abstract fileNameToModuleName(importedFile: string, containingFile: string): string|null;
|
||||
|
||||
abstract toSummaryFileName(fileName: string, referringSrcFileName: string): string;
|
||||
@ -234,6 +236,7 @@ export class CompilerHost extends BaseAotCompilerHost<CompilerHostContext> {
|
||||
private isGenDirChildOfRootDir: boolean;
|
||||
private genDir: string;
|
||||
protected resolveModuleNameHost: CompilerHostContext;
|
||||
private urlResolver: UrlResolver;
|
||||
|
||||
constructor(
|
||||
program: ts.Program, options: AngularCompilerOptions, context: CompilerHostContext,
|
||||
@ -266,6 +269,7 @@ export class CompilerHost extends BaseAotCompilerHost<CompilerHostContext> {
|
||||
}
|
||||
return false;
|
||||
};
|
||||
this.urlResolver = createOfflineCompileUrlResolver();
|
||||
}
|
||||
|
||||
toSummaryFileName(fileName: string, referringSrcFileName: string): string {
|
||||
@ -382,6 +386,10 @@ export class CompilerHost extends BaseAotCompilerHost<CompilerHostContext> {
|
||||
}
|
||||
}
|
||||
|
||||
resourceNameToFileName(m: string, containingFile: string): string {
|
||||
return this.urlResolver.resolve(containingFile, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the path into `genDir` folder while preserving the `node_modules` directory.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user