From b1daf0a9afa1606e5a462753ded392e6f69b50ad Mon Sep 17 00:00:00 2001 From: Jongwoo Han Date: Thu, 15 Dec 2022 03:16:14 +0900 Subject: [PATCH] refactor: Use early return pattern Signed-off-by: jongwooo --- src/cache-utils.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cache-utils.ts b/src/cache-utils.ts index 5df3e718..48682388 100644 --- a/src/cache-utils.ts +++ b/src/cache-utils.ts @@ -63,21 +63,24 @@ const getPackageManagerVersion = async ( export const getPackageManagerInfo = async (packageManager: string) => { if (packageManager === 'npm') { return supportedPackageManagers.npm; - } else if (packageManager === 'pnpm') { - return supportedPackageManagers.pnpm; - } else if (packageManager === 'yarn') { - const yarnVersion = await getPackageManagerVersion('yarn', '--version'); + } + if (packageManager === 'pnpm') { + return supportedPackageManagers.pnpm; + } + + if (packageManager === 'yarn') { + const yarnVersion = await getPackageManagerVersion('yarn', '--version'); core.debug(`Consumed yarn version is ${yarnVersion}`); if (yarnVersion.startsWith('1.')) { return supportedPackageManagers.yarn1; - } else { - return supportedPackageManagers.yarn2; } - } else { - return null; + + return supportedPackageManagers.yarn2; } + + return null; }; export const getCacheDirectoryPath = async (