Skip to content

Commit dccf975

Browse files
committed
Add maxRetries option to fs.rm to mitigate EPERM errors on Windows
- When using the `--save-bundle` and `--clean-dir` CLI arguments, we can get intermittent `EPERM` errors on Windows. Passing in the `maxRetries` option to `fs.rm` and `fs.rmdir` functions seems to resolve this issue.
1 parent 22c14ee commit dccf975

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

packages/size-limit/rm.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { existsSync } from 'node:fs'
2+
import fs from 'node:fs/promises'
3+
4+
export async function rm(dir) {
5+
if (!fs.rm) {
6+
/* c8 ignore next 3 */
7+
if (existsSync(dir)) {
8+
await fs.rmdir(dir, { maxRetries: 3, recursive: true })
9+
}
10+
} else {
11+
await fs.rm(dir, { force: true, maxRetries: 3, recursive: true })
12+
}
13+
}

0 commit comments

Comments
 (0)