Skip to content

📈 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) error

Parameters

ParameterTypeDescription
packages[]stringList of package names to upgrade; pass an empty slice to upgrade all packages

Return value

ValueTypeDescription
ErrorerrorReturned 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) error
go
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.

Released under the MIT License