UNPKG

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