Files
pmg/packagemanager/packagemanager.go
Abhisek DattaandGitHub e86b6ef056 feat: Refactor PMG to Maintain Separation of Concerns and Clean Architecture (#19)
* feat: Add separate package manager and resolver

* fix: Npm dependency resolver

* feat: Add analyzer for malysis query

* feat: Add package manager guard as the orchestrator

* feat: Add PMG to orchestrate installation

* Add concurrent scan execution

* Introduce package manager interaction abstraction

* feat: Add UI port for guard

* Remove refactored source files

* Update README

* fix: CI script for multi-arch build

* ci: goreleaser CI fix

* fix: npm command parser to extract package names

* feat: Introduce global config primitive

* fix: Close results channel for clean goroutine exit

* ci: Add container image releaser

* test: Improve test for npm resolver

* refactor: Analyzer to generalise

* Improve UI with additional info

* fix: Goreleaser config

* fix: npm resolver bug

* fix: Fail when command exec workflow fails

* fix: Bug with transitive dependency resolution

* fix: Synchronize common data update in dependency resolver

* chore: Improve log handling

* docs: Update README

* fix: UI text wrapping

* fix: UI handling bugs

* feat: Use concurrent dependency resolver
2025-05-15 16:50:59 +05:30

55 lines
1.6 KiB
Go

package packagemanager
import (
"context"
packagev1 "buf.build/gen/go/safedep/api/protocolbuffers/go/safedep/messages/package/v1"
)
type Command struct {
Exe string
Args []string
}
type PackageInstallTarget struct {
PackageVersion *packagev1.PackageVersion
}
func (pit *PackageInstallTarget) HasVersion() bool {
return pit.PackageVersion != nil && pit.PackageVersion.GetVersion() != ""
}
type ParsedCommand struct {
// Original command
Command Command
// Parsed install target if this is an install command
InstallTargets []*PackageInstallTarget
}
func (pc *ParsedCommand) HasInstallTarget() bool {
return len(pc.InstallTargets) > 0
}
// PackageManager is the contract for implementing a package manager
type PackageManager interface {
// Name of the package manager implementation
Name() string
// ParseCommand parses the command and returns a parsed command
// specific to the package manager implementation
ParseCommand(args []string) (*ParsedCommand, error)
}
// PackageResolver is the contract for resolving package info
type PackageResolver interface {
// ResolveLatestVersion resolves the latest version for a given package
ResolveLatestVersion(context.Context, *packagev1.Package) (*packagev1.PackageVersion, error)
// ResolveDependencies resolves the dependencies for a given package version
// It returns a flattened list of all the dependencies based on implementation
// specific config. The version resolution is based on minimum version selection
// for a given version range.
ResolveDependencies(context.Context, *packagev1.PackageVersion) ([]*packagev1.PackageVersion, error)
}