Skip to content

Commit 0e63b6e

Browse files
committed
Restrict user from using yarn v4
1 parent 284c79c commit 0e63b6e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

artifactory/utils/yarn/configget.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"strings"
77
)
88

9-
// This method runs "yarn config set" command and sets the yarn configuration.
9+
// This method runs "yarn config get" command and sets the yarn configuration.
1010
func ConfigGet(key, executablePath string, jsonOutput bool) (string, error) {
1111
var flags []string = nil
1212
if jsonOutput {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package yarn
2+
3+
import (
4+
gofrogcmd "github.com/jfrog/gofrog/io"
5+
"github.com/jfrog/gofrog/version"
6+
"github.com/jfrog/jfrog-client-go/utils/errorutils"
7+
"strings"
8+
)
9+
10+
const UNSUPPORTED_YARN_VERSION = "4.0.0"
11+
12+
func VerifyYarnVersionSupport(executablePath string) error {
13+
versionGetCmdConfig := getVersionCmdConfig(executablePath)
14+
output, err := gofrogcmd.RunCmdOutput(versionGetCmdConfig)
15+
if err != nil {
16+
return errorutils.CheckError(err)
17+
}
18+
yarnVersionStr := strings.TrimSpace(output)
19+
return IsVersionSupported(yarnVersionStr)
20+
}
21+
22+
func IsVersionSupported(versionStr string) error {
23+
yarnVersion := version.NewVersion(versionStr)
24+
if yarnVersion.Compare(UNSUPPORTED_YARN_VERSION) < 0 {
25+
return errorutils.CheckErrorf("Yarn version 4 is not supported. The current version is: " + versionStr +
26+
". Please downgrade to a compatible version to continue")
27+
}
28+
return nil
29+
}
30+
31+
func getVersionCmdConfig(executablePath string) *YarnConfig {
32+
return &YarnConfig{
33+
Executable: executablePath,
34+
Command: []string{"--version"},
35+
CommandFlags: nil,
36+
StrWriter: nil,
37+
ErrWriter: nil,
38+
}
39+
}

0 commit comments

Comments
 (0)