From 7c13e54ca75a0cb36a8399d0feaa5e2d833a7494 Mon Sep 17 00:00:00 2001 From: Daniel Bevenius Date: Tue, 8 May 2018 09:49:45 +0200 Subject: [PATCH] lib: return directly from packageMainCache MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates readPackage to return directly when calling packageMainCache instead of storing the result in a local var and returning later. PR-URL: https://github.com/nodejs/node/pull/20591 Reviewed-By: Michaël Zasso Reviewed-By: Gus Caplan Reviewed-By: Trivikram Kamat Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Tobias Nießen --- lib/internal/modules/cjs/loader.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 85ab3ab1443ded..8a4974225049ce 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -153,13 +153,12 @@ function readPackage(requestPath) { } try { - var pkg = packageMainCache[requestPath] = JSON.parse(json).main; + return packageMainCache[requestPath] = JSON.parse(json).main; } catch (e) { e.path = jsonPath; e.message = 'Error parsing ' + jsonPath + ': ' + e.message; throw e; } - return pkg; } function tryPackage(requestPath, exts, isMain) {