From 543ecbdbd83e2b7e2ec7dc4c02a4aa1deb0a8d4f Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 16 Jan 2021 20:05:26 +0100 Subject: [PATCH] module: simplify tryStatSync with throwIfNoEntry option PR-URL: https://github.com/nodejs/node/pull/36971 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell --- lib/internal/modules/esm/resolve.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 98683441586784..5a578902cbb01a 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -104,13 +104,8 @@ function getConditionsSet(conditions) { const realpathCache = new SafeMap(); const packageJSONCache = new SafeMap(); /* string -> PackageConfig */ -function tryStatSync(path) { - try { - return statSync(path); - } catch { - return new Stats(); - } -} +const tryStatSync = + (path) => statSync(path, { throwIfNoEntry: false }) ?? new Stats(); function getPackageConfig(path, specifier, base) { const existing = packageJSONCache.get(path);