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

Fix bug where fs.exists is incorrectly promisified #835

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/node-resolve/src/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import fs from 'fs';

import { promisify } from 'util';

export const exists = promisify(fs.exists);
export const access = promisify(fs.access);
export const readFile = promisify(fs.readFile);
export const realpath = promisify(fs.realpath);
export { realpathSync } from 'fs';
export const stat = promisify(fs.stat);
export async function exists(filePath) {
Copy link

@merceyz merceyz Mar 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since fs.exists is just a wrapper around fs.access you should use that to make sure the behaviour is the same and to not unnecessarily create the stat object just to throw it away

https://github.com/nodejs/node/blob/5ff2e582cd867feba71bb13d9d8bed9953721145/lib/fs.js#L240-L252

try {
await access(filePath);
return true;
} catch {
return false;
}
}