A Composer plugin that automatically applies git-format patches to your project. Useful for patching vendor packages without forking.
- Automatic patching - Patches are applied after every
composer installandcomposer update - Development patches - Use
.patch.devfiles for patches that only apply in dev mode - Organized structure - Supports subdirectories to organize patches by package
- Idempotent - Safely re-applies patches on every run (reverses first, then applies)
- Whitespace tolerant - Ignores whitespace differences when applying patches
- Interactive patch creation - Generate patches from modified vendor files with a single command
- Clear reporting - Grouped output showing success/failure status for all patches
composer require sidworks/composer-patcher- Create a
patchesdirectory in your project root - Add
.patchfiles (git diff format) - Run
composer install
your-project/ ├── composer.json ├── patches/ │ ├── fix-typo.patch # Applied always │ ├── debug-helper.patch.dev # Applied only in dev mode │ └── acme/ # Organize by package │ └── utils/ │ └── fix-calculation.patch └── vendor/ The easiest way to create a patch from a modified vendor file:
composer sidworks:composer-patcher --createThis interactive command will:
- Ask for the file path (e.g.,
vendor/acme/utils/src/Calculator.php) - Extract the original file from the package
- Generate a diff between original and modified versions
- Ask if you want to save in the package folder (e.g.,
patches/acme/utils/) - Save the patch with your chosen filename
Example session:
Enter the file path (relative to project root): > vendor/acme/utils/src/Calculator.php Save in patches/acme/utils/? [Y/n] y Enter patch filename [Calculator.php.patch]: > ✓ Patch created successfully! Location: patches/acme/utils/Calculator.php.patch Generate a patch using git diff:
# For tracked files git diff vendor/package/file.php > patches/my-fix.patch # Or from scratch using diff diff -u original.php modified.php > patches/my-fix.patchPatches must use git-style headers:
--- a/vendor/package/src/File.php +++ b/vendor/package/src/File.php @@ -10,7 +10,7 @@ public function example() { - return 'old'; + return 'new'; }| Extension | Applied When |
|---|---|
.patch | Always (install and update) |
.patch.dev | Only in dev mode (composer install without --no-dev) |
composer sidworks:composer-patcherRuns the patcher manually (useful for testing). Always runs in dev mode.
composer sidworks:composer-patcher --create # or composer sidworks:composer-patcher -c- On
composer installorcomposer update, the plugin activates - All existing patches are reversed (to handle updates cleanly)
- Patches are re-applied in alphabetical order
- Results are displayed grouped by folder
- If any patch fails, Composer exits with error code 1
- PHP 8.0+
- Composer 2.x
- Git (for applying patches)
MIT