forked from isaacs/rimraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0833aa
commit 9986a81
Showing
3 changed files
with
18 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,20 @@ | ||
import { errorCode } from './error.js' | ||
|
||
export const ignoreENOENT = async <T>(p: Promise<T>) => | ||
export const ignoreENOENT = async <T>(p: Promise<T>, rethrow?: unknown) => | ||
p.catch(er => { | ||
if (errorCode(er) === 'ENOENT') { | ||
return | ||
} | ||
throw er | ||
throw rethrow ?? er | ||
}) | ||
|
||
export const didIgnoreENOENT = async (p: Promise<unknown>, rethrow?: unknown) => | ||
p | ||
.then(() => false) | ||
.catch(er => { | ||
if (errorCode(er) === 'ENOENT') { | ||
return true | ||
} | ||
throw rethrow ?? er | ||
}) | ||
|
||
export const ignoreENOENTSync = <T>(fn: () => T) => { | ||
export const ignoreENOENTSync = <T>(fn: () => T, rethrow?: unknown) => { | ||
try { | ||
return fn() | ||
} catch (er) { | ||
if (errorCode(er) === 'ENOENT') { | ||
return | ||
} | ||
throw er | ||
} | ||
} | ||
|
||
export const didIgnoreENOENTSync = (fn: () => unknown, rethrow?: unknown) => { | ||
try { | ||
fn() | ||
return false | ||
} catch (er) { | ||
if (errorCode(er) === 'ENOENT') { | ||
return true | ||
} | ||
throw rethrow ?? er | ||
} | ||
} |
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