import type * as fs from 'fs'; import type * as asyncFs from 'fs/promises'; import { ts } from './typescript'; import * as fg from 'fast-glob'; import { Writable, Readable } from 'readable-stream'; /** * A file system API based on a subset of the `fs` module from Node.js. */ export interface FileSystem { /** * Synchronously deletes the file or directory at the provided path. */ rmSync(path: string, options?: { recursive?: boolean; force?: boolean; }): void; /** * Synchronously retrieves the status of the file or directory at the provided path. */ statSync(path: string): FileSystem.Stats; /** * Synchronously retrieves the status of the file or directory at the provided path. Does * not dereference symbolic links. */ lstatSync(path: string): FileSystem.Stats; /** * Synchronously computes the canonical path by resolving `.`, `..` and symbolic links. */ realpathSync(path: string): string; /** * Synchronously creates a directory at the provided path. * * If `options.recursive` is `true`, the full path will be created including any missing * parent directories, and the path of the first directory created will be returned. * Otherwise, returns `undefined`. */ mkdirSync(path: string): void; mkdirSync(path: string, options: { recursive: true; }): string | undefined; mkdirSync(path: string, options?: { recursive: boolean; }): string | undefined; /** * Synchronously renames the file or directory at the old path to the new path. */ renameSync(oldPath: string, newPath: string): void; /** * Synchronously reads the contents of the directory at the provided path. * * If `options.withFileTypes` is `true`, returns the contents as an array of `Entry` * objects. Otherwise, returns the contents as an array of strings containing the names * of each entry. */ readdirSync(path: string): string[]; readdirSync(path: string, options: { withFileTypes: true; }): FileSystem.Entry[]; readdirSync(path: string, options?: { withFileTypes: boolean; }): string[] | FileSystem.Entry[]; /** * Synchronously reads the contents of the file at the provided path. * * If `options.encoding` is provided, the contents will be returned as a string. Otherwise, * the contents will be returned as a `Buffer`. */ readFileSync(path: string, options?: { flag: 'r'; }): Buffer; readFileSync(path: string, options: { encoding: FileSystem.Encoding; flag?: 'r'; }): string; readFileSync(path: string, options?: { encoding?: FileSystem.Encoding; flag?: 'r'; }): string | Buffer; /** * Synchronously writes the provided content to the file at the provided path. */ writeFileSync(path: string, content: string | NodeJS.ArrayBufferView, options?: { encoding: FileSystem.Encoding; }): void; /** * Synchronously copies the file at the source path to the destination path. */ copyFileSync(srcPath: string, destPath: string): void; /** * Synchronously checks if the file or directory at the provided path is accessible. If it * is accessible, the method does nothing. If it is not accessible, an error is thrown. */ accessSync(path: string): void; } export type AsyncFileSystem = { rm(path: fs.PathLike, options?: any): Promise; stat(path: fs.PathLike, options?: any): Promise; exists(path: fs.PathLike, options?: any): Promise; lstat: typeof asyncFs.lstat; mkdir: typeof asyncFs.mkdir; rename: typeof asyncFs.rename; readdir: typeof asyncFs.readdir; realpath: typeof asyncFs.realpath; readFile: typeof asyncFs.readFile; copyFile: typeof asyncFs.copyFile; writeFile: typeof asyncFs.writeFile; }; export declare namespace FileSystem { type Entry = { name: string; isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; isCharacterDevice(): boolean; isBlockDevice(): boolean; isSocket(): boolean; isFIFO(): boolean; }; type Stats = { isFile(): boolean; isDirectory(): boolean; isSymbolicLink(): boolean; isCharacterDevice(): boolean; isBlockDevice(): boolean; isSocket(): boolean; isFIFO(): boolean; }; type Encoding = 'utf-8' | 'binary'; /** * Synchronously copies the file or directory at the source path to the destination * path. If the source path is a directory, only its contents will be copied, not the * directory itself. If the source path is a file, the destination path cannot be a * directory. * * If `options.filter` is provided, only entries for which the filter returns `true` * will be copied. */ function copySync(fs: FileSystem, srcPath: string, destPath: string, options?: { filter(src: string): boolean; }): void; /** * Synchronously checks if the file or directory at the provided path exists. */ function existsSync(fs: FileSystem, path: string): boolean; function ensureDirSync(fs: FileSystem, path: string): void; /** * Provides an implementation of a write stream for FileSystems that don't * have one natively. Buffers all chunks in memory until finalized. */ function createWriteStream(fs: FileSystem, path: string): Writable; /** * Provides an implementation of a read stream for FileSystems that don't * have one natively. Reads the entire content as a single chunk. */ function createReadStream(fs: FileSystem, path: string): Readable; } export declare class TsMorphFileSystemWrapper implements ts.FileSystemHost { #private; private readonly fs; static ENOENT: string; constructor(fs: FileSystem); deleteSync(path: string): void; readFileSync(path: string, encoding?: FileSystem.Encoding): string; writeFileSync(path: string, text: string): void; mkdirSync(path: string): void; moveSync(srcPath: string, destPath: string): void; copySync(srcPath: string, destPath: string): void; fileExistsSync(path: string): boolean; directoryExistsSync(path: string): boolean; readDirSync(dir: string): ts.RuntimeDirEntry[]; globSync(patterns: string[], opts?: fg.Options): string[]; realpathSync(path: string): string; getCurrentDirectory(): string; isCaseSensitive(): boolean; delete(path: string): Promise; readFile(path: string, encoding?: FileSystem.Encoding): Promise; writeFile(path: string, text: string): Promise; mkdir(path: string): Promise; move(srcPath: string, destPath: string): Promise; copy(srcPath: string, destPath: string): Promise; fileExists(path: string): Promise; directoryExists(path: string): Promise; glob(patterns: string[]): Promise; }