- How do I install and use composer-normalize in a Laravel project?
- Install it globally with `composer global require localheinz/composer-normalize`, then run `composer normalize` in your Laravel project directory. It works as a Composer plugin, so no Laravel-specific setup is needed. For CI/CD, add it as a pre-install step in your pipeline.
- Will this break my existing composer.json or Laravel dependencies?
- No, the tool is idempotent—repeated runs produce the same output. It only sorts keys, formats lists, and enforces structure without altering dependency versions or Laravel-specific configurations. Always test with `composer normalize --dry-run` first.
- Can I customize which parts of composer.json are normalized?
- Yes, use a `.composer-normalize.json` config file to exclude sections (e.g., `extra.laravel`) or define custom sorting rules. This is useful for Laravel projects where certain sections like `scripts` or `config` should remain unchanged.
- Does this work with Laravel’s extra.laravel section?
- By default, the tool normalizes all sections, including `extra.laravel`. To preserve custom ordering or exclude it, add `extra.laravel` to the `exclude` array in your `.composer-normalize.json` config file.
- How can I integrate this into GitHub Actions for Laravel CI?
- Add a step like `- run: composer normalize --check` before `composer install` in your workflow. This ensures `composer.json` matches the normalized format, preventing inconsistent merges. Use `--check` to fail the build if files differ.
- Is this compatible with Laravel 10 and Composer 2.x?
- Yes, the package supports Composer 2.x (used by Laravel 8+) and Composer 1.x. It’s framework-agnostic but particularly useful for Laravel projects where dependency consistency is critical. Tested with modern Laravel versions.
- What if my team relies on specific composer.json formatting (e.g., alphabetized require-dev)?
- The tool respects your preferred order by default. If you want alphabetized sections, configure it via `.composer-normalize.json` with custom sorting rules. Run `composer normalize --dry-run` to preview changes before enforcing them.
- Can I use this in a monorepo with multiple Laravel packages?
- Absolutely. Run `composer normalize` in the root directory to standardize all `composer.json` files across packages. This reduces diff noise and ensures consistency in dependency management for large Laravel monorepos.
- Are there alternatives to this package for Laravel projects?
- Other tools like `composer-merge-plugin` or `composer-normalize` (by different authors) exist, but this one focuses specifically on formatting and sorting without merging. For Laravel, this is ideal for CI/CD consistency, while tools like `roave/security-advisories` handle security checks.
- How do I handle false positives in CI (e.g., unnecessary diffs from normalization)?
- Start with `--dry-run` to preview changes, then commit the normalized `composer.json` to your repo. This ensures CI only flags *actual* inconsistencies. For Laravel, exclude sections like `extra.laravel` if they’re intentionally unordered.