Skip to content

Commit

Permalink
chore: simplify isFileReadable
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Feb 13, 2022
1 parent 7994e77 commit 3231932
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,15 +421,12 @@ export function writeFile(
* unnecessary in the first place)
*/
export function isFileReadable(filename: string): boolean {
let stat = null
try {
stat = fs.statSync(filename, { throwIfNoEntry: false })
} catch (e) {
if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false

throw e
const stat = fs.statSync(filename, { throwIfNoEntry: false })
return !!stat
} catch {
return false
}
return !!stat
}

/**
Expand Down

0 comments on commit 3231932

Please sign in to comment.