➖ Remove
Removes the specified dependency package from the project, equivalent to composer remove [--dev] package/name.
When to use
- 🧹 Clean up dependencies that are no longer in use, reducing the size of
composer.jsonand the lock file. - ♻️ Combine with
RequirePackageto "switch versions": remove first, then add. - 🧪 Combine with
RemoveDryRunto preview the impact of removal first.
Signature
go
func (c *Composer) Remove(packageName string, dev bool) errorParameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | The name of the package to remove |
dev | bool | true to remove from development dependencies (require-dev) |
Return value
| Value | Type | Description |
|---|---|---|
| Error | error | Returned when an error occurs during package removal |
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)
}
// Remove a production dependency
if err := comp.Remove("symfony/console", false); err != nil {
log.Fatalf("remove production dependency failed: %v", err)
}
// Remove a development dependency
if err := comp.Remove("phpunit/phpunit", true); err != nil {
log.Fatalf("remove development dependency failed: %v", err)
}
}Advanced
RemoveWithOptions
Use this when you need to attach flags such as --no-update or --no-progress:
go
func (c *Composer) RemoveWithOptions(packageName string, options map[string]string) errorIn options, dev can also be expressed as "dev": "".
Batch removal
To remove multiple packages at once, use RemoveMultiple to avoid running composer remove multiple times.
🔍 Related methods
RequirePackage: add a dependency.RemoveDryRun: dry-run to preview the removal result.