🚫 WhyNotPackage
Explains why a specific version of a package cannot be installed. Equivalent to composer why-not package/name version.
When to use
- 🐛 When you hit a conflict while upgrading or pinning a version and need to locate which constraint blocks the installation.
- 🔍 To evaluate whether a specific version can be introduced.
- 📋 To explain the root cause of a version choice in a dependency review.
Signature
go
func (c *Composer) WhyNotPackage(packageName string, version string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | Name of the package to query |
version | string | Version to query, e.g. v4.0.0 |
Return value
| Value | Type | Description |
|---|---|---|
| Output | string | Output of the explanation, listing the chain of constraints that block the installation |
| Error | error | Returned when an error occurs during the query |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("init failed: %v", err)
}
output, err := comp.WhyNotPackage("symfony/console", "v4.0.0")
if err != nil {
log.Fatalf("query version constraint failed: %v", err)
}
fmt.Println("reason it cannot be installed:", output)
}Advanced
WhyNotWithOptions
Use this when you need to pass additional options (additional_methods.go):
go
func (c *Composer) WhyNotWithOptions(packageName, version string, options map[string]string) (string, error)Forward question
- To find out "why a package is installed", use
WhyPackage. - To find out "whether you can upgrade to the latest", use
OutdatedPackagesor the structuredGetOutdatedInfo.
Version format
version should be a version string Composer can recognize, such as v4.0.0, ^4.0, etc. Passing an invalid format may produce error output that is hard to interpret.
🔍 Related methods
WhyPackage: explain why a package is installed.OutdatedPackages: view upgradeable packages.