/** * @file Recursive copy for a file or directory tree, with three destination * modes (see {@link CopyMode}). Plain `fs.cp` (even with `force`) overwrites * files present in the source but never deletes destination files absent from * it, so copying onto an existing target leaves stale leftovers behind. The * `'pave'` mode makes the destination an exact copy of the source by staging * a fresh tree in a sibling temp directory and swapping it in with a single * rename — atomic, with no stale survivors. */ import type { PathLike } from 'node:fs'; /** * Named values for {@link CopyMode}. A frozen object rather than a TypeScript * `enum` so the declaration is erasable, since enums emit runtime helper code. */ export declare const CopyMode: Readonly<{ readonly Fill: 'fill'; readonly Overlay: 'overlay'; readonly Pave: 'pave'; }>; /** * How {@link copy} treats an existing destination. * * - `'overlay'` (default) — overwrite files present in the source but leave any * pre-existing destination-only files in place (a recursive `fs.cp`). * - `'pave'` — replace the destination so it becomes an exact copy of the source; * destination entries absent from the source do not survive. The swap is * atomic, renaming a sibling temp directory into place, so a partial tree is * never observable. * - `'fill'` — copy only what the destination lacks: existing files stay * untouched (no-clobber), missing ones are added. Never throws on an existing * file. * * Maps to `cp` (overlay), `rsync --delete` / robocopy `/MIR` (pave), and * `cp -n` (fill). */ export type CopyMode = (typeof CopyMode)[keyof typeof CopyMode]; /** * Options for {@link copy}. */ export interface CopyOptions { /** * Dereference symlinks — copy what each points to rather than the link * itself. * * @default false */ dereference?: boolean | undefined; /** * Predicate deciding which entries to copy. Return `false` to skip an entry; * skipping a directory also skips everything beneath it. Receives resolved * source and destination paths, matching `node:fs` `cp`'s `filter`. */ filter?: ((source: string, destination: string) => boolean) | undefined; /** * How to treat an existing destination. See {@link CopyMode}. * * @default 'overlay' */ mode?: CopyMode | undefined; /** * Abort signal to cancel the operation. */ signal?: AbortSignal | undefined; } /** * Copy one directory tree, sharing the bytes of every file when the filesystem * can. See {@link cloneFile} for what the sharing buys. * * Children come from one `readdir` with their types attached, so nothing stats * a path twice to learn what it is. Symlinks are recreated as symlinks: * following one would turn a link into a full copy of its target, and a link * pointing outside the tree would drag in whatever it names. * * @param from - Source directory. * @param to - Destination directory. */ export declare function cloneDir(from: PathLike, to: PathLike): Promise; /** * Copy one file, sharing its bytes with the source when the filesystem can. * * `COPYFILE_FICLONE` asks for a copy-on-write clone: APFS and Btrfs answer with * a metadata operation whatever the file size, and everything else copies the * bytes. A clone is NOT a hard link - the two files carry separate inodes and * separate mode bits, so writing one can never reach back into the other. * * @example * ;```js * // Near-free on APFS, a plain copy elsewhere. * await cloneFile('./template/hook.mts', './.cache/stage/hook.mts') * ``` * * @param from - Source file. * @param to - Destination file. */ export declare function cloneFile(from: PathLike, to: PathLike): Promise; /** * Recursively copy a file or directory tree from `from` to `to`. * * Works for both files and directories. The `mode` option chooses how an * existing destination is treated — overlay (default), pave, or fill; see * {@link CopyMode}. * * @example * ;```ts * // Overlay (default) — overwrite collisions, keep files already in dest: * await copy('./src', './dest') * * // Pave — dest ends up identical to src, no stale survivors: * await copy('./vendor/upstream', './deps/upstream', { mode: CopyMode.Pave }) * * // Fill — add only what's missing, never overwrite an existing file: * await copy('./defaults', './config', { mode: CopyMode.Fill }) * ``` * * @param from - Source file or directory to copy. * @param to - Destination path. * @param options - Copy options: mode, filter, dereference, abort signal. */ export declare function copy(from: PathLike, to: PathLike, options?: CopyOptions | undefined): Promise; /** * Forget that a filesystem refused to reflink, so the next clone asks again. */ export declare function resetReflinkSupport(): void;