File size: 368 Bytes
fc93158 | 1 2 3 4 5 6 7 8 9 10 11 12 13 | import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
export async function withTempDir<T>(prefix: string, run: (dir: string) => Promise<T>): Promise<T> {
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
try {
return await run(dir);
} finally {
await fs.rm(dir, { recursive: true, force: true });
}
}
|