Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: improve isFileReadable performance #12397

Merged
merged 3 commits into from Mar 30, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/vite/src/node/utils.ts
Expand Up @@ -537,7 +537,16 @@ export function writeFile(

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

if (!fileExists) {
return false
}
AriPerkkio marked this conversation as resolved.
Show resolved Hide resolved

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

return true
} catch {
return false
Expand Down