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

NPM scan repository pushes node_modules into PR fix #551

Merged
Merged
23 changes: 21 additions & 2 deletions packagehandlers/npmpackagehandler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
package packagehandlers

import "github.com/jfrog/frogbot/utils"
import (
"fmt"
"github.com/jfrog/frogbot/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
"path/filepath"
)

const (
npmInstallPackageLockOnlyFlag = "--package-lock-only"
npmInstallIgnoreScriptsFlag = "--ignore-scripts"
)

type NpmPackageHandler struct {
CommonPackageHandler
Expand All @@ -19,5 +29,14 @@ func (npm *NpmPackageHandler) UpdateDependency(vulnDetails *utils.VulnerabilityD
}

func (npm *NpmPackageHandler) updateDirectDependency(vulnDetails *utils.VulnerabilityDetails) (err error) {
return npm.CommonPackageHandler.UpdateDependency(vulnDetails, vulnDetails.Technology.GetPackageInstallationCommand())
isNodeModulesExists, err := fileutils.IsDirExists(filepath.Join(".", "node_modules"), false)
eranturgeman marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
err = fmt.Errorf("failed while serching for node_modules in project: %s", err.Error())
return
}
if !isNodeModulesExists {
// In case node_modules don't exist in current dir the fix will update only package.json and package-lock.json
return npm.CommonPackageHandler.UpdateDependency(vulnDetails, vulnDetails.Technology.GetPackageInstallationCommand(), npmInstallPackageLockOnlyFlag, npmInstallIgnoreScriptsFlag)
}
return npm.CommonPackageHandler.UpdateDependency(vulnDetails, vulnDetails.Technology.GetPackageInstallationCommand(), npmInstallIgnoreScriptsFlag)
}
Loading