🧪 RemoveDryRun Simulate removing a package
🔍
RemoveDryRunsimulates removing a specified dependency package from the project without actually modifyingcomposer.jsonor uninstalling the package. It is equivalent to runningcomposer remove --dry-run packageName, suitable for previewing the impact before performing a removal.
📋 Signature
go
func (c *Composer) RemoveDryRun(packageName string) (string, error)📥 Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | The name of the package to simulate removing, e.g. symfony/console |
📤 Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | The text output of the simulated removal process |
| Second return value | error | Returned when an error occurs during the simulation; nil on success |
📝 Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.NewComposer()
if err != nil {
log.Fatalf("failed to create Composer instance: %v", err)
}
output, err := comp.RemoveDryRun("symfony/console")
if err != nil {
log.Fatalf("simulate removal failed: %v", err)
}
fmt.Println("Simulated removal result:")
fmt.Println(output)
}🚀 Advanced
- ✅ After the dry run passes, use
Remove(packageName, dev)to perform the real removal; to preserve the--devflag behavior, pass thedevargument explicitly. - 📦 To simulate a batch removal or with custom options (e.g.
--no-update), refer toRemoveWithOptionsand add"dry-run": ""tooptionsfor an equivalent effect. - 🧪 In CI, run
RemoveDryRunfirst to check whether it would break the dependency graph before deciding to commit the removal change. - 🔗 Under the hood it calls
c.Run("remove", "--dry-run", packageName); package names should use the standardvendor/packageformat to avoid ambiguity.