From 6a192be343bd2ba5ecf5939304a4a348bfa56d3e Mon Sep 17 00:00:00 2001 From: patak-dev Date: Mon, 23 May 2022 19:59:59 +0200 Subject: [PATCH] chore: remove new rmdirSync --- packages/vite/src/node/utils.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 45416c2900a7ea..14bfa259b165c0 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -525,16 +525,11 @@ export function copyDir(srcDir: string, destDir: string): void { } } -export function removeDirSync(dir: string) { - if (fs.existsSync(dir)) { - const rmSync = fs.rmSync ?? fs.rmdirSync // TODO: Remove after support for Node 12 is dropped - rmSync(dir, { recursive: true }) - } -} - export const removeDir = isWindows ? promisify(gracefulRemoveDir) - : removeDirSync + : function removeDirSync(dir: string) { + fs.rmSync(dir, { recursive: true, force: true }) + } export const renameDir = isWindows ? promisify(gracefulRename) : fs.renameSync export function ensureWatchedFile( @@ -835,10 +830,9 @@ function gracefulRemoveDir( dir: string, cb: (error: NodeJS.ErrnoException | null) => void ) { - const rmdir = fs.rm ?? fs.rmdir // TODO: Remove after support for Node 12 is dropped const start = Date.now() let backoff = 0 - rmdir(dir, { recursive: true }, function CB(er) { + fs.rm(dir, { recursive: true }, function CB(er) { if (er) { if ( (er.code === 'ENOTEMPTY' || @@ -847,7 +841,7 @@ function gracefulRemoveDir( Date.now() - start < GRACEFUL_REMOVE_DIR_TIMEOUT ) { setTimeout(function () { - rmdir(dir, { recursive: true }, CB) + fs.rm(dir, { recursive: true }, CB) }, backoff) if (backoff < 100) backoff += 10 return