From bc594e3bf810df9ccbd80741f05a3b30fe80750d Mon Sep 17 00:00:00 2001 From: Daphne Yang Date: Thu, 9 Nov 2023 16:35:36 -0500 Subject: [PATCH] refactor: use constants for SFDX CLI and SF CLI versions --- .../src/cli/checkCliVersion.ts | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/salesforcedx-utils/src/cli/checkCliVersion.ts b/packages/salesforcedx-utils/src/cli/checkCliVersion.ts index 55e69f3336..d6c99e8f2a 100644 --- a/packages/salesforcedx-utils/src/cli/checkCliVersion.ts +++ b/packages/salesforcedx-utils/src/cli/checkCliVersion.ts @@ -29,6 +29,14 @@ export class CheckCliVersion { } public async validateCliVersion(cliVersion: string): Promise { + // The last working version of SFDX is v7.193.2 + const minSFDXVersion = '7.193.2'; + const minSFDXVersionArray = minSFDXVersion.split('.').map(Number); + + // SF v1 does not map sf commands to sfdx commands and is not supported + const minSFVersion = '2.0.0'; + const minSFVersionArray = minSFVersion.split('.').map(Number); + // Parse the result to check if the version is supported const sfdxPattern = /sfdx-cli\/(\d+\.\d+\.\d+)/; const sfPattern = /@salesforce\/cli\/(\d+\.\d+\.\d+)/; @@ -40,11 +48,10 @@ export class CheckCliVersion { if (sfdxMatch) { const sfdxVersion = sfdxMatch[1]; const sfdxVersionNumber = sfdxVersion.split('.').map(Number); - // The last working version of SFDX is v7.193.2 if ( - sfdxVersionNumber[0] >= 7 && - sfdxVersionNumber[1] >= 193 && - sfdxVersionNumber[2] >= 2 + sfdxVersionNumber[0] >= minSFDXVersionArray[0] && + sfdxVersionNumber[1] >= minSFDXVersionArray[1] && + sfdxVersionNumber[2] >= minSFDXVersionArray[2] ) { return CheckCliEnum.validCli; } else { @@ -56,11 +63,10 @@ export class CheckCliVersion { else if (sfMatch) { const sfVersion = sfMatch[1]; const sfVersionNumber = sfVersion.split('.').map(Number); - // SF v1 does not map sf commands to sfdx commands and is not supported if ( - sfVersionNumber[0] >= 2 && - sfVersionNumber[1] >= 0 && - sfVersionNumber[2] >= 0 + sfVersionNumber[0] >= minSFVersionArray[0] && + sfVersionNumber[1] >= minSFVersionArray[1] && + sfVersionNumber[2] >= minSFVersionArray[2] ) { return CheckCliEnum.validCli; } else {