Update third-party composer package in your project

Sometimes you encounter some issue or would like to add some feature to the open source package you use in your project. And it useful enough to be contributed to the original package. Or you fixed some bug and want to share it with package maintainer.
The best way (and usually the only way) to do this is to fork the package on github and send the pull request. But what if your application can't work without this fix? 
The simplest way to resolve this matter is to move package from vendor to your project and maintain it there. But this approach has a few flaws - it is quite hard to keep library up to date with original and not so easy to contribute to the package.
It is much better to fork the package, switch composer to your fork, fix the bug and contribute it back on github.

So the steps are:


Fork the package on github


Just go to the package github page and press button "Fork". As a result you will have a copy of the original package in your account, like a this https://github.com/cmyker/PACKAGE

Clone forked repository somewhere

git clone git@github.com:cmyker/PACKAGE.git

Add original package repository as upstream

git remote add upstream https://github.com/AUTHOR/PACKAGE.git
git fetch upstream

Update your fork if it is behind



git fetch upstream
git merge upstream/master



Create a branch for your fix


git branch some-fix

At this stage I replace original package in vendor directory with symlink to my cloned fork, change or fix something, and once it ready to be published I do the following

Change the branch in composer.json



  "require": {
    ...
    "AUTHOR/PACKAGE": "dev-some-fix"
    ...
  }

Add your repository to composer.json



  "repositories": [
    ...
    {
      "type": "vcs",
      "url": "https://github.com/cmyker/Holiday.git"
    }
    ...
  ],

Replace original package with your version


composer update AUTHOR/PACKAGE

Send pull request on github https://help.github.com/articles/using-pull-requests/ and once your contribution will be approved and merged you can switch back the package to the original repository.





Comments

Popular posts from this blog

Memory efficient array permutation in PHP 5.5 using generators

How to dump http request headers with PHP under CGI/FastCGI SAPI

Zend Framework 2 AJAX: return JSON response from controller action. The proper way.