♻️ Reinstall
Reinstalls the specified package using Composer 2.2+'s native command, equivalent to composer reinstall packageName.
When to use
- 🩹 Recover after a package installation is corrupted (missing or modified files).
- 🔧 Reinstall when switching between
--prefer-source/--prefer-distinstallation modes. - 🧪 Fix installation anomalies caused by cache or interruption.
Signature
go
func (c *Composer) Reinstall(packageName string) errorParameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | The name of the package to reinstall |
Return value
| Value | Type | Description |
|---|---|---|
| Error | error | Returned when an error occurs during reinstallation |
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)
}
if err := comp.Reinstall("symfony/console"); err != nil {
log.Fatalf("reinstall package failed: %v", err)
}
}Advanced
ReinstallWithOptions
Use this when you need to attach flags such as --prefer-source or --prefer-dist:
go
func (c *Composer) ReinstallWithOptions(packageName string, options map[string]string) errorgo
options := map[string]string{"prefer-source": ""}
err := comp.ReinstallWithOptions("symfony/console", options)Batch reinstall
To reinstall multiple packages at once, use ReinstallMultiple(packages []string), equivalent to composer reinstall pkg1 pkg2 ....
Version requirement
reinstall is a native command introduced in Composer 2.2+. For older Composer versions, use the Remove + RequirePackage combination to achieve reinstallation.
🔍 Related methods
Remove/RequirePackage: the reinstallation alternative for older Composer.RemoveMultiple: batch removal.