UNPKG

6.58 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC 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/core/src/host" />
9import ts from 'typescript';
10import { AbsoluteFsPath } from '../../file_system';
11import { ShimAdapter, ShimReferenceTagger } from '../../shims';
12import { FactoryTracker } from '../../shims/api';
13import { RequiredDelegations } from '../../util/src/typescript';
14import { ExtendedTsCompilerHost, NgCompilerAdapter, NgCompilerOptions, UnifiedModulesHost } from '../api';
15/**
16 * Delegates all methods of `ExtendedTsCompilerHost` to a delegate, with the exception of
17 * `getSourceFile` and `fileExists` which are implemented in `NgCompilerHost`.
18 *
19 * If a new method is added to `ts.CompilerHost` which is not delegated, a type error will be
20 * generated for this class.
21 */
22export declare class DelegatingCompilerHost implements Omit<RequiredDelegations<ExtendedTsCompilerHost>, 'getSourceFile' | 'fileExists'> {
23 protected delegate: ExtendedTsCompilerHost;
24 constructor(delegate: ExtendedTsCompilerHost);
25 private delegateMethod;
26 createHash: ((data: string) => string) | undefined;
27 directoryExists: ((directoryName: string) => boolean) | undefined;
28 fileNameToModuleName: ((importedFilePath: string, containingFilePath: string) => string) | undefined;
29 getCancellationToken: (() => ts.CancellationToken) | undefined;
30 getCanonicalFileName: (fileName: string) => string;
31 getCurrentDirectory: () => string;
32 getDefaultLibFileName: (options: ts.CompilerOptions) => string;
33 getDefaultLibLocation: (() => string) | undefined;
34 getDirectories: ((path: string) => string[]) | undefined;
35 getEnvironmentVariable: ((name: string) => string | undefined) | undefined;
36 getModifiedResourceFiles: (() => Set<string> | undefined) | undefined;
37 getNewLine: () => string;
38 getParsedCommandLine: ((fileName: string) => ts.ParsedCommandLine | undefined) | undefined;
39 getSourceFileByPath: ((fileName: string, path: ts.Path, languageVersion: ts.ScriptTarget, onError?: ((message: string) => void) | undefined, shouldCreateNewSourceFile?: boolean | undefined) => ts.SourceFile | undefined) | undefined;
40 readDirectory: ((rootDir: string, extensions: readonly string[], excludes: readonly string[] | undefined, includes: readonly string[], depth?: number | undefined) => string[]) | undefined;
41 readFile: (fileName: string) => string | undefined;
42 readResource: ((fileName: string) => string | Promise<string>) | undefined;
43 transformResource: ((data: string, context: import("@angular/compiler-cli/src/ngtsc/core/api/index").ResourceHostContext) => Promise<import("@angular/compiler-cli/src/ngtsc/core/api/index").TransformResourceResult | null>) | undefined;
44 realpath: ((path: string) => string) | undefined;
45 resolveModuleNames: ((moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ts.ResolvedProjectReference | undefined, options: ts.CompilerOptions) => (ts.ResolvedModule | undefined)[]) | undefined;
46 resolveTypeReferenceDirectives: ((typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ts.ResolvedProjectReference | undefined, options: ts.CompilerOptions) => (ts.ResolvedTypeReferenceDirective | undefined)[]) | undefined;
47 resourceNameToFileName: ((resourceName: string, containingFilePath: string, fallbackResolve?: ((url: string, fromFile: string) => string | null) | undefined) => string | null) | undefined;
48 trace: ((s: string) => void) | undefined;
49 useCaseSensitiveFileNames: () => boolean;
50 writeFile: ts.WriteFileCallback;
51}
52/**
53 * A wrapper around `ts.CompilerHost` (plus any extension methods from `ExtendedTsCompilerHost`).
54 *
55 * In order for a consumer to include Angular compilation in their TypeScript compiler, the
56 * `ts.Program` must be created with a host that adds Angular-specific files (e.g. factories,
57 * summaries, the template type-checking file, etc) to the compilation. `NgCompilerHost` is the
58 * host implementation which supports this.
59 *
60 * The interface implementations here ensure that `NgCompilerHost` fully delegates to
61 * `ExtendedTsCompilerHost` methods whenever present.
62 */
63export declare class NgCompilerHost extends DelegatingCompilerHost implements RequiredDelegations<ExtendedTsCompilerHost>, ExtendedTsCompilerHost, NgCompilerAdapter {
64 private shimAdapter;
65 private shimTagger;
66 readonly factoryTracker: FactoryTracker | null;
67 readonly entryPoint: AbsoluteFsPath | null;
68 readonly constructionDiagnostics: ts.Diagnostic[];
69 readonly inputFiles: ReadonlyArray<string>;
70 readonly rootDirs: ReadonlyArray<AbsoluteFsPath>;
71 constructor(delegate: ExtendedTsCompilerHost, inputFiles: ReadonlyArray<string>, rootDirs: ReadonlyArray<AbsoluteFsPath>, shimAdapter: ShimAdapter, shimTagger: ShimReferenceTagger, entryPoint: AbsoluteFsPath | null, factoryTracker: FactoryTracker | null, diagnostics: ts.Diagnostic[]);
72 /**
73 * Retrieves a set of `ts.SourceFile`s which should not be emitted as JS files.
74 *
75 * Available after this host is used to create a `ts.Program` (which causes all the files in the
76 * program to be enumerated).
77 */
78 get ignoreForEmit(): Set<ts.SourceFile>;
79 /**
80 * Retrieve the array of shim extension prefixes for which shims were created for each original
81 * file.
82 */
83 get shimExtensionPrefixes(): string[];
84 /**
85 * Performs cleanup that needs to happen after a `ts.Program` has been created using this host.
86 */
87 postProgramCreationCleanup(): void;
88 /**
89 * Create an `NgCompilerHost` from a delegate host, an array of input filenames, and the full set
90 * of TypeScript and Angular compiler options.
91 */
92 static wrap(delegate: ts.CompilerHost, inputFiles: ReadonlyArray<string>, options: NgCompilerOptions, oldProgram: ts.Program | null): NgCompilerHost;
93 /**
94 * Check whether the given `ts.SourceFile` is a shim file.
95 *
96 * If this returns false, the file is user-provided.
97 */
98 isShim(sf: ts.SourceFile): boolean;
99 getSourceFile(fileName: string, languageVersion: ts.ScriptTarget, onError?: ((message: string) => void) | undefined, shouldCreateNewSourceFile?: boolean | undefined): ts.SourceFile | undefined;
100 fileExists(fileName: string): boolean;
101 get unifiedModulesHost(): UnifiedModulesHost | null;
102 private createCachedResolveModuleNamesFunction;
103}