UNPKG

2.43 kBTypeScriptView Raw
1/// <amd-module name="@angular/compiler-cli/src/ngtsc/file_system/src/logical" />
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 */
9import ts from 'typescript';
10import { AbsoluteFsPath, BrandedPath, PathSegment } from './types';
11/**
12 * A path that's relative to the logical root of a TypeScript project (one of the project's
13 * rootDirs).
14 *
15 * Paths in the type system use POSIX format.
16 */
17export declare type LogicalProjectPath = BrandedPath<'LogicalProjectPath'>;
18export declare const LogicalProjectPath: {
19 /**
20 * Get the relative path between two `LogicalProjectPath`s.
21 *
22 * This will return a `PathSegment` which would be a valid module specifier to use in `from` when
23 * importing from `to`.
24 */
25 relativePathBetween: (from: LogicalProjectPath, to: LogicalProjectPath) => PathSegment;
26};
27/**
28 * A utility class which can translate absolute paths to source files into logical paths in
29 * TypeScript's logical file system, based on the root directories of the project.
30 */
31export declare class LogicalFileSystem {
32 private compilerHost;
33 /**
34 * The root directories of the project, sorted with the longest path first.
35 */
36 private rootDirs;
37 /**
38 * The same root directories as `rootDirs` but with each one converted to its
39 * canonical form for matching in case-insensitive file-systems.
40 */
41 private canonicalRootDirs;
42 /**
43 * A cache of file paths to project paths, because computation of these paths is slightly
44 * expensive.
45 */
46 private cache;
47 constructor(rootDirs: AbsoluteFsPath[], compilerHost: Pick<ts.CompilerHost, 'getCanonicalFileName'>);
48 /**
49 * Get the logical path in the project of a `ts.SourceFile`.
50 *
51 * This method is provided as a convenient alternative to calling
52 * `logicalPathOfFile(absoluteFromSourceFile(sf))`.
53 */
54 logicalPathOfSf(sf: ts.SourceFile): LogicalProjectPath | null;
55 /**
56 * Get the logical path in the project of a source file.
57 *
58 * @returns A `LogicalProjectPath` to the source file, or `null` if the source file is not in any
59 * of the TS project's root directories.
60 */
61 logicalPathOfFile(physicalFile: AbsoluteFsPath): LogicalProjectPath | null;
62 private createLogicalProjectPath;
63}