Files
Moltbot/src/test-utils/temp-dir.ts
2026-02-22 07:44:57 +00:00

13 lines
368 B
TypeScript

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 });
}
}