diff --git a/artifactory/utils/yarn/configget.go b/artifactory/utils/yarn/configget.go index 48d14c3b1..ab529c5c5 100644 --- a/artifactory/utils/yarn/configget.go +++ b/artifactory/utils/yarn/configget.go @@ -6,7 +6,7 @@ import ( "strings" ) -// This method runs "yarn config set" command and sets the yarn configuration. +// This method runs "yarn config get" command and sets the yarn configuration. func ConfigGet(key, executablePath string, jsonOutput bool) (string, error) { var flags []string = nil if jsonOutput { diff --git a/artifactory/utils/yarn/versionVerify.go b/artifactory/utils/yarn/versionVerify.go new file mode 100644 index 000000000..db58dcb47 --- /dev/null +++ b/artifactory/utils/yarn/versionVerify.go @@ -0,0 +1,39 @@ +package yarn + +import ( + gofrogcmd "github.com/jfrog/gofrog/io" + "github.com/jfrog/gofrog/version" + "github.com/jfrog/jfrog-client-go/utils/errorutils" + "strings" +) + +const UNSUPPORTED_YARN_VERSION = "4.0.0" + +func VerifyYarnVersionSupport(executablePath string) error { + versionGetCmdConfig := getVersionCmdConfig(executablePath) + output, err := gofrogcmd.RunCmdOutput(versionGetCmdConfig) + if err != nil { + return errorutils.CheckError(err) + } + yarnVersionStr := strings.TrimSpace(output) + return IsVersionSupported(yarnVersionStr) +} + +func IsVersionSupported(versionStr string) error { + yarnVersion := version.NewVersion(versionStr) + if yarnVersion.Compare(UNSUPPORTED_YARN_VERSION) < 0 { + return errorutils.CheckErrorf("Yarn version 4 is not supported. The current version is: " + versionStr + + ". Please downgrade to a compatible version to continue") + } + return nil +} + +func getVersionCmdConfig(executablePath string) *YarnConfig { + return &YarnConfig{ + Executable: executablePath, + Command: []string{"--version"}, + CommandFlags: nil, + StrWriter: nil, + ErrWriter: nil, + } +}