### Install Composer Normalize as Composer Plugin Source: https://context7.com/ergebnis/composer-normalize/llms.txt Install the plugin as a dev dependency and allow it to run. ```bash composer require --dev ergebnis/composer-normalize composer config allow-plugins.ergebnis/composer-normalize true ``` -------------------------------- ### Install composer-normalize via Composer Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Install composer-normalize as a dev dependency using Composer. ```sh composer require --dev ergebnis/composer-normalize ``` -------------------------------- ### Install composer-normalize with Phive Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Install composer-normalize using the Phive package manager. ```sh phive install ergebnis/composer-normalize ``` -------------------------------- ### Install Composer Normalize via PHIVE Source: https://context7.com/ergebnis/composer-normalize/llms.txt Install the package using PHIVE and run it from the tools directory. ```bash phive install ergebnis/composer-normalize ./tools/composer-normalize ``` -------------------------------- ### Install Composer Normalize as PHAR Source: https://context7.com/ergebnis/composer-normalize/llms.txt Download the latest release, make it executable, and run it directly. ```bash curl -OL https://github.com/ergebnis/composer-normalize/releases/latest/download/composer-normalize.phar chmod +x composer-normalize.phar ./composer-normalize.phar ``` -------------------------------- ### Composer JSON Before Normalization Source: https://context7.com/ergebnis/composer-normalize/llms.txt Example of a composer.json file before applying normalization. ```json { "type": "library", "keywords": ["foo", "bar"], "license": "MIT", "authors": [ {"name": "John Doe", "email": "john@example.com"} ], "require": { "ext-json": "*", "php": "^8.0" }, "config": { "sort-packages": true, "preferred-install": "dist" }, "name": "vendor/package", "description": "A sample package" } ``` -------------------------------- ### Composer JSON After Normalization Source: https://context7.com/ergebnis/composer-normalize/llms.txt Example of the same composer.json file after normalization, showing reordered keys and sorted arrays. ```json { "name": "vendor/package", "type": "library", "description": "A sample package", "keywords": [ "bar", "foo" ], "license": "MIT", "authors": [ { "name": "John Doe", "email": "john@example.com" } ], "require": { "ext-json": "*", "php": "^8.0" }, "config": { "preferred-install": "dist", "sort-packages": true } } ``` -------------------------------- ### Normalize composer.json with composer normalize Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Run the composer normalize command to format the composer.json file. This example shows the diff generated when normalizing the pestphp/pest composer.json. ```sh composer normalize ``` ```diff diff --git a/composer.json b/composer.json index 1cfbf1e..204f20f 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,32 @@ "pestphp/pest-plugin-init": "^0.3", "phpunit/phpunit": ">= 9.3.7 <= 9.5.0" }, + "require-dev": { + "illuminate/console": "^7.16.1", + "illuminate/support": "^7.16.1", + "laravel/dusk": "^6.9.1", + "mockery/mockery": "^1.4.1", + "pestphp/pest-dev-tools": "dev-master" + }, + "config": { + "preferred-install": "dist", + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "0.3.x-dev" + }, + "laravel": { + "providers": [ + "Pest\\Laravel\\PestServiceProvider" + ] + }, + "pest": { + "plugins": [ + "Pest\\Plugins\\Version" + ] + } + }, "autoload": { "psr-4": { "Pest\": "src/" @@ -42,49 +68,23 @@ "tests/Autoload.php" ] }, - "require-dev": { - "illuminate/console": "^7.16.1", - "illuminate/support": "^7.16.1", - "laravel/dusk": "^6.9.1", - "mockery/mockery": "^1.4.1", - "pestphp/pest-dev-tools": "dev-master" - }, + "minimum-stability": "dev", + "prefer-stable": true, - "minimum-stability": "dev", - "prefer-stable": true, - "config": { - "sort-packages": true, - "preferred-install": "dist" - }, "bin": [ "bin/pest" ], "scripts": { "lint": "php-cs-fixer fix -v", - "test:lint": "php-cs-fixer fix -v --dry-run", - "test:types": "phpstan analyse --ansi --memory-limit=0", - "test:unit": "php bin/pest --colors=always --exclude-group=integration", - "test:integration": "php bin/pest --colors=always --group=integration", - "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always", "test": [ "@test:lint", "@test:types", "@test:unit", "@test:integration" - ] - }, - "extra": { - "branch-alias": { - "dev-master": "0.3.x-dev" - }, - "pest": { - "plugins": [ - "Pest\\Plugins\\Version" - ] - }, - "laravel": { - "providers": [ - "Pest\\Laravel\\PestServiceProvider" - ] - } + ], + "test:integration": "php bin/pest --colors=always --group=integration", + "test:lint": "php-cs-fixer fix -v --dry-run", + "test:types": "phpstan analyse --ansi --memory-limit=0", + "test:unit": "php bin/pest --colors=always --exclude-group=integration", + "update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always" } } ``` -------------------------------- ### Normalize composer.json using Phive Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Run the composer normalize command via the Phive installation to normalize the composer.json file in the current directory. ```sh ./tools/composer-normalize ``` -------------------------------- ### Allow composer-normalize to run as a plugin Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Configure Composer to allow the ergebnis/composer-normalize plugin to execute. This is an extra security measure. ```sh composer config allow-plugins.ergebnis/composer-normalize true ``` -------------------------------- ### Make downloaded Phar executable Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Make the downloaded composer-normalize.phar file executable. ```sh chmod +x composer-normalize.phar ``` -------------------------------- ### Basic Normalize Command Source: https://context7.com/ergebnis/composer-normalize/llms.txt Run the normalize command to format and order the composer.json file in the current directory or a specified path. Can also be run using the PHAR. ```bash composer normalize composer normalize /path/to/project/composer.json ./composer-normalize.phar ``` -------------------------------- ### Custom Indentation via Command Line Source: https://context7.com/ergebnis/composer-normalize/llms.txt Specify custom indentation size and style (space or tab) using command-line options. ```bash # Use 2 spaces for indentation composer normalize --indent-size=2 --indent-style=space # Use tabs for indentation composer normalize --indent-size=1 --indent-style=tab # Use 4 spaces (common default) composer normalize --indent-size=4 --indent-style=space ``` -------------------------------- ### Show Diff Without Modifying Source: https://context7.com/ergebnis/composer-normalize/llms.txt Use the --diff option to preview changes without altering the composer.json file. ```bash composer normalize --diff ``` ```diff --- original +++ normalized @@ -1,10 +1,10 @@ { "name": "my/package", - "description": "My package description", "type": "library", + "description": "My package description", "require": { - "php": "^8.0", - "ext-json": "*" + "ext-json": "*", + "php": "^8.0" } } ``` -------------------------------- ### Composer Normalize Exit Code 0 Source: https://context7.com/ergebnis/composer-normalize/llms.txt Demonstrates the exit code 0 when composer.json is already normalized or successfully normalized. ```bash composer normalize echo $? # Output: 0 ``` -------------------------------- ### Configure composer-normalize in composer.json Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Use the 'extra' section in composer.json to set indent size and style. This configuration overrides command-line options. ```json { "extra": { "composer-normalize": { "indent-size": 2, "indent-style": "space" } } } ``` -------------------------------- ### Normalize composer.json using Composer Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Run the composer normalize command to normalize the composer.json file in the current directory. ```sh composer normalize ``` -------------------------------- ### Delete Backup Files Source: https://github.com/ergebnis/composer-normalize/blob/main/CHANGELOG.md This command deletes all backup files created with the '.bak' extension in the previous step. ```bash $ find -type f -name '*.bak' -delete ``` -------------------------------- ### Composer Normalize Exit Code 1 (Invalid Schema) Source: https://context7.com/ergebnis/composer-normalize/llms.txt Demonstrates exit code 1 when the composer.json has an invalid schema. ```bash composer normalize # Error: Original composer.json does not match the expected JSON schema ``` -------------------------------- ### Update Composer Package Source: https://github.com/ergebnis/composer-normalize/blob/main/CHANGELOG.md Use these commands to remove the old package and require the new one. ```bash $ composer remove localheinz/composer-normalize ``` ```bash $ composer require ergebnis/composer-normalize ``` -------------------------------- ### Normalize composer.json using Phar Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Execute the composer-normalize.phar to normalize the composer.json file in the current directory. ```sh ./composer-normalize.phar ``` -------------------------------- ### Composer Normalize Exit Code 1 (Lock File Out of Date) Source: https://context7.com/ergebnis/composer-normalize/llms.txt Illustrates exit code 1 when the lock file is not up to date with composer.json. ```bash composer normalize # Error: The lock file is not up to date with the latest changes in composer.json ``` -------------------------------- ### Run composer normalize in CI Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md Execute composer normalize with the --dry-run option in continuous integration environments. The command fails with exit code 1 if files are not normalized or the lock file is outdated. ```sh composer normalize --dry-run ``` -------------------------------- ### Custom Indentation via composer.json Configuration Source: https://context7.com/ergebnis/composer-normalize/llms.txt Configure indentation preferences directly in composer.json under the 'extra' key. These settings override command-line options. ```json { "name": "my/package", "type": "library", "require": { "php": "^8.0" }, "extra": { "composer-normalize": { "indent-size": 2, "indent-style": "space" } } } ``` -------------------------------- ### Composer.json Diff after Normalization Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md This diff illustrates the changes applied to composer.json by `composer normalize`. Note the reordering of keys and adjustments in configuration. ```diff diff --git a/composer.json b/composer.json index fd6461fc3..23c3a3596 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "phpunit/phpunit", - "description": "The PHP Unit Testing framework.", "type": "library", + "description": "The PHP Unit Testing framework.", "keywords": [ "phpunit", "xunit", @@ -16,10 +16,6 @@ "role": "lead" } ], - "support": { - "issues": "https://github.com/sebastianbergmann/phpunit/issues" - }, - "prefer-stable": true, "require": { "php": ">=7.3", "ext-dom": "*", @@ -54,20 +50,22 @@ "ext-PDO": "*", "phpspec/prophecy-phpunit": "^2.0.1" }, + "suggest": { + "ext-soap": "*", + "ext-xdebug": "*" + }, "config": { + "optimize-autoloader": true, "platform": { "php": "7.3.0" }, - "optimize-autoloader": true, "sort-packages": true }, - "suggest": { - "ext-soap": "*", - "ext-xdebug": "*" + "extra": { + "branch-alias": { + "dev-master": "9.5-dev" + } }, - "bin": [ - "phpunit" - ], "autoload": { "classmap": [ "src/" @@ -86,9 +84,11 @@ "tests/_files/NamespaceCoveredFunction.php" ] }, - "extra": { - "branch-alias": { - "dev-master": "9.5-dev" - } + "prefer-stable": true, + "bin": [ + "phpunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues" } } ``` -------------------------------- ### Replace Namespace in Files Source: https://github.com/ergebnis/composer-normalize/blob/main/CHANGELOG.md This command replaces occurrences of 'Localheinz\Composer\Normalizer' with 'Ergebnis\Composer\Normalize' in files and creates backup files. ```bash $ find . -type f -exec sed -i '.bak' 's/Localheinz\\Composer\\Normalizer/Ergebnis\\Composer\\Normalize/g' {} \; ``` -------------------------------- ### Composer Normalize Exit Code 1 (Dry Run) Source: https://context7.com/ergebnis/composer-normalize/llms.txt Shows exit code 1 when composer.json requires normalization and --dry-run is used. ```bash composer normalize --dry-run echo $? # Output: 1 (if changes needed) ``` -------------------------------- ### Dry Run for CI/CD Integration Source: https://context7.com/ergebnis/composer-normalize/llms.txt Use the --dry-run option in CI/CD pipelines to verify normalization without making changes. The command exits with code 1 if the file is not normalized. ```bash # Check if composer.json is normalized (exits with code 1 if not) composer normalize --dry-run # Example GitHub Actions workflow step # - name: Check composer.json normalization # run: composer normalize --dry-run ``` -------------------------------- ### Skip Lock File Verification Source: https://context7.com/ergebnis/composer-normalize/llms.txt Use the --no-check-lock option to skip verifying that composer.lock is up to date with composer.json. This is useful when the lock file is updated separately. ```bash # Normalize without checking lock file freshness composer normalize --no-check-lock # Useful when you know the lock file will be updated separately composer normalize --no-check-lock --dry-run ``` -------------------------------- ### Composer.json diff after normalization Source: https://github.com/ergebnis/composer-normalize/blob/main/README.md This diff shows the changes applied to the composer.json file after running `composer normalize`. It highlights reordering of keys and formatting adjustments. ```diff diff --git a/composer.json b/composer.json index 90150a37..276a2ecd 100644 --- a/composer.json +++ b/composer.json @@ -1,72 +1,73 @@ { - "name": "phpspec/phpspec", - "description": "Specification-oriented BDD framework for PHP 7.1+", - "keywords": ["BDD", "SpecBDD", "TDD", "spec", "specification", "tests", "testing"], - "homepage": "http://phpspec.net/", - "type": "library", - "license": "MIT", - "authors": [ + "name": "phpspec/phpspec", + "type": "library", + "description": "Specification-oriented BDD framework for PHP 7.1+", + "keywords": [ + "BDD", + "SpecBDD", + "TDD", + "spec", + "specification", + "tests", + "testing" + ], + "homepage": "http://phpspec.net/", + "license": "MIT", + "authors": [ { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" }, { - "name": "Marcello Duarte", - "homepage": "http://marcelloduarte.net/" + "name": "Marcello Duarte", + "homepage": "http://marcelloduarte.net/" }, { - "name": "Ciaran McNulty", - "homepage": "https://ciaranmcnulty.com/" + "name": "Ciaran McNulty", + "homepage": "https://ciaranmcnulty.com/" } ], - "require": { - "php": "^7.3 || 8.0.*", - "phpspec/prophecy": "^1.9", - "phpspec/php-diff": "^1.0.0", - "sebastian/exporter": "^3.0 || ^4.0", - "symfony/console": "^3.4 || ^4.4 || ^5.0", - "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.0", - "symfony/process": "^3.4 || ^4.4 || ^5.0", - "symfony/finder": "^3.4 || ^4.4 || ^5.0", - "symfony/yaml": "^3.4 || ^4.4 || ^5.0", - "doctrine/instantiator": "^1.0.5", - "ext-tokenizer": "*" + "php": "^7.3 || 8.0.*", + "ext-tokenizer": "*", + "doctrine/instantiator": "^1.0.5", + "phpspec/php-diff": "^1.0.0", + "phpspec/prophecy": "^1.9", + "sebastian/exporter": "^3.0 || ^4.0", + "symfony/console": "^3.4 || ^4.4 || ^5.0", + "symfony/event-dispatcher": "^3.4 || ^4.4 || ^5.0", + "symfony/finder": "^3.4 || ^4.4 || ^5.0", + "symfony/process": "^3.4 || ^4.4 || ^5.0", + "symfony/yaml": "^3.4 || ^4.4 || ^5.0" }, - "require-dev": { - "behat/behat": "^3.3", - "symfony/filesystem": "^3.4 || ^4.0 || ^5.0", - "phpunit/phpunit": "^8.0 || ^9.0" + "behat/behat": "^3.3", + "phpunit/phpunit": "^8.0 || ^9.0", + "symfony/filesystem": "^3.4 || ^4.0 || ^5.0" }, - "suggest": { - "phpspec/nyan-formatters": "Adds Nyan formatters" + "phpspec/nyan-formatters": "Adds Nyan formatters" }, - "conflict": { - "sebastian/comparator" : "<1.2.4" + }, + "conflict": { + "sebastian/comparator": "<1.2.4" }, - "autoload": { "psr-0": { "PhpSpec": "src/" } }, - "autoload-dev": { "psr-0": { "spec\PhpSpec": "." } }, - - "bin": ["bin/phpspec"], - - "extra": { - "branch-alias": { - "dev-main": "7.0.x-dev" - } - } - + "autoload": { + "psr-0": { + "PhpSpec": "src/" + } + }, + "autoload-dev": { + "psr-0": { + "spec\PhpSpec": "." + } + }, + "bin": [ + "bin/phpspec" + ], + "extra": { + "branch-alias": { + "dev-main": "7.0.x-dev" + } + } } ``` -------------------------------- ### Prevent Lock File Updates Source: https://context7.com/ergebnis/composer-normalize/llms.txt Use the --no-update-lock option to prevent automatic updating of composer.lock after normalization. This can be combined with --diff to see changes without modifying any files. ```bash # Normalize composer.json but don't update the lock file composer normalize --no-update-lock # Combine with diff to see changes without any file modifications composer normalize --diff --no-update-lock ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.