Skip to content

Commit

Permalink
perf(core): check files before interacting with them
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Apr 2, 2021
1 parent 86c44ba commit 67b6e93
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/babel-core/src/config/files/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export function makeStaticFileCache<T>(
}

function fileMtime(filepath: string): number | null {
if (!nodeFs.existsSync(filepath)) return null;

try {
return +nodeFs.statSync(filepath).mtime;
} catch (e) {
Expand Down
7 changes: 1 addition & 6 deletions packages/babel-core/src/gensync-utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ export const readFile = gensync<(filepath: string, encoding: "utf8") => string>(

export const exists = gensync<(filepath: string) => boolean>({
sync(path) {
try {
fs.accessSync(path);
return true;
} catch {
return false;
}
return fs.existsSync(path);
},
errback: (path, cb) => fs.access(path, undefined, err => cb(null, !err)),
});
Expand Down

0 comments on commit 67b6e93

Please sign in to comment.