🗑️ RemoveRequire
Removes a dependency package from composer.json, deleting it from either the require or require-dev section based on isDev.
When to use
Use this when you need to programmatically clean up project dependency declarations. Symmetric with AddRequire, it only modifies the composer.json file itself and does not trigger an actual uninstall, making it suitable for scripts that maintain config files.
Signature
go
func (c *Composer) RemoveRequire(packageName string, isDev bool) errorParameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | The name of the package to remove |
isDev | bool | true to remove from require-dev, false to remove from require |
Return value
error: returned when reading or writingcomposer.jsonfails.
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.Fatal(err)
}
// Remove a production dependency
if err := comp.RemoveRequire("symfony/console", false); err != nil {
log.Fatal(err)
}
// Remove a development dependency
if err := comp.RemoveRequire("phpunit/phpunit", true); err != nil {
log.Fatal(err)
}
}Advanced
- 🔄 Internal flow of this method:
ReadComposerJSON→delete(map, key)→WriteComposerJSON. - ⚠️ When the corresponding map is
nilor the package does not exist, the method is a safe no-op and does not error. - 🚀 To actually uninstall from
vendor, useRemove(which runs thecomposer removecommand). For batch uninstall, useRemoveMultiple. - ➕ The corresponding add method is
AddRequire.