Skip to content

Commit

Permalink
Simplify if/else logic for checking wrangler versions as per review n…
Browse files Browse the repository at this point in the history
…otes
  • Loading branch information
AdiRishi committed May 5, 2024
1 parent 06f5e60 commit 992c58e
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 992c58e

Please sign in to comment.