From 3fb968443ba4635e42dc4dc9771e9cd999934e34 Mon Sep 17 00:00:00 2001 From: azlam Date: Fri, 25 Aug 2023 11:11:14 +1000 Subject: [PATCH] fix(validate): --installdeps flag was getting ignored in certain modes in validateAgainstOrg This commit simplifies the whole preDependncies installation and installs it as same as both for validate and validateAgainst Org, with only caveat being in validateAgainstOrg you need to be explicit with in installDeps --- .../src/impl/validate/ValidateImpl.ts | 121 ++++++------------ 1 file changed, 40 insertions(+), 81 deletions(-) diff --git a/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts b/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts index f1ffa03ed..07a9651ee 100644 --- a/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts +++ b/packages/sfpowerscripts-cli/src/impl/validate/ValidateImpl.ts @@ -650,88 +650,47 @@ export default class ValidateImpl implements PostDeployHook, PreDeployHook { } async preDeployPackage( - sfpPackage: SfpPackage, - targetUsername: string, - deployedPackages?: SfpPackage[], - devhubUserName?: string, - ): Promise<{ isToFailDeployment: boolean; message?: string }> { - //Its a scratch org fetched from pool.. install dependencies - //Assume hubOrg will be available, no need to check - switch (this.props.validateAgainst) { - case ValidateAgainst.PRECREATED_POOL: - if ( - this.props.validationMode == ValidationMode.THOROUGH || - this.props.validationMode == - ValidationMode.THOROUGH_LIMITED_BY_RELEASE_CONFIG - ) { - await this.installPackageDependencies( - ProjectConfig.getSFDXProjectConfig(null), - this.orgAsSFPOrg, - sfpPackage, - deployedPackages, - ); - } else if (this.props.validationMode == ValidationMode.INDIVIDUAL) { - await this.installPackageDependencies( - ProjectConfig.cleanupMPDFromProjectDirectory( - null, - sfpPackage.package_name, - ), - this.orgAsSFPOrg, - sfpPackage, - deployedPackages, - ); - } - else if (this.props.validationMode == ValidationMode.FASTFEEDBACK_LIMITED_BY_RELEASE_CONFIG - || this.props.validationMode == ValidationMode.FAST_FEEDBACK) { - if(this.props.installExternalDependencies) - await this.installPackageDependencies( - ProjectConfig.cleanupMPDFromProjectDirectory( - null, - sfpPackage.package_name, - ), - this.orgAsSFPOrg, - sfpPackage, - deployedPackages, - ); - } - break; - case ValidateAgainst.PROVIDED_ORG: - if (this.props.validationMode == ValidationMode.INDIVIDUAL) { - if (this.props.hubOrg) - await this.installPackageDependencies( - ProjectConfig.cleanupMPDFromProjectDirectory( - null, - sfpPackage.package_name, - ), - this.orgAsSFPOrg, - sfpPackage, - deployedPackages, - ); - else - SFPLogger.log( - `${COLOR_WARNING( - `DevHub was not provided, will skip installing /updating external dependencies of this package`, - )}`, - LoggerLevel.INFO, - ); - } - else if (this.props.validationMode == ValidationMode.FASTFEEDBACK_LIMITED_BY_RELEASE_CONFIG - || this.props.validationMode == ValidationMode.FAST_FEEDBACK) { - if(this.props.installExternalDependencies) - await this.installPackageDependencies( - ProjectConfig.cleanupMPDFromProjectDirectory( - null, - sfpPackage.package_name, - ), - this.orgAsSFPOrg, - sfpPackage, - deployedPackages, - ); - } - } + sfpPackage: SfpPackage, + targetUsername: string, + deployedPackages?: SfpPackage[], + devhubUserName?: string, +): Promise<{ isToFailDeployment: boolean; message?: string }> { + + const shouldInstallDependencies = (mode: ValidationMode) => { + if (this.props.validateAgainst === ValidateAgainst.PROVIDED_ORG && + !this.props.installExternalDependencies) { + return false; + } + + const isThoroughValidation = mode === ValidationMode.THOROUGH || + mode === ValidationMode.THOROUGH_LIMITED_BY_RELEASE_CONFIG; + + const isFastFeedbackWithExternalDependencies = + (mode === ValidationMode.FASTFEEDBACK_LIMITED_BY_RELEASE_CONFIG || + mode === ValidationMode.FAST_FEEDBACK) && + this.props.installExternalDependencies; + + return isThoroughValidation || + mode === ValidationMode.INDIVIDUAL || + isFastFeedbackWithExternalDependencies; + }; + + if (shouldInstallDependencies(this.props.validationMode)) { + const projectConfig = this.props.validationMode === ValidationMode.INDIVIDUAL ? + ProjectConfig.cleanupMPDFromProjectDirectory(null, sfpPackage.package_name) : + ProjectConfig.getSFDXProjectConfig(null); + + await this.installPackageDependencies( + projectConfig, + this.orgAsSFPOrg, + sfpPackage, + deployedPackages, + ); + } + + return { isToFailDeployment: false }; +} - return { isToFailDeployment: false }; - } async postDeployPackage( sfpPackage: SfpPackage,