From 992c58e9327503225898d77d04c87dc84c1bcb13 Mon Sep 17 00:00:00 2001 From: Adishwar Rishi Date: Sun, 5 May 2024 22:57:24 +1000 Subject: [PATCH] Simplify if/else logic for checking wrangler versions as per review notes --- src/index.ts | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/index.ts b/src/index.ts index f8ad9d2b..c9b9b474 100755 --- a/src/index.ts +++ b/src/index.ts @@ -87,6 +87,7 @@ async function installWrangler() { startGroup("🔍 Checking for existing Wrangler installation"); let installedVersion = ""; + let installedVersionSatisfiesRequirement = false; try { const { stdout } = await getExecOutput( packageManager.exec, @@ -106,31 +107,27 @@ async function installWrangler() { if (versionMatch) { installedVersion = versionMatch[1]; } - if (installedVersion) { - if (config.didUserProvideWranglerVersion) { - if (semverEq(config.WRANGLER_VERSION, installedVersion)) { - info(`✅ Using Wrangler ${installedVersion}`, true); - endGroup(); - return; - } else { - info( - `Wrangler version ${installedVersion} is not equal to the required version. Installing...`, - true, - ); - } - } else { - info( - `✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`, - true, - ); - endGroup(); - return; - } + if (config.didUserProvideWranglerVersion) { + installedVersionSatisfiesRequirement = semverEq( + installedVersion, + config["WRANGLER_VERSION"], + ); + } + if (!config.didUserProvideWranglerVersion && installedVersion) { + info(`✅ No wrangler version specified, using pre-installed wrangler version ${installedVersion}`, true); + endGroup(); + return; + } + if (config.didUserProvideWranglerVersion && installedVersionSatisfiesRequirement) { + info(`✅ Using Wrangler ${installedVersion}`, true); + endGroup(); + return; } + info('⚠️ Wrangler not found or version is incompatible. Installing...', true); } catch (error) { debug(`Error checking Wrangler version: ${error}`); info( - "Wrangler not found or version is not compatible. Installing...", + "⚠️ Wrangler not found or version is incompatible. Installing...", true, ); } finally {