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:
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import {MissingTranslationStrategy, ViewEncapsulation, ɵConsole as Console} from '@angular/core';
|
||||
|
||||
import {CompilerConfig} from '../config';
|
||||
import {DirectiveNormalizer} from '../directive_normalizer';
|
||||
import {DirectiveResolver} from '../directive_resolver';
|
||||
@ -22,7 +23,8 @@ import {PipeResolver} from '../pipe_resolver';
|
||||
import {DomElementSchemaRegistry} from '../schema/dom_element_schema_registry';
|
||||
import {StyleCompiler} from '../style_compiler';
|
||||
import {TemplateParser} from '../template_parser/template_parser';
|
||||
import {createOfflineCompileUrlResolver} from '../url_resolver';
|
||||
import {UrlResolver} from '../url_resolver';
|
||||
import {syntaxError} from '../util';
|
||||
import {ViewCompiler} from '../view_compiler/view_compiler';
|
||||
|
||||
import {AotCompiler} from './compiler';
|
||||
@ -33,6 +35,19 @@ import {StaticSymbol, StaticSymbolCache} from './static_symbol';
|
||||
import {StaticSymbolResolver} from './static_symbol_resolver';
|
||||
import {AotSummaryResolver} from './summary_resolver';
|
||||
|
||||
export function createAotUrlResolver(host: {
|
||||
resourceNameToFileName(resourceName: string, containingFileName: string): string | null;
|
||||
}): UrlResolver {
|
||||
return {
|
||||
resolve: (basePath: string, url: string) => {
|
||||
const filePath = host.resourceNameToFileName(url, basePath);
|
||||
if (!filePath) {
|
||||
throw syntaxError(`Couldn't resolve resource ${url} from ${basePath}`);
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new AotCompiler based on options and a host.
|
||||
@ -41,7 +56,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
|
||||
{compiler: AotCompiler, reflector: StaticReflector} {
|
||||
let translations: string = options.translations || '';
|
||||
|
||||
const urlResolver = createOfflineCompileUrlResolver();
|
||||
const urlResolver = createAotUrlResolver(compilerHost);
|
||||
const symbolCache = new StaticSymbolCache();
|
||||
const summaryResolver = new AotSummaryResolver(compilerHost, symbolCache);
|
||||
const symbolResolver = new StaticSymbolResolver(compilerHost, symbolCache, summaryResolver);
|
||||
|
@ -14,6 +14,11 @@ import {AotSummaryResolverHost} from './summary_resolver';
|
||||
* services and from underlying file systems.
|
||||
*/
|
||||
export interface AotCompilerHost extends StaticSymbolResolverHost, AotSummaryResolverHost {
|
||||
/**
|
||||
* Converts a path that refers to a resource into an absolute filePath
|
||||
* that can be later on used for loading the resource via `loadResource.
|
||||
*/
|
||||
resourceNameToFileName(resourceName: string, containingFileName: string): string|null;
|
||||
/**
|
||||
* Loads a resource (e.g. html / css)
|
||||
*/
|
||||
|
Reference in New Issue
Block a user