refactor: add Ecosystem() method to PackageManager interface

This commit is contained in:
Sahilb315
2025-06-11 17:13:55 +05:30
parent af27701b8d
commit 8b8a98b13d
4 changed files with 12 additions and 12 deletions
+1 -12
View File
@@ -279,19 +279,8 @@ func (g *packageManagerGuard) clearStatus() {
func (g *packageManagerGuard) handleManifestInstallation(ctx context.Context, parsedCommand *packagemanager.ParsedCommand) error {
g.setStatus("Extracting packages from manifest files")
// Create extractor with appropriate ecosystem
var ecosystem packagev1.Ecosystem
switch g.packageManager.Name() {
case "pip":
ecosystem = packagev1.Ecosystem_ECOSYSTEM_PYPI
case "npm", "pnpm":
ecosystem = packagev1.Ecosystem_ECOSYSTEM_NPM
default:
return fmt.Errorf("unsupported package manager for manifest extraction: %s", g.packageManager.Name())
}
extractorConfig := extractor.NewDefaultExtractorConfig()
extractorConfig.ExtractorEcosystem = ecosystem
extractorConfig.ExtractorEcosystem = g.packageManager.Ecosystem()
packageExtractor := extractor.New(*extractorConfig)
+4
View File
@@ -43,6 +43,10 @@ func (npm *npmPackageManager) Name() string {
return "npm"
}
func (npm *npmPackageManager) Ecosystem() packagev1.Ecosystem {
return packagev1.Ecosystem_ECOSYSTEM_NPM
}
func (npm *npmPackageManager) ParseCommand(args []string) (*ParsedCommand, error) {
if len(args) > 0 && (args[0] == "npm" || args[0] == "pnpm") {
args = args[1:]
+3
View File
@@ -60,6 +60,9 @@ type PackageManager interface {
// ParseCommand parses the command and returns a parsed command
// specific to the package manager implementation
ParseCommand(args []string) (*ParsedCommand, error)
// Ecosystem of the package manager
Ecosystem() packagev1.Ecosystem
}
// PackageResolver is the contract for resolving package info
+4
View File
@@ -37,6 +37,10 @@ func (pip *pipPackageManager) Name() string {
return "pip"
}
func (pip *pipPackageManager) Ecosystem() packagev1.Ecosystem {
return packagev1.Ecosystem_ECOSYSTEM_PYPI
}
func (pip *pipPackageManager) ParseCommand(args []string) (*ParsedCommand, error) {
if len(args) > 0 && args[0] == "pip" {
args = args[1:]