1 | /// <amd-module name="@angular/compiler-cli/ngcc/src/packages/source_file_cache" />
|
---|
2 | /**
|
---|
3 | * @license
|
---|
4 | * Copyright Google LLC All Rights Reserved.
|
---|
5 | *
|
---|
6 | * Use of this source code is governed by an MIT-style license that can be
|
---|
7 | * found in the LICENSE file at https://angular.io/license
|
---|
8 | */
|
---|
9 | import * as ts from 'typescript';
|
---|
10 | import { AbsoluteFsPath, ReadonlyFileSystem } from '../../../src/ngtsc/file_system';
|
---|
11 | /**
|
---|
12 | * A cache that holds on to source files that can be shared for processing all entry-points in a
|
---|
13 | * single invocation of ngcc. In particular, the following files are shared across all entry-points
|
---|
14 | * through this cache:
|
---|
15 | *
|
---|
16 | * 1. Default library files such as `lib.dom.d.ts` and `lib.es5.d.ts`. These files don't change
|
---|
17 | * and some are very large, so parsing is expensive. Therefore, the parsed `ts.SourceFile`s for
|
---|
18 | * the default library files are cached.
|
---|
19 | * 2. The typings of @angular scoped packages. The typing files for @angular packages are typically
|
---|
20 | * used in the entry-points that ngcc processes, so benefit from a single source file cache.
|
---|
21 | * Especially `@angular/core/core.d.ts` is large and expensive to parse repeatedly. In contrast
|
---|
22 | * to default library files, we have to account for these files to be invalidated during a single
|
---|
23 | * invocation of ngcc, as ngcc will overwrite the .d.ts files during its processing.
|
---|
24 | *
|
---|
25 | * The lifecycle of this cache corresponds with a single invocation of ngcc. Separate invocations,
|
---|
26 | * e.g. the CLI's synchronous module resolution fallback will therefore all have their own cache.
|
---|
27 | * This allows for the source file cache to be garbage collected once ngcc processing has completed.
|
---|
28 | */
|
---|
29 | export declare class SharedFileCache {
|
---|
30 | private fs;
|
---|
31 | private sfCache;
|
---|
32 | constructor(fs: ReadonlyFileSystem);
|
---|
33 | /**
|
---|
34 | * Loads a `ts.SourceFile` if the provided `fileName` is deemed appropriate to be cached. To
|
---|
35 | * optimize for memory usage, only files that are generally used in all entry-points are cached.
|
---|
36 | * If `fileName` is not considered to benefit from caching or the requested file does not exist,
|
---|
37 | * then `undefined` is returned.
|
---|
38 | */
|
---|
39 | getCachedSourceFile(fileName: string): ts.SourceFile | undefined;
|
---|
40 | /**
|
---|
41 | * Attempts to load the source file from the cache, or parses the file into a `ts.SourceFile` if
|
---|
42 | * it's not yet cached. This method assumes that the file will not be modified for the duration
|
---|
43 | * that this cache is valid for. If that assumption does not hold, the `getVolatileCachedFile`
|
---|
44 | * method is to be used instead.
|
---|
45 | */
|
---|
46 | private getStableCachedFile;
|
---|
47 | /**
|
---|
48 | * In contrast to `getStableCachedFile`, this method always verifies that the cached source file
|
---|
49 | * is the same as what's stored on disk. This is done for files that are expected to change during
|
---|
50 | * ngcc's processing, such as @angular scoped packages for which the .d.ts files are overwritten
|
---|
51 | * by ngcc. If the contents on disk have changed compared to a previously cached source file, the
|
---|
52 | * content from disk is re-parsed and the cache entry is replaced.
|
---|
53 | */
|
---|
54 | private getVolatileCachedFile;
|
---|
55 | }
|
---|
56 | /**
|
---|
57 | * Determines whether the provided path corresponds with a default library file inside of the
|
---|
58 | * typescript package.
|
---|
59 | *
|
---|
60 | * @param absPath The path for which to determine if it corresponds with a default library file.
|
---|
61 | * @param fs The filesystem to use for inspecting the path.
|
---|
62 | */
|
---|
63 | export declare function isDefaultLibrary(absPath: AbsoluteFsPath, fs: ReadonlyFileSystem): boolean;
|
---|
64 | /**
|
---|
65 | * Determines whether the provided path corresponds with a .d.ts file inside of an @angular
|
---|
66 | * scoped package. This logic only accounts for the .d.ts files in the root, which is sufficient
|
---|
67 | * to find the large, flattened entry-point files that benefit from caching.
|
---|
68 | *
|
---|
69 | * @param absPath The path for which to determine if it corresponds with an @angular .d.ts file.
|
---|
70 | * @param fs The filesystem to use for inspecting the path.
|
---|
71 | */
|
---|
72 | export declare function isAngularDts(absPath: AbsoluteFsPath, fs: ReadonlyFileSystem): boolean;
|
---|
73 | /**
|
---|
74 | * A cache for processing a single entry-point. This exists to share `ts.SourceFile`s between the
|
---|
75 | * source and typing programs that are created for a single program.
|
---|
76 | */
|
---|
77 | export declare class EntryPointFileCache {
|
---|
78 | private fs;
|
---|
79 | private sharedFileCache;
|
---|
80 | private readonly sfCache;
|
---|
81 | constructor(fs: ReadonlyFileSystem, sharedFileCache: SharedFileCache);
|
---|
82 | /**
|
---|
83 | * Returns and caches a parsed `ts.SourceFile` for the provided `fileName`. If the `fileName` is
|
---|
84 | * cached in the shared file cache, that result is used. Otherwise, the source file is cached
|
---|
85 | * internally. This method returns `undefined` if the requested file does not exist.
|
---|
86 | *
|
---|
87 | * @param fileName The path of the file to retrieve a source file for.
|
---|
88 | * @param languageVersion The language version to use for parsing the file.
|
---|
89 | */
|
---|
90 | getCachedSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile | undefined;
|
---|
91 | }
|
---|
92 | /**
|
---|
93 | * Creates a `ts.ModuleResolutionCache` that uses the provided filesystem for path operations.
|
---|
94 | *
|
---|
95 | * @param fs The filesystem to use for path operations.
|
---|
96 | */
|
---|
97 | export declare function createModuleResolutionCache(fs: ReadonlyFileSystem): ts.ModuleResolutionCache;
|
---|