Skip to content

🔗 UpdateWithDependencies

Updates the specified packages and their dependencies using the --with-dependencies option, not limited to the directly specified packages.

When to use

Use this when, after updating a package, its dependencies also need to be updated to remain compatible with the new version. Equivalent to running composer update --with-dependencies [packages...]. Note that Composer only updates the directly passed packages by default; dependency packages are not automatically upgraded.

Signature

go
func (c *Composer) UpdateWithDependencies(packages []string) error

Parameters

ParameterTypeDescription
packages[]stringList of package names to update; their dependencies will be updated as well; pass an empty slice to update all packages and dependencies

Return value

error: returns the corresponding error message when an error occurs during the update; nil on success.

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)
	}

	// Upgrade symfony/console and its dependencies to ensure overall compatibility
	if err := comp.UpdateWithDependencies([]string{"symfony/console"}); err != nil {
		log.Fatalf("update dependencies failed: %v", err)
	}

	fmt.Println("dependencies and sub-dependencies update complete")
}

Advanced

  • To recursively update all levels of dependencies, use UpdateWithAllDependencies (--with-all-dependencies).
  • When you need to combine --with-dependencies with other options, use UpdateWithOptions.
  • To update only the directly specified packages, see Update.

Released under the MIT License