🧩 IsPackageDev
Checks whether the specified package is declared in the require-dev section of composer.json, i.e. whether it is a development dependency.
When to use
Use this when you need to distinguish whether a package is a production dependency or only a development-time dependency. For example, deciding whether to remove it before packaging for release, or excluding development dependencies when generating a deployment manifest. It reads composer.json directly and does not execute Composer commands.
Signature
go
func (c *Composer) IsPackageDev(packageName string) (bool, error)Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | The package name to check, e.g. phpunit/phpunit |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | bool | Returns true if the package is in require-dev, otherwise false |
| Second return value | error | Returned when reading or parsing composer.json fails |
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatalf("Initialization failed: %v", err)
}
isDev, err := comp.IsPackageDev("phpunit/phpunit")
if err != nil {
log.Fatalf("Check failed: %v", err)
}
if isDev {
fmt.Println("phpunit/phpunit is a dev dependency 🧪")
} else {
fmt.Println("phpunit/phpunit is not a dev dependency 📦")
}
}Advanced
- To only check whether a package is installed (without distinguishing dev), use IsPackageInstalled.
- To read the complete
require-devlist, use ReadComposerJson. - To get a summary of the project's development dependencies, use GetProjectDependencies.