@appium/support
Version:
Support libs used across Appium packages
148 lines • 6.19 kB
TypeScript
import B from 'bluebird';
import { close, constants, createReadStream, createWriteStream, promises as fsPromises, read, open, type PathLike, type MakeDirectoryOptions, type ReadAsyncOptions } from 'node:fs';
import type { GlobOptions } from 'glob';
import klaw from 'klaw';
import type { Walker } from 'klaw';
import ncp from 'ncp';
import { type NormalizeOptions, type NormalizedPackageJson } from 'read-pkg';
import sanitize from 'sanitize-filename';
import which from 'which';
/** Options for {@linkcode fs.mv} */
export interface MvOptions {
/** Whether to automatically create the destination folder structure */
mkdirp?: boolean;
/** Set to false to throw if the destination file already exists */
clobber?: boolean;
/** @deprecated Legacy, not used */
limit?: number;
}
/**
* Callback used during directory walking in {@linkcode fs.walkDir}.
* Return true to stop walking.
*/
export type WalkDirCallback = (itemPath: string, isDirectory: boolean) => boolean | void | Promise<boolean | void>;
/**
* Promisified fs.read signature.
* @template TBuffer - Buffer type (e.g. NodeJS.ArrayBufferView)
* @deprecated use `typeof read.__promisify__` instead
*/
export type ReadFn<TBuffer extends NodeJS.ArrayBufferView = NodeJS.ArrayBufferView> = (fd: number, buffer: TBuffer | ReadAsyncOptions<TBuffer>, offset?: number, length?: number, position?: number | null) => B<{
bytesRead: number;
buffer: TBuffer;
}>;
export declare const fs: {
/**
* Resolves `true` if `path` is _readable_.
* On Windows, ACLs are not supported, so this becomes a simple check for existence.
* This function will never reject.
*/
hasAccess(filePath: PathLike): Promise<boolean>;
/**
* Resolves `true` if `path` is executable; `false` otherwise.
* On Windows, delegates to {@linkcode fs.hasAccess}.
* This function will never reject.
*/
isExecutable(filePath: PathLike): Promise<boolean>;
/** Alias for {@linkcode fs.hasAccess} */
exists(filePath: PathLike): Promise<boolean>;
/**
* Remove a directory and all its contents, recursively.
* @see https://nodejs.org/api/fs.html#fspromisesrmpath-options
*/
rimraf(filepath: PathLike): Promise<void>;
/**
* Remove a directory and all its contents, recursively (sync).
* @see https://nodejs.org/api/fs.html#fsrmsyncpath-options
*/
rimrafSync(filepath: PathLike): void;
/**
* Like Node.js `fsPromises.mkdir()`, but will not reject if the directory already exists.
* @see https://nodejs.org/api/fs.html#fspromisesmkdirpath-options
*/
mkdir(filepath: string | Buffer | URL, opts?: MakeDirectoryOptions): Promise<string | undefined>;
/**
* Copies files and entire directories.
* @see https://npm.im/ncp
*/
copyFile(source: string, destination: string, opts?: ncp.Options): Promise<void>;
/** Create an MD5 hash of a file. */
md5(filePath: PathLike): Promise<string>;
/**
* Move a file or a folder.
*/
mv(from: string, to: string, opts?: MvOptions): Promise<void>;
/** Find path to an executable in system `PATH`. @see https://github.com/npm/node-which */
which: typeof which;
/**
* Given a glob pattern, resolve with list of files matching that pattern.
* @see https://github.com/isaacs/node-glob
*/
glob(pattern: string, options?: GlobOptions): Promise<string[]>;
/** Sanitize a filename. @see https://github.com/parshap/node-sanitize-filename */
sanitizeName: typeof sanitize;
/** Create a hex digest of some file at `filePath`. */
hash(filePath: PathLike, algorithm?: string): Promise<string>;
/**
* Returns a Walker instance (readable stream / async iterator).
* @see https://www.npmjs.com/package/klaw
*/
walk(dir: string, opts?: klaw.Options): Walker;
/** Recursively create a directory. */
mkdirp(dir: PathLike): Promise<string | undefined>;
/**
* Walks a directory; callback is invoked with path joined with dir.
* @param dir - Directory path to start walking
* @param recursive - If true, walk subdirectories
* @param callback - Called for each path; return true to stop
* @returns The found path or null if not found
*/
walkDir(dir: string, recursive: boolean, callback: WalkDirCallback): Promise<string | null>;
/**
* Reads the closest `package.json` from absolute path `dir`.
* @throws If there were problems finding or reading `package.json`
*/
readPackageJsonFrom(dir: string, opts?: NormalizeOptions & {
cwd?: string;
}): NormalizedPackageJson;
/**
* Finds the project root directory from `dir`.
* @throws TypeError If `dir` is not a non-empty absolute path
* @throws Error If project root could not be found
*/
findRoot(dir: string): string;
access: typeof fsPromises.access;
appendFile: typeof fsPromises.appendFile;
chmod: typeof fsPromises.chmod;
close: typeof close.__promisify__;
constants: typeof constants;
createWriteStream: typeof createWriteStream;
createReadStream: typeof createReadStream;
lstat: typeof fsPromises.lstat;
/**
* Promisified fs.open. Resolves with a file descriptor (not FileHandle).
* Use fs.openFile for a FileHandle.
*/
open: typeof open.__promisify__;
openFile: typeof fsPromises.open;
readdir: typeof fsPromises.readdir;
read: typeof read.__promisify__;
readFile: typeof fsPromises.readFile;
readlink: typeof fsPromises.readlink;
realpath: typeof fsPromises.realpath;
rename: typeof fsPromises.rename;
stat: typeof fsPromises.stat;
symlink: typeof fsPromises.symlink;
unlink: typeof fsPromises.unlink;
write: (arg1: number, arg2: string) => B<number>;
writeFile: typeof fsPromises.writeFile;
/** @deprecated Use `constants.F_OK` instead. */
F_OK: number;
/** @deprecated Use `constants.R_OK` instead. */
R_OK: number;
/** @deprecated Use `constants.W_OK` instead. */
W_OK: number;
/** @deprecated Use `constants.X_OK` instead. */
X_OK: number;
};
export default fs;
//# sourceMappingURL=fs.d.ts.map