Skip to content

🔗 ShowReverseDependencies

Queries which installed packages depend on a given package (reverse dependencies). Equivalent to running composer depends <packageName>, commonly used to assess the impact of removing or upgrading a package.

📋 Signature

go
func (c *Composer) ShowReverseDependencies(packageName string) (string, error)

📥 Parameters

ParameterTypeDescription
packageNamestringName of the package whose reverse dependencies to query, e.g. "symfony/polyfill-mbstring"

📤 Return value

Return valueTypeDescription
First return valuestringStandard output text of composer depends <packageName>, listing all other packages that depend on this package
Second return valueerrorReturned when an error occurs during execution; nil indicates 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 Composer failed: %v", err)
	}

	output, err := comp.ShowReverseDependencies("symfony/polyfill-mbstring")
	if err != nil {
		log.Fatalf("get reverse dependencies failed: %v", err)
	}
	fmt.Println("packages that depend on this package:")
	fmt.Println(output)
}

🚀 Advanced

  • ❓ To find out why a package is installed (dependency chain): use WhyPackage (composer why <package>).
  • 🚫 To find out why a specific version cannot be installed: use WhyNotPackage (composer why-not <package> <version>).
  • ⚠️ When the queried package is not depended on by any package, or is not installed, Composer may exit with a non-zero exit code. In that case this method returns an error, which should be handled properly at the call site.
  • 🔧 Calling this before removing a package (Remove) can surface affected downstream packages in advance and avoid breaking the dependency chain.

Released under the MIT License