-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict user from using yarn v4 (#1347)
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |