Skip to content

Commit

Permalink
fix(resolve): remove file readable check
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Dec 20, 2022
1 parent e3505ea commit 28b6200
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ function tryResolveFile(
skipPackageJson?: boolean,
): string | undefined {
const stat = fs.statSync(file, { throwIfNoEntry: false })
if (stat && (stat.mode & fs.constants.S_IRUSR) > 0) {
if (stat) {
if (!stat.isDirectory()) {
return getRealPath(file, options.preserveSymlinks) + postfix
} else if (tryIndex) {
Expand Down
8 changes: 6 additions & 2 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,12 @@ export function writeFile(
}

export function isFileReadable(filename: string): boolean {
const stat = fs.statSync(filename, { throwIfNoEntry: false })
return stat ? (stat.mode & fs.constants.S_IRUSR) > 0 : false
try {
fs.accessSync(filename, fs.constants.R_OK)
return true
} catch {
return false
}
}

const splitFirstDirRE = /(.+?)[\\/](.+)/
Expand Down

0 comments on commit 28b6200

Please sign in to comment.