-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: handle directory being passed to
Deno.remove
(#104)
- Loading branch information
Showing
8 changed files
with
84 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
///<reference path="../lib.deno.d.ts" /> | ||
|
||
import { rm } from "fs/promises"; | ||
import { rm, rmdir } from "fs/promises"; | ||
|
||
export const remove: typeof Deno.remove = function remove( | ||
export const remove: typeof Deno.remove = async function remove( | ||
path, | ||
options = {}, | ||
) { | ||
return rm(path, options.recursive ? { recursive: true, force: true } : {}); | ||
const innerOptions = options.recursive | ||
? { recursive: true, force: true } | ||
: {}; | ||
try { | ||
return await rm(path, innerOptions); | ||
} catch (err) { | ||
if ((err as any).code === "ERR_FS_EISDIR") { | ||
return await rmdir(path, innerOptions); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters