UNPKG

2.12 kBTypeScriptView Raw
1import { AbsoluteFsPath, FileSystem, PathSegment, PathString } from './types';
2export declare function getFileSystem(): FileSystem;
3export declare function setFileSystem(fileSystem: FileSystem): void;
4/**
5 * Convert the path `path` to an `AbsoluteFsPath`, throwing an error if it's not an absolute path.
6 */
7export declare function absoluteFrom(path: string): AbsoluteFsPath;
8/**
9 * Extract an `AbsoluteFsPath` from a `ts.SourceFile`-like object.
10 */
11export declare function absoluteFromSourceFile(sf: {
12 fileName: string;
13}): AbsoluteFsPath;
14/**
15 * Convert the path `path` to a `PathSegment`, throwing an error if it's not a relative path.
16 */
17export declare function relativeFrom(path: string): PathSegment;
18/**
19 * Static access to `dirname`.
20 */
21export declare function dirname<T extends PathString>(file: T): T;
22/**
23 * Static access to `join`.
24 */
25export declare function join<T extends PathString>(basePath: T, ...paths: string[]): T;
26/**
27 * Static access to `resolve`s.
28 */
29export declare function resolve(basePath: string, ...paths: string[]): AbsoluteFsPath;
30/** Returns true when the path provided is the root path. */
31export declare function isRoot(path: AbsoluteFsPath): boolean;
32/**
33 * Static access to `isRooted`.
34 */
35export declare function isRooted(path: string): boolean;
36/**
37 * Static access to `relative`.
38 */
39export declare function relative<T extends PathString>(from: T, to: T): PathSegment | AbsoluteFsPath;
40/**
41 * Static access to `basename`.
42 */
43export declare function basename(filePath: PathString, extension?: string): PathSegment;
44/**
45 * Returns true if the given path is locally relative.
46 *
47 * This is used to work out if the given path is relative (i.e. not absolute) but also is not
48 * escaping the current directory.
49 */
50export declare function isLocalRelativePath(relativePath: string): boolean;
51/**
52 * Converts a path to a form suitable for use as a relative module import specifier.
53 *
54 * In other words it adds the `./` to the path if it is locally relative.
55 */
56export declare function toRelativeImport(relativePath: PathSegment | AbsoluteFsPath): PathSegment | AbsoluteFsPath;