with-local-tmp-dir
Version:
Creates a temporary folder inside cwd, cds inside the folder, runs a function, and removes the folder. Especially useful for testing.
26 lines (25 loc) • 1.08 kB
TypeScript
import type { DirOptions } from 'tmp';
export interface NameOptions {
dir: string;
prefix: string;
postfix?: string;
template?: string;
name?: string;
}
export interface Options extends NameOptions {
tries: number;
keep: boolean;
unsafeCleanup: boolean;
mode: number;
}
/**
* A callback which runs in the context of a temporary directory. After the callback is completed context is returned to the original directory.
* */
export type TmpDirCallback<T> = () => T;
export type WithLocalTmpDirArgs<T> = TmpDirCallback<T> | Options;
/**
* A promise returned from withLocalTmpDir that, when executed, cleans up the tmp directory. Can be used instead of the callback.
* */
export type ResetFunc = () => Promise<void>;
declare const _default: (<TCallbackReturn>(callback: TmpDirCallback<TCallbackReturn>, options?: DirOptions) => Promise<TCallbackReturn>) & (<TCallbackReturn>(options: DirOptions, callback: TmpDirCallback<TCallbackReturn>) => Promise<TCallbackReturn>) & ((options?: DirOptions) => Promise<ResetFunc>);
export default _default;