mirror of
https://github.com/safedep/pmg.git
synced 2026-08-03 07:24:09 +02:00
refactor: add Ecosystem() method to PackageManager interface
This commit is contained in:
+1
-12
@@ -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)
|
||||
|
||||
|
||||
@@ -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:]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:]
|
||||
|
||||
Reference in New Issue
Block a user