import { rm as fsRm } from "node:fs/promises"; const RETRY_CODES = new Set(["EBUSY", "EPERM"]); export async function retryRm( path: string, { maxRetries = 5, baseDelay = 100, _rm = fsRm, }: { maxRetries?: number; baseDelay?: number; _rm?: typeof fsRm } = {}, ): Promise { for (let attempt = 0; attempt <= maxRetries; attempt++) { try { await _rm(path, { recursive: true, force: true }); return; } catch (err: any) { if (!RETRY_CODES.has(err.code) || attempt === maxRetries) { throw err; } const delay = baseDelay * 2 ** attempt; await new Promise((resolve) => setTimeout(resolve, delay)); } } }