Skip to content

Commit

Permalink
chore: remove new rmdirSync
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed May 23, 2022
1 parent 70272dd commit 6a192be
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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' ||
Expand All @@ -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
Expand Down

0 comments on commit 6a192be

Please sign in to comment.