From 7653bc83cb97eee774f59bf63fe74f82e895a668 Mon Sep 17 00:00:00 2001 From: Arya Emami Date: Sun, 26 May 2024 08:50:00 -0500 Subject: [PATCH] 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. --- packages/esbuild/index.js | 12 ++++++++++-- packages/webpack/index.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/packages/esbuild/index.js b/packages/esbuild/index.js index f9094e50..5450c111 100644 --- a/packages/esbuild/index.js +++ b/packages/esbuild/index.js @@ -63,7 +63,11 @@ export default [ async before(config) { if (config.saveBundle) { if (config.cleanDir) { - await rm(config.saveBundle, { force: true, recursive: true }) + await rm(config.saveBundle, { + force: true, + maxRetries: 3, + recursive: true + }) } else { let notEmpty = await isDirNotEmpty(config.saveBundle) if (notEmpty) { @@ -75,7 +79,11 @@ export default [ async finally(config, check) { if (check.esbuildOutfile && !config.saveBundle) { - await rm(check.esbuildOutfile, { force: true, recursive: true }) + await rm(check.esbuildOutfile, { + force: true, + maxRetries: 3, + recursive: true + }) } }, diff --git a/packages/webpack/index.js b/packages/webpack/index.js index ce19ab30..02ced120 100644 --- a/packages/webpack/index.js +++ b/packages/webpack/index.js @@ -59,7 +59,11 @@ export default [ async before(config) { if (config.saveBundle) { if (config.cleanDir) { - await rm(config.saveBundle, { force: true, recursive: true }) + await rm(config.saveBundle, { + force: true, + maxRetries: 3, + recursive: true + }) } else { let notEmpty = await isDirNotEmpty(config.saveBundle) if (notEmpty) { @@ -71,7 +75,11 @@ export default [ async finally(config, check) { if (check.webpackOutput && !config.saveBundle) { - await rm(check.webpackOutput, { force: true, recursive: true }) + await rm(check.webpackOutput, { + force: true, + maxRetries: 3, + recursive: true + }) } },