Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to develop a library using composer?

We're starting a new project, and we're managing dependencies with Composer. We'll probably build our app on top of Laravel 4. But we'll also create our own library, which we will use for all our next projects, not just this one.

So, we have this terrible doubt: what's the best way to develop a library using composer?

If we list that new library as a dependency, every time we modify it we will have to commit the change to the repository and then call composer update.

That seems terrible!

Is there a better way to do that?

like image 468
Denis Lins Avatar asked Nov 04 '13 12:11

Denis Lins


1 Answers

I think there are two ways to handle this, which I use depending on the case:

  • The library is a pure library, which is standalone, fully tested, and develop it using TDD to ensure that it all works. That way it can be used with the "commit, update" cycle you described just fine I think.
  • You are developing a plugin or something that must be integrated in something else (application/framework) and testing it standalone is more difficult, or you are developing it very tightly with your application. In this case require the dev-master version of the library so Composer installs it with a git clone (if it was already installed as a tag you will have to rm -rf vendor/your/library to force a reinstall as opposed to an update). You can also force this for tagged releases using the --prefer-source flag. Then once you have a clone in the vendor dir you can very easily work directly in there. If you do work in a team though you will still need to do this commit and then update to make sure the others get the latest version.

The third alternative is to just develop the code in the src/ directory of your application until it is mostly stabilized and then you can extract it as a new package and add it back as a dependency, then fall back on the first two ways I described because it will then be a lot more viable.

like image 69
Seldaek Avatar answered Sep 28 '22 19:09

Seldaek