Skip to content

Commit

Permalink
chore: remove confusing comment
Browse files Browse the repository at this point in the history
  • Loading branch information
brillout committed Nov 8, 2022
1 parent c1380cd commit 2842fd6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
3 changes: 0 additions & 3 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -531,9 +531,6 @@ function tryResolveFile(
tryPrefix?: string,
skipPackageJson?: boolean
): string | undefined {
// #2051 if we don't have read permission on a directory, existsSync() still
// works and will result in massively slow subsequent checks (which are
// unnecessary in the first place)
if (isFileReadable(file)) {
if (!fs.statSync(file).isDirectory()) {
return getRealPath(file, options.preserveSymlinks) + postfix
Expand Down
10 changes: 1 addition & 9 deletions packages/vite/src/node/utils.ts
Expand Up @@ -535,18 +535,10 @@ export function writeFile(
fs.writeFileSync(filename, content)
}

/**
* Use fs.statSync(filename) instead of fs.existsSync(filename)
* #2051 if we don't have read permission on a directory, existsSync() still
* works and will result in massively slow subsequent checks (which are
* unnecessary in the first place)
*/
export function isFileReadable(filename: string): boolean {
try {
const stat = fs.statSync(filename, { throwIfNoEntry: false })
// Test user permission. Throws error if no permission.
fs.accessSync(filename, fs.constants.R_OK)
return !!stat
return true
} catch {
return false
}
Expand Down

0 comments on commit 2842fd6

Please sign in to comment.