Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix yarn install flags #1063

Merged
merged 5 commits into from
Dec 7, 2023
Merged
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
20 changes: 15 additions & 5 deletions xray/commands/audit/sca/yarn/yarn.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ const (
v1SilentFlag = "--silent"
// Disable interactive prompts, like when there’s an invalid version of a dependency.
v1NonInteractiveFlag = "--non-interactive"
// Ignores any build scripts
v2SkipBuildFlag = "--skip-builds"
// Skips linking and fetch only packages that are missing from yarn.lock file
v2UpdateLockfileFlag = "--mode=update-lockfile"
v3UpdateLockfileFlag = "--mode=update-lockfile"
// Ignores any build scripts
v2SkipBuildFlag = "--mode=skip-build"
v3SkipBuildFlag = "--mode=skip-build"
yarnV2Version = "2.0.0"
yarnV3Version = "3.0.0"
yarnV4Version = "4.0.0"
nodeModulesRepoName = "node_modules"
)
Expand Down Expand Up @@ -161,7 +164,8 @@ func runYarnInstallAccordingToVersion(curWd, yarnExecPath string, installCommand
return
}

isYarnV1 := version.NewVersion(executableVersionStr).Compare(yarnV2Version) > 0
yarnVersion := version.NewVersion(executableVersionStr)
isYarnV1 := yarnVersion.Compare(yarnV2Version) > 0

if isYarnV1 {
// When executing 'yarn install...', the node_modules directory is automatically generated.
Expand All @@ -181,9 +185,15 @@ func runYarnInstallAccordingToVersion(curWd, yarnExecPath string, installCommand

installCommandArgs = append(installCommandArgs, v1IgnoreScriptsFlag, v1SilentFlag, v1NonInteractiveFlag)
} else {
installCommandArgs = append(installCommandArgs, v2UpdateLockfileFlag, v2SkipBuildFlag)
// Checks if the version is V2 or V3 to insert the correct flags
if yarnVersion.Compare(yarnV3Version) > 0 {
installCommandArgs = append(installCommandArgs, v2SkipBuildFlag)
} else {
installCommandArgs = append(installCommandArgs, v3UpdateLockfileFlag, v3SkipBuildFlag)
}
}
return build.RunYarnCommand(yarnExecPath, curWd, installCommandArgs...)
err = build.RunYarnCommand(yarnExecPath, curWd, installCommandArgs...)
return
}

// Parse the dependencies into a Xray dependency tree format
Expand Down
Loading