Skip to content

➖ 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.json and the lock file.
  • ♻️ Combine with RequirePackage to "switch versions": remove first, then add.
  • 🧪 Combine with RemoveDryRun to preview the impact of removal first.

Signature

go
func (c *Composer) Remove(packageName string, dev bool) error

Parameters

ParameterTypeDescription
packageNamestringThe name of the package to remove
devbooltrue to remove from development dependencies (require-dev)

Return value

ValueTypeDescription
ErrorerrorReturned 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) error

In 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.

Released under the MIT License