import type { Result } from '../lib'; import type { IFileSystemError } from './errors/filesystem.errors'; export interface IFileSystem { /** * Collection of utilities for working with paths in a OS-specific way */ path: { /** * Returns the path to the current working directory */ cwd(): string; /** * Returns the directory name of the given path. */ dirname: (path: string) => string; /** * Joins path with platform specific separator. */ join: (...path: string[]) => string; /** * Normalizes the given path. */ normalize: (path: string) => string; /** * Resolves path from left to the rightmost argument as an absolute path. */ resolve: (...pathSegments: string[]) => string; /** * Return the relative path from directory `from` to directory `to`. */ relative: (from: string, to: string) => string; }; /** * Synchronous variants of filesystem functions */ sync: { /** * Returns `true` if directory or file exists. */ exists: (path: string) => boolean; /** * Returns `true` if directory or file * exists, is readable and writable for the current user. */ isAccessible: (path: string) => boolean; /** * Returns `true` if `path` is a directory. * Returns `false` if `path` is not a directory or doesn't exist. */ isDirectory: (path: string) => boolean; /** * Returns `true` if `path` is a file. * Returns `false` if `path` is not a file or doesn't exist. */ isFile: (path: string) => boolean; /** * Creates a directory if it does not exist. */ mkdir: (path: string, options?: { recursive?: boolean; }) => Result; /** * Reads file content as string. */ readFile: (path: string) => Result; /** * Returns list of files at `path`. */ readdir: (path: string) => Result; /** * Removes file or director if it exists. * Fails silently if the directory does not exist or is not possible to remove it */ rm: (path: string, options?: { recursive?: boolean; }) => Result; /** * Writes string to file. */ writeFile: (path: string, data: string) => Result; }; /** * Returns `true` if directory or file exists. */ exists: (path: string) => Promise; /** * Returns `true` if directory or file * exists, is readable and writable for the current user. */ isAccessible: (path: string) => Promise; /** * Returns `true` if `path` is a directory. * Returns `false` if `path` is not a directory or doesn't exist. */ isDirectory: (path: string) => Promise; /** * Returns `true` if `path` is a file. * Returns `false` if `path` is not a file or doesn't exist. */ isFile: (path: string) => Promise; /** * Creates a directory if it does not exist. */ mkdir: (path: string, options?: { recursive?: boolean; }) => Promise>; /** * Reads file content as string. */ readFile: (path: string) => Promise>; /** * Returns list of files at `path`. */ readdir: (path: string) => Promise>; /** * Removes file or directory if it exists. * Fails silently if the directory does not exist or is not possible to remove it */ rm: (path: string, options?: { recursive?: boolean; }) => Promise>; /** * Writes string to file. */ writeFile: (path: string, data: string) => Promise>; }