Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Composer Normalize Laravel Package

ergebnis/composer-normalize

Composer plugin that automatically normalizes composer.json: consistent key ordering, formatting, and whitespace to reduce diffs and style debates. Install as a dev dependency, allow the plugin, and run it in CI to keep composer.json tidy and predictable.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Low Coupling: The package operates as a Composer plugin, meaning it integrates seamlessly with the existing Composer workflow without requiring modifications to Laravel’s core or application logic. It does not introduce new dependencies or alter runtime behavior.
  • Non-Invasive: Normalization is purely a pre-commit/pre-push or CI/CD tool, ensuring composer.json adheres to a standardized format. No impact on Laravel’s architecture or performance.
  • Laravel-Specific Use Case: While not Laravel-specific, it aligns with Laravel’s dependency management and monorepo/multi-package projects (e.g., Laravel Framework itself, Forge, Nova, or custom packages). Useful for enforcing consistency across repositories.

Integration Feasibility

  • Plugin-Based: Requires zero code changes—only a composer require and configuration update (allow-plugins).
  • Composer Hooks: Can be integrated into:
    • Pre-commit hooks (via husky, pre-commit, or Git hooks).
    • CI/CD pipelines (GitHub Actions, GitLab CI, etc.) as a validation step.
    • Local development via composer normalize or scripts in package.json.
  • Laravel Ecosystem Fit:
    • Ideal for Laravel packages (e.g., laravel/framework, spatie/laravel-*) to enforce consistent composer.json formatting.
    • Useful in monorepos (e.g., Laravel’s own repo) where multiple packages share a root composer.json.

Technical Risk

Risk Area Assessment Mitigation Strategy
Composer Version Requires Composer 2.0+ (Laravel projects typically use Composer 2.x). Verify Composer version in CI/CD and local environments.
Lock File Conflicts May update composer.lock if composer.json changes. Use --no-update-lock in CI or enforce --dry-run for validation.
False Positives Strict normalization may flag intentional formatting (e.g., custom scripts). Configure extra.composer-normalize to relax rules or exclude specific sections.
Performance Minimal overhead; runs only during normalization. Benchmark in CI to ensure no slowdowns.
Plugin Security Requires allow-plugins configuration. Audit plugin permissions and restrict to trusted dev environments.

Key Questions for TPM

  1. Scope of Adoption:
    • Will this be enforced globally (all Laravel repos) or selectively (specific packages)?
    • Should it apply to root composer.json or all sub-packages (e.g., in a monorepo)?
  2. CI/CD Integration:
    • Should normalization fail builds if composer.json is non-compliant (CI enforcement)?
    • How to handle false positives (e.g., intentionally unformatted sections)?
  3. Local Development:
    • Should developers run normalization automatically (e.g., via post-install-cmd) or manually?
    • How to handle merge conflicts when normalized files are committed?
  4. Configuration:
    • Should indentation/style be globally standardized (e.g., 4 spaces) or per-repo?
    • Should certain sections (e.g., scripts, extra) be excluded from normalization?
  5. Backward Compatibility:
    • How to handle legacy composer.json files that deviate significantly from the normalized format?
    • Should normalization be opt-in or mandatory for new packages?

Integration Approach

Stack Fit

  • Composer-Centric: Perfect fit for PHP/Laravel projects relying on Composer for dependency management.
  • Toolchain Compatibility:
    • Works with Git hooks, CI/CD (GitHub Actions, GitLab CI), and local workflows.
    • Complements tools like PHP-CS-Fixer, Prettier, or Laravel Pint for broader codebase standardization.
  • Laravel-Specific Synergies:
    • Useful for Laravel packages (e.g., spatie/laravel-*, laravel/scout) to maintain consistency.
    • Can be extended to Laravel Forge/Nova repos where multiple packages share a root composer.json.

Migration Path

Phase Action Tools/Commands
Evaluation Test normalization on a non-critical repo (e.g., a sample package). composer normalize --dry-run --diff
Configuration Add to composer.json and CI/CD. composer require --dev ergebnis/composer-normalize + composer config allow-plugins
CI Enforcement Add to CI pipeline as a validation step. GitHub Actions: composer normalize --dry-run (fails if diff exists).
Local Adoption Integrate into pre-commit hooks or VS Code tasks. husky + composer normalize or package.json scripts.
Rollout Gradually enforce across all Laravel packages/repos. Start with opt-in, then mandate for new packages.

Compatibility

  • Composer 2.x: Required (Laravel projects typically use Composer 2.x).
  • PHP 7.4+: No direct PHP version dependency, but Composer 2.x requires PHP 7.2+.
  • Multi-Package Repos: Works recursively if run from the root directory (normalizes all sub-packages).
  • Custom composer.json: May conflict with highly customized files (e.g., non-standard key ordering). Mitigate via extra.composer-normalize overrides.

Sequencing

  1. Audit Existing Repos:
    • Run composer normalize --dry-run --diff across all Laravel packages to identify potential conflicts.
  2. Configure Globally:
    • Standardize extra.composer-normalize settings (e.g., indentation, excluded sections) in a base template.
  3. CI/CD First:
    • Enforce in CI before local adoption to catch issues early.
  4. Local Workflow:
    • Add to pre-commit hooks or IDE tasks (e.g., VS Code tasks.json).
  5. Documentation:
    • Add a .composer-normalize.md guide for contributors on formatting rules and exceptions.

Operational Impact

Maintenance

  • Low Overhead:
    • No runtime impact; only affects composer.json formatting.
    • Updates to the plugin are backward-compatible (MIT license, active maintenance).
  • Dependency Management:
    • Dev dependency only (no impact on production).
    • Update via composer update ergebnis/composer-normalize.
  • Configuration Drift:
    • Risk of inconsistent extra.composer-normalize settings across repos.
    • Mitigation: Enforce a standard config via templates or CI validation.

Support

  • Troubleshooting:
    • Common issues: lock file conflicts, false positives, or merge conflicts.
    • Debug with composer normalize --diff --verbose.
  • Contributor Onboarding:
    • Requires one-time setup (allow-plugins, local config).
    • Document in CONTRIBUTING.md or repo README.
  • Plugin Support:
    • Maintained by ergebnis (active GitHub project with 1.1K+ stars).
    • Community-driven; issues resolved within days.

Scaling

  • Performance:
    • Normalization is O(1) for most files (fast even in large repos).
    • CI impact: <1s for typical Laravel packages.
  • Multi-Repo Enforcement:
    • Scales via CI templates (e.g., GitHub Actions reusable workflows).
    • For monorepos, run from the root directory to normalize all sub-packages.
  • Parallelization:
    • Can be run in parallel for independent packages (e.g., in CI).

Failure Modes

Failure Scenario Impact Mitigation
Lock File Mismatch Builds fail due to outdated composer.lock. Use --no-update-lock in CI or enforce --dry-run.
Merge Conflicts Normalized files conflict with manual edits. Use --dry-run in CI; resolve locally before committing.
False Positives Legitimate formatting flagged as invalid. Configure extra.composer-normalize to exclude sections or relax rules.
Composer Plugin Blocked allow-plugins not configured. Add
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata