All Projects → cweagans → Composer Patches

cweagans / Composer Patches

Licence: bsd-3-clause
Simple patches plugin for Composer

Labels

Projects that are alternatives of or similar to Composer Patches

Easyhttp
A Laravel HTTP-client to make HTTP request easier and log requests and responses
Stars: ✭ 20 (-98.06%)
Mutual labels:  composer
Htmlcache
Laravel middleware to cache the rendered html
Stars: ✭ 35 (-96.61%)
Mutual labels:  composer
Docker Skeleton Php
A simple Docker PHP development environment
Stars: ✭ 40 (-96.13%)
Mutual labels:  composer
Codefii
A micro-framework for web Ninjas
Stars: ✭ 30 (-97.1%)
Mutual labels:  composer
Nem Php
NEM Blockchain NIS API Wrapper and Software Development Kit for PHP
Stars: ✭ 32 (-96.9%)
Mutual labels:  composer
Rtorrent Cleaner
🧹 rtorrent-cleaner is a tool to clean up unnecessary files in rtorrent
Stars: ✭ 36 (-96.52%)
Mutual labels:  composer
Zhima
芝麻信用商家服务PHP版SDK。目前为止,是github上最好用的php版SDK
Stars: ✭ 13 (-98.74%)
Mutual labels:  composer
Composer Notifier
💬 Display desktop notification after Composer install / update
Stars: ✭ 42 (-95.93%)
Mutual labels:  composer
Rexrex
🦖 Composable JavaScript regular expressions
Stars: ✭ 34 (-96.71%)
Mutual labels:  composer
Lara Eye
Filter your Query\Builder using a structured query language
Stars: ✭ 39 (-96.22%)
Mutual labels:  composer
Composer Dropin Installer
Use composer for installing dropin dependencies
Stars: ✭ 30 (-97.1%)
Mutual labels:  composer
Packagist Mirror
Creates Packagist.org mirror site.
Stars: ✭ 32 (-96.9%)
Mutual labels:  composer
Discord Webhooks
A simple lightweight Discord webhook client library.
Stars: ✭ 36 (-96.52%)
Mutual labels:  composer
Regexanalyzer
Regular Expression Analyzer and Composer for Node.js / XPCOM / Browser Javascript, PHP, Python
Stars: ✭ 29 (-97.19%)
Mutual labels:  composer
Kontent Delivery Sdk Php
Kentico Kontent Delivery SDK for PHP
Stars: ✭ 41 (-96.03%)
Mutual labels:  composer
Id Card
身份证号校验及信息获取
Stars: ✭ 14 (-98.64%)
Mutual labels:  composer
Composify
Turn WordPress plugin zip files into git repositories, so that composer version constraints work properly.
Stars: ✭ 36 (-96.52%)
Mutual labels:  composer
Datagrid
Datagrid for Laravel v5
Stars: ✭ 44 (-95.74%)
Mutual labels:  composer
Cloudreve
🌩支持多家云存储的云盘系统 (Self-deployed file management and sharing system, supports multiple storage providers)
Stars: ✭ 12,318 (+1092.45%)
Mutual labels:  composer
Pretty Package Versions
A small, indipendent wrapper to get pretty versions strings
Stars: ✭ 986 (-4.55%)
Mutual labels:  composer

composer-patches

Build Status Coverage Status

Simple patches plugin for Composer. Applies a patch from a local or remote file to any package required with composer.

Support notes

  • If you need PHP 5.3, 5.4, or 5.5 support, you should probably use a 1.x release.
  • 1.x is mostly unsupported, but bugfixes and security fixes will still be accepted. 1.7.0 will be the last minor release in the 1.x series.
  • Beginning in 2.x, the automated tests will not allow us to use language features that will cause syntax errors in PHP 5.6 and later. The unit/acceptance tests do not run on anything earlier than PHP 7.1, so while pull requests will be accepted for those versions, support is on a best-effort basis.

Usage

Example composer.json:

{
  "require": {
    "cweagans/composer-patches": "~1.0",
    "drupal/core-recommended": "^8.8",
  },
  "config": {
    "preferred-install": "source"
  },
  "extra": {
    "patches": {
      "drupal/core": {
        "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
      }
    }
  }
}

Using an external patch file

Instead of a patches key in your root composer.json, use a patches-file key.

{
  "require": {
    "cweagans/composer-patches": "~1.0",
    "drupal/core-recommended": "^8.8",
  },
  "config": {
    "preferred-install": "source"
  },
  "extra": {
    "patches-file": "local/path/to/your/composer.patches.json"
  }
}

Then your composer.patches.json should look like this:

{
  "patches": {
    "vendor/project": {
      "Patch title": "http://example.com/url/to/patch.patch"
    }
  }
}

Allowing patches to be applied from dependencies

If you want your project to accept patches from dependencies, you must have the following in your composer file:

{
  "require": {
      "cweagans/composer-patches": "^1.5.0"
  },
  "extra": {
      "enable-patching": true
  }
}

Ignoring patches

There may be situations in which you want to ignore a patch supplied by a dependency. For example:

  • You use a different more recent version of a dependency, and now a patch isn't applying.
  • You have a more up to date patch than the dependency, and want to use yours instead of theirs.
  • A dependency's patch adds a feature to a project that you don't need.
  • Your patches conflict with a dependency's patches.
{
  "require": {
    "cweagans/composer-patches": "~1.0",
    "drupal/core-recommended": "^8.8",
    "drupal/lightning": "~8.1"
  },
  "config": {
    "preferred-install": "source"
  },
  "extra": {
    "patches": {
      "drupal/core": {
        "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
      }
    },
    "patches-ignore": {
      "drupal/lightning": {
        "drupal/panelizer": {
          "This patch has known conflicts with our Quick Edit integration": "https://www.drupal.org/files/issues/2664682-49.patch"
        }
      }
    }
  }
}

Using patches from HTTP URLs

Composer blocks you from downloading anything from HTTP URLs, you can disable this for your project by adding a secure-http setting in the config section of your composer.json. Note that the config section should be under the root of your composer.json.

{
  "config": {
    "secure-http": false
  }
}

However, it's always advised to setup HTTPS to prevent MITM code injection.

Patches containing modifications to composer.json files

Because patching occurs after Composer calculates dependencies and installs packages, changes to an underlying dependency's composer.json file introduced in a patch will have no effect on installed packages.

If you need to modify a dependency's composer.json or its underlying dependencies, you cannot use this plugin. Instead, you must do one of the following:

  • Work to get the underlying issue resolved in the upstream package.
  • Fork the package and specify your fork as the package repository in your root composer.json
  • Specify compatible package version requirements in your root composer.json

Error handling

If a patch cannot be applied (hunk failed, different line endings, etc.) a message will be shown and the patch will be skipped.

To enforce throwing an error and stopping package installation/update immediately, you have two available options:

  1. Add "composer-exit-on-patch-failure": true option to the extra section of your composer.json file.
  2. Export COMPOSER_EXIT_ON_PATCH_FAILURE=1

By default, failed patches are skipped.

Patching composer.json in dependencies

This doesn't work like you'd want. By the time you're running composer install, the metadata from your dependencies' composer.json has already been aggregated by packagist (or whatever metadata repo you're using). Unfortunately, this means that you cannot e.g. patch a dependency to be compatible with an earlier version of PHP or change the framework version that a plugin depends on.

@anotherjames over at @computerminds wrote an article about how to work around that particular problem for a Drupal 8 -> Drupal 9 upgrade:

Apply Drupal 9 compatibility patches with Composer (archive)

Difference between this and netresearch/composer-patches-plugin

  • This plugin is much more simple to use and maintain
  • This plugin doesn't require you to specify which package version you're patching
  • This plugin is easy to use with Drupal modules (which don't use semantic versioning).
  • This plugin will gather patches from all dependencies and apply them as if they were in the root composer.json

Contributing

  1. composer install
  2. vendor/bin/grumphp run
  3. vendor/bin/codecept run unit
  4. <write code>
  5. vendor/bin/grumphp run
  6. vendor/bin/codecept run unit
  7. <commit code>
  8. <create pull request>

Credits

A ton of this code is adapted or taken straight from https://github.com/jpstacey/composer-patcher, which is abandoned in favor of https://github.com/netresearch/composer-patches-plugin, which is (IMHO) overly complex and difficult to use.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].