( path: string | URL, options?: RemoveOptions, )
| 30 | * @param options Options when reading a file. See {@linkcode RemoveOptions}. |
| 31 | */ |
| 32 | export async function remove( |
| 33 | path: string | URL, |
| 34 | options?: RemoveOptions, |
| 35 | ) { |
| 36 | if (isDeno) { |
| 37 | await Deno.remove(path, options); |
| 38 | } else { |
| 39 | const { recursive = false } = options ?? {}; |
| 40 | try { |
| 41 | await getNodeFs().promises.rm(path, { recursive: recursive }); |
| 42 | } catch (error) { |
| 43 | if ((error as Error & { code: string }).code === "ERR_FS_EISDIR") { |
| 44 | try { |
| 45 | await getNodeFs().promises.rmdir(path); |
| 46 | } catch (error) { |
| 47 | throw mapError(error); |
| 48 | } |
| 49 | return; |
| 50 | } |
| 51 | throw mapError(error); |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Synchronously removes the named file or directory. |
no test coverage detected