Using Patched Dependencies with Composer

Quite frequently it’s useful to patch a dependency and use it in your project immediately from a local file path without deploying to packageist. This is easily achieved with composer.

  "repositories": [
    {
      "type":"git",
      "url":"/home/jamesw/login-and-pay-with-amazon-sdk/"
    }
  ]

If you don’t have a the dependency added yet you can use the composer require command or edit your composer.json directly to set the version of your dependency to dev-master.

Composer’s update can be restricted to just one dependency in order to update your lock file and install the new version.

$ ./composer.phar update amzn/login-and-pay-with-amazon-sdk-php
  - Updating amzn/login-and-pay-with-amazon-sdk-php dev-master

If you get “no driver for repository” then try changing the “type” in the repository configuration entry. Some documentation says use type ‘vcs’, but I needed ‘git’.

If the dependency you are overriding is already a “dev-master” version then this is sufficient to cause your chosen repository to be the source for the dependency. If the dependency has a release version then you will need the --prefer-source argument when you update.

Remember that if you do this your package will only be installable for you so it’s a good idea to keep the changes to composer.json and composer.lock isolated to a single commit on a private branch. You can then use a rebase to skip or squash those changes when your commits are in the public version of the dependency or you have otherwise deployed those patches publicly.

To make your patches publicly installable, create a public branch on your fork at github and reference this in your requirement, for example:

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/bnkr/login-and-pay-with-amazon-sdk-php"
    }
  ],
  "require": {
    "amzn/login-and-pay-with-amazon-sdk-php ": "dev-abstract-transport"
  }
}
Advertisements
Using Patched Dependencies with Composer

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s