Skip to content

Commit

Permalink
fix(optimizer): check .vite/deps directory existence before removing (#…
Browse files Browse the repository at this point in the history
…11499)

Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
  • Loading branch information
jeromehan and bluwy authored Jan 3, 2023
1 parent 3748acb commit 1b043f9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,12 @@ export function copyDir(srcDir: string, destDir: string): void {
export const removeDir = isWindows
? promisify(gracefulRemoveDir)
: function removeDirSync(dir: string) {
fs.rmSync(dir, { recursive: true, force: true })
// when removing `.vite/deps`, if it doesn't exist, nodejs may also remove
// other directories within `.vite/`, including `.vite/deps_temp` (bug).
// workaround by checking for directory existence before removing for now.
if (fs.existsSync(dir)) {
fs.rmSync(dir, { recursive: true, force: true })
}
}
export const renameDir = isWindows ? promisify(gracefulRename) : fs.renameSync

Expand Down

0 comments on commit 1b043f9

Please sign in to comment.