📈 BumpPackages
Upgrades the specified packages to the latest version that satisfies their version constraints in composer.json, equivalent to composer bump package1 package2 ....
When to use
- ⬆️ Pull dependencies to the latest version allowed by the constraints, without modifying the version constraints.
- 🧹 Clean up stale version records in
composer.lock. - 🔄 As the first step of an upgrade flow: bump first, then loosen constraints as needed.
Signature
go
func (c *Composer) BumpPackages(packages []string) errorParameters
| Parameter | Type | Description |
|---|---|---|
packages | []string | List of package names to upgrade; pass an empty slice to upgrade all packages |
Return value
| Value | Type | Description |
|---|---|---|
| Error | error | Returned when an error occurs while upgrading packages |
Example
go
package main
import (
"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)
}
// Upgrade multiple packages
if err := comp.BumpPackages([]string{"symfony/console", "symfony/process"}); err != nil {
log.Fatalf("failed to bump packages: %v", err)
}
// Pass an empty slice to upgrade all packages
if err := comp.BumpPackages([]string{}); err != nil {
log.Fatalf("failed to bump all packages: %v", err)
}
}Advanced
BumpPackagesWithOptions
Use when you need to attach flags such as --dry-run, --dev-only, --prefer-stable:
go
func (c *Composer) BumpPackagesWithOptions(packages []string, options map[string]string) errorgo
options := map[string]string{
"dev-only": "",
"prefer-stable": "",
"dry-run": "",
}
err := comp.BumpPackagesWithOptions([]string{"symfony/console"}, options)Difference between bump and update
bump only pulls to the latest within the constraints and does not change the version constraints in composer.json; update re-resolves dependencies and may update transitive dependencies. Use bump when you want to strictly upgrade within the constraints.
🔍 Related methods
OutdatedPackages: First see which packages can be upgraded.GetOutdatedInfo: A structured list of upgradeable packages.