UNPKG

3.15 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8/// <amd-module name="@angular/compiler-cli/src/ngtsc/resource_loader" />
9import * as ts from 'typescript';
10import { CompilerHost } from '../transformers/api';
11import { ResourceLoader } from './annotations';
12/**
13 * `ResourceLoader` which delegates to a `CompilerHost` resource loading method.
14 */
15export declare class HostResourceLoader implements ResourceLoader {
16 private host;
17 private options;
18 private cache;
19 private fetching;
20 private rootDirs;
21 canPreload: boolean;
22 constructor(host: CompilerHost, options: ts.CompilerOptions);
23 /**
24 * Resolve the url of a resource relative to the file that contains the reference to it.
25 * The return value of this method can be used in the `load()` and `preload()` methods.
26 *
27 * Uses the provided CompilerHost if it supports mapping resources to filenames.
28 * Otherwise, uses a fallback mechanism that searches the module resolution candidates.
29 *
30 * @param url The, possibly relative, url of the resource.
31 * @param fromFile The path to the file that contains the URL of the resource.
32 * @returns A resolved url of resource.
33 * @throws An error if the resource cannot be resolved.
34 */
35 resolve(url: string, fromFile: string): string;
36 /**
37 * Preload the specified resource, asynchronously.
38 *
39 * Once the resource is loaded, its value is cached so it can be accessed synchronously via the
40 * `load()` method.
41 *
42 * @param resolvedUrl The url (resolved by a call to `resolve()`) of the resource to preload.
43 * @returns A Promise that is resolved once the resource has been loaded or `undefined` if the
44 * file has already been loaded.
45 * @throws An Error if pre-loading is not available.
46 */
47 preload(resolvedUrl: string): Promise<void> | undefined;
48 /**
49 * Load the resource at the given url, synchronously.
50 *
51 * The contents of the resource may have been cached by a previous call to `preload()`.
52 *
53 * @param resolvedUrl The url (resolved by a call to `resolve()`) of the resource to load.
54 * @returns The contents of the resource.
55 */
56 load(resolvedUrl: string): string;
57 /**
58 * Attempt to resolve `url` in the context of `fromFile`, while respecting the rootDirs
59 * option from the tsconfig. First, normalize the file name.
60 */
61 private fallbackResolve;
62 private getRootedCandidateLocations;
63 /**
64 * TypeScript provides utilities to resolve module names, but not resource files (which aren't
65 * a part of the ts.Program). However, TypeScript's module resolution can be used creatively
66 * to locate where resource files should be expected to exist. Since module resolution returns
67 * a list of file names that were considered, the loader can enumerate the possible locations
68 * for the file by setting up a module resolution for it that will fail.
69 */
70 private getResolvedCandidateLocations;
71}