Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 unsupportedYarnVersion = "4.0.0"

func IsInstalledYarnVersionSupported(executablePath string) error {
versionGetCmdConfig := getVersionCmdConfig(executablePath)
output, err := gofrogcmd.RunCmdOutput(versionGetCmdConfig)
if err != nil {
return errorutils.CheckError(err)
}
yarnVersion := strings.TrimSpace(output)
return IsVersionSupported(yarnVersion)
}

func IsVersionSupported(versionStr string) error {
yarnVersion := version.NewVersion(versionStr)
if yarnVersion.Compare(unsupportedYarnVersion) <= 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,
}
}
26 changes: 26 additions & 0 deletions artifactory/utils/yarn/versionVerify_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package yarn

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestIsVersionSupported(t *testing.T) {
tests := []struct {
versionStr string
expectErr bool
}{
{"3.9.0", false},
{"4.0.0", true},
{"4.1.0", true},
}

for _, test := range tests {
err := IsVersionSupported(test.versionStr)
if test.expectErr {
assert.Error(t, err, "Expected an error for version: %s", test.versionStr)
} else {
assert.NoError(t, err, "Did not expect an error for version: %s", test.versionStr)
}
}
}