1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export type BrandedPath<B extends string> = string & {
|
15 | _brand: B;
|
16 | };
|
17 |
|
18 |
|
19 |
|
20 | export type AbsoluteFsPath = BrandedPath<'AbsoluteFsPath'>;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | export type PathSegment = BrandedPath<'PathSegment'>;
|
27 |
|
28 |
|
29 |
|
30 | export interface PathManipulation {
|
31 | extname(path: AbsoluteFsPath | PathSegment): string;
|
32 | isRoot(path: AbsoluteFsPath): boolean;
|
33 | isRooted(path: string): boolean;
|
34 | dirname<T extends PathString>(file: T): T;
|
35 | extname(path: AbsoluteFsPath | PathSegment): string;
|
36 | join<T extends PathString>(basePath: T, ...paths: string[]): T;
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | relative<T extends PathString>(from: T, to: T): PathSegment | AbsoluteFsPath;
|
45 | basename(filePath: string, extension?: string): PathSegment;
|
46 | normalize<T extends PathString>(path: T): T;
|
47 | resolve(...paths: string[]): AbsoluteFsPath;
|
48 | pwd(): AbsoluteFsPath;
|
49 | chdir(path: AbsoluteFsPath): void;
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 | export interface ReadonlyFileSystem extends PathManipulation {
|
55 | isCaseSensitive(): boolean;
|
56 | exists(path: AbsoluteFsPath): boolean;
|
57 | readFile(path: AbsoluteFsPath): string;
|
58 | readFileBuffer(path: AbsoluteFsPath): Uint8Array;
|
59 | readdir(path: AbsoluteFsPath): PathSegment[];
|
60 | lstat(path: AbsoluteFsPath): FileStats;
|
61 | stat(path: AbsoluteFsPath): FileStats;
|
62 | realpath(filePath: AbsoluteFsPath): AbsoluteFsPath;
|
63 | getDefaultLibLocation(): AbsoluteFsPath;
|
64 | }
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | export interface FileSystem extends ReadonlyFileSystem {
|
72 | writeFile(path: AbsoluteFsPath, data: string | Uint8Array, exclusive?: boolean): void;
|
73 | removeFile(path: AbsoluteFsPath): void;
|
74 | symlink(target: AbsoluteFsPath, path: AbsoluteFsPath): void;
|
75 | copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void;
|
76 | moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void;
|
77 | ensureDir(path: AbsoluteFsPath): void;
|
78 | removeDeep(path: AbsoluteFsPath): void;
|
79 | }
|
80 | export type PathString = string | AbsoluteFsPath | PathSegment;
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | export interface FileStats {
|
86 | isFile(): boolean;
|
87 | isDirectory(): boolean;
|
88 | isSymbolicLink(): boolean;
|
89 | }
|