Skip to content

🧪 RemoveDryRun Simulate removing a package

🔍 RemoveDryRun simulates removing a specified dependency package from the project without actually modifying composer.json or uninstalling the package. It is equivalent to running composer remove --dry-run packageName, suitable for previewing the impact before performing a removal.

📋 Signature

go
func (c *Composer) RemoveDryRun(packageName string) (string, error)

📥 Parameters

ParameterTypeDescription
packageNamestringThe name of the package to simulate removing, e.g. symfony/console

📤 Return value

Return valueTypeDescription
First return valuestringThe text output of the simulated removal process
Second return valueerrorReturned 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 --dev flag behavior, pass the dev argument explicitly.
  • 📦 To simulate a batch removal or with custom options (e.g. --no-update), refer to RemoveWithOptions and add "dry-run": "" to options for an equivalent effect.
  • 🧪 In CI, run RemoveDryRun first 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 standard vendor/package format to avoid ambiguity.

Released under the MIT License