From 4d6b4bc05c573eb1d152373e41dd864c1dc3c557 Mon Sep 17 00:00:00 2001 From: Nestor Cortina Date: Tue, 8 Oct 2024 02:47:30 -0500 Subject: [PATCH] fix: replace deprecated fs.rmdir with recursive removal logic --- packages/rspack/src/util/fs.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/rspack/src/util/fs.ts b/packages/rspack/src/util/fs.ts index 3609b1f271f..b7ec75c020e 100644 --- a/packages/rspack/src/util/fs.ts +++ b/packages/rspack/src/util/fs.ts @@ -11,6 +11,7 @@ import assert from "node:assert"; import type { Abortable } from "node:events"; import path from "node:path"; +import type { RmOptions } from "node:fs"; import type { WatchOptions } from "../config"; @@ -96,9 +97,10 @@ export interface OutputFileSystem { arg1?: (string | Buffer)[] | IDirent[] ) => void ) => void; - rmdir: ( + rm: ( arg0: string, - arg1: (arg0?: null | NodeJS.ErrnoException) => void + arg1: RmOptions, + arg2: (arg0?: null | NodeJS.ErrnoException) => void ) => void; unlink: ( arg0: string, @@ -499,7 +501,7 @@ export function rmrf( } let count = files!.length; if (count === 0) { - fs.rmdir(p, callback); + fs.rm(p, { recursive: true }, callback); } else { for (const file of files!) { assert(typeof file === "string"); @@ -510,7 +512,7 @@ export function rmrf( } count--; if (count === 0) { - fs.rmdir(p, callback); + fs.rm(p, { recursive: true }, callback); } }); }