Skip to content

Commit

Permalink
perf: improve isFileReadable performance (#12397)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Mar 30, 2023
1 parent a59914c commit acf3a14
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/node/utils.ts
Expand Up @@ -501,7 +501,14 @@ export function generateCodeFrame(

export function isFileReadable(filename: string): boolean {
try {
// The "throwIfNoEntry" is a performance optimization for cases where the file does not exist
if (!fs.statSync(filename, { throwIfNoEntry: false })) {
return false
}

// Check if current process has read permission to the file
fs.accessSync(filename, fs.constants.R_OK)

return true
} catch {
return false
Expand Down

0 comments on commit acf3a14

Please sign in to comment.