ergebnis/composer-normalize
Composer plugin to normalize composer.json automatically: consistent key ordering, formatting, and sorting of dependencies. Avoid manual formatting debates and keep projects tidy across teams and CI with a simple dev requirement and allow-plugins setting.
Installation:
composer require --dev ergebnis/composer-normalize
Add to your project's composer.json under "extra":
"extra": {
"composer-normalize": {
"dry-run": false,
"sort-order": ["require", "require-dev", "config", "autoload"]
}
}
First Run:
composer normalize
This sorts and formats your composer.json according to predefined rules.
composer.json to match team conventions.composer normalize before submitting PRs to ensure consistency.composer.json files.Pre-Commit Hook:
Use with tools like Husky or [Git Hooks] to auto-format composer.json before commits:
composer normalize --dry-run # Validate without modifying files
CI Pipeline: Add to your CI (e.g., GitHub Actions) to enforce normalization:
- name: Normalize composer.json
run: composer normalize
Custom Sort Order:
Override defaults in composer.json:
"extra": {
"composer-normalize": {
"sort-order": [
"config",
"require",
"require-dev",
"autoload",
"autoload-dev"
]
}
}
composer.json for plugins (e.g., Laravel packages) to ensure consistent dependency ordering.--path to normalize multiple composer.json files in a single command:
composer normalize --path ./packages/*
Dry-Run Misuse:
Forgetting --dry-run in CI may overwrite files unexpectedly. Always test locally first.
Merge Conflicts:
Normalization may cause conflicts if multiple developers modify composer.json simultaneously. Use git merge --no-commit to resolve manually.
Custom Rules:
Overriding sort-order may break tooling (e.g., composer validate). Stick to the Composer schema for compatibility.
-v for detailed logs:
composer normalize -v
composer validate to catch schema issues:
composer validate && composer normalize
Custom Normalizers:
Extend via Composer Plugin API to add project-specific rules (e.g., alphabetical sorting for require).
Git Attributes:
Add .gitattributes to ignore normalized files (if using --no-sort):
composer.json filter=composer-normalize
Configuration Inheritance:
Use composer.json in monorepos to share normalization rules across projects.
How can I help you explore Laravel packages today?