Skip to content

Commit

Permalink
Restrict user from using yarn v4
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxxBot committed Feb 10, 2025
1 parent 60cd17a commit 3e83264
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion artifactory/utils/yarn/configget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions artifactory/utils/yarn/versionVerify.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit 3e83264

Please sign in to comment.