localheinz/composer-normalize
Normalize your composer.json consistently. localheinz/composer-normalize sorts keys, formats lists, and enforces a stable structure to reduce diffs and keep projects tidy. Works well in CI and pre-commit hooks for repeatable results.
Installation Add the plugin to your project via Composer:
composer require --dev localheinz/composer-normalize
Ensure composer.json includes the plugin under "config":
{
"config": {
"allow-plugins": {
"localheinz/composer-normalize": true
}
}
}
First Run
Normalize your composer.json with:
composer normalize
Review the changes in the diff output. Commit the normalized file.
Where to Look First
vendor/localheinz/composer-normalize/config/default.json for built-in sorting/validation rules..composer-normalize.json (see Implementation Patterns).Project Onboarding
composer normalize once to baseline existing composer.json.composer.json scripts:
{
"scripts": {
"post-install-cmd": [
"@normalize"
],
"post-update-cmd": [
"@normalize"
]
}
}
post-install-cmd/post-update-cmd cautiously—only for projects where normalization is non-negotiable.Team Enforcement
composer normalize --dry-run || exit 1
(Fail if changes would occur without applying them.)# GitHub Actions example
- name: Check composer.json normalization
run: composer normalize --dry-run
Custom Rule Sets
.composer-normalize.json in your project root:
{
"sort": [
"require",
"require-dev",
"config",
"extra.laravel"
],
"rules": {
"extra.laravel.auth": "required",
"scripts.*": "alphabetical"
}
}
extra.laravel keys).Partial Normalization
--only to target specific sections:
composer normalize --only="scripts"
composer.json formatting—let the tool handle it.--working-dir:
composer normalize --working-dir=packages/api
composer.json merge hell.Overzealous Autoloading
autoload/autoload-dev sections, breaking IDE indexing temporarily. Run composer dump-autoload afterward if issues arise.Dry-Run False Positives
--dry-run may show changes even for trivial whitespace fixes. Use --no-diff to suppress output if only validation matters:
composer normalize --dry-run --no-diff
Plugin Conflicts
dealerdirect/phpcodesniffer-composer-installer), ensure normalization runs after them in post-install-cmd.Git Ignore
vendor/ to .gitignore if you rely on the plugin’s cached rules.-v to debug rule application:
composer normalize -v
composer normalize --only="rules"
.composer-normalize.json with an empty file to revert to defaults.Custom Rules
.composer-normalize.json or environment variables:
COMPOSER_NORMALIZE_RULES='{"scripts.*": "reverse-alphabetical"}' composer normalize
Localheinz\ComposerNormalize\Rule\RuleInterface for project-specific logic.Excluding Files
composer.lock) via:
{
"exclude": [
"composer.lock",
"vendor/**"
]
}
Laravel-Specific Quirks
extra.laravel keys to match Laravel’s expected structure:
{
"rules": {
"extra.laravel": {
"publishes": "required",
"providers": "alphabetical"
}
}
}
composer.json chaos.Performance
- name: Cache Composer Normalize
uses: actions/cache@v3
with:
path: ~/.cache/composer/files
key: ${{ runner.os }}-composer-normalize
How can I help you explore Laravel packages today?