From f639fe4c559e893465aa1944f9b382426a8a49d2 Mon Sep 17 00:00:00 2001 From: Rob Stolarz Date: Wed, 30 Nov 2022 14:14:54 -0600 Subject: [PATCH] Skip stat call / throwing when files don't exist (#225) --- src/filesystem.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/filesystem.ts b/src/filesystem.ts index a6773a7..9bc1605 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -33,6 +33,10 @@ export interface ReadJsonAsync { } export function fileExistsSync(path: string): boolean { + // If the file doesn't exist, avoid throwing an exception over the native barrier for every miss + if (!fs.existsSync(path)) { + return false; + } try { const stats = fs.statSync(path); return stats.isFile();