From 77c7d979b6215ddcac2f025a1506b7b1bc2b5a3b 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 dadad4ff57cb66..d299cff6120ffb 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -74,13 +74,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);