| 11 | const __dirname = path.dirname(__filename) |
| 12 | |
| 13 | async function removeDirWithRetries(dirPath, retries = 5, retryDelayMs = 200) { |
| 14 | for (let attempt = 0; attempt <= retries; attempt++) { |
| 15 | try { |
| 16 | await fs.promises.rm(dirPath, { recursive: true, force: true }) |
| 17 | return |
| 18 | } catch (error) { |
| 19 | const isRetryable = error?.code === "ENOTEMPTY" || error?.code === "EBUSY" || error?.code === "EPERM" |
| 20 | const isLastAttempt = attempt === retries |
| 21 | |
| 22 | if (!isRetryable || isLastAttempt) { |
| 23 | throw error |
| 24 | } |
| 25 | |
| 26 | await new Promise((resolve) => globalThis.setTimeout(resolve, retryDelayMs * (attempt + 1))) |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | async function main() { |
| 32 | const name = "extension" |