4

I'm a litte confused about the right way to use Composer and Bitbucket regarding the distribution of my libraries, maybe because I'm a newbie both in Composer and Bitbucket.

My problem is: I have two repositories on Bitbucket, the first one is a simple utility library (Utility) and the second one is the main project (MainProject). Both have one single branch, the master one.

I want to use Utility in MainProject, so I wrote two composer.json.

Mainproject composer.json:

{
    "require": {
       "vendor/utility": "*"
     },
    "repositories": [
        {
            "type": "vcs",
            "url":  "https://MyUsername@bitbucket.org/MyUsername/utility.git"
        }
    ]
}

Utility composer.json:

{
    "name": "vendor/utility",
    "autoload": {
        "psr-4": {
            "Vendor\\": "src/"
        }
    }
}

This configuration works perfectly, I mean, if I launch 'composer install' on MainProject, Utility is correctly cloned. But in the vendor directory in MainProject I get all the Utility files, including test directory and useless files like phpunit.xml.

I've tried to use the solution offered here: https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production/, I created the archive via Sourcetree, but after? How I should use this archive? I suspect I miss some basic knowledge.

If I want to distribute Utility via composer as a package also for other applications, but without its tests and other files, which is the right way? Should I use .gitattribute or is there a simple way to create a dist version? I don't understand how to do with Bitbucket, maybe because I'm a newbie.

A little help?

Giorgia
  • 41
  • 3

1 Answers1

0

I understand that the situation looks a bit unsatisfying, but that Reddit thread "I don't need your tests in my production" is only one side of the story. The other side is "I need your test in my pre-deployment checks to verify your code works as well as mine".

So there's two conflicting wishes: Either have no tests, or have them.

Composer doesn't solve this for you. If you don't like the files that you get by the process, you can write a script that does delete them before putting the project live.

There currently is no automatic help planned via Composer because it is easier for those people that want less files to delete them after composer install than the other way round.

Sven
  • 69,403
  • 10
  • 107
  • 109
  • Hi Swen, thanks for your answer. I actually wrote a script to clean the package already, but my problem is another one. Utility is a package of mine, I want to use it in a lot of project of mine and my problem is I don't want to replicate my own tests. But still I want to take advantage of composer and bitbucket. If it is impossibile to have packages without tests via composer and private repositories, I wonder if it is possibile to create an archive (via git/.gitattributes) and to distribute it normally. I'm able to create the archive already, but I'm not able to distribute it. – Giorgia Nov 19 '15 at 21:44