Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to require a package whilst omiting select files with composer

Say I want to require a package with composer but that the package has some directories that I do not believe ought to be included. eg. maybe a tests/ directory or whatever. Is there a way to omit this directory from what composer downloads?

There's the --prefer-dist flag but that requires repos have a .gitattributes file present with export-ignore for the various files / directories. But what if the repo in question doesn't have that? Sure, I could make a pull request, but what if they don't accept it? What if the project is abandoned? For these reasons I think the --prefer-dist flag is suboptimal and I would like an answer (if one exists) other than "use --prefer-dist".

like image 604
neubert Avatar asked Oct 30 '22 13:10

neubert


1 Answers

Symfony tried to do this, and their experience made them revert this decision. Composer had information about using .gitattributes in the documentation, but removed it.

In essence, removing some part of a package from a distinct distribution path is likely to cause more problems than it solves. From my perspective, the CLI switch --prefer-dist and --prefer-source is a selector of either having to clone a huge repository that takes ages or download a ZIP with that exact version - but the results should be equal, i.e. I should not be forced to --prefer-source for ALL my dependencies just because one single package that decided to "optimize for deployment" decided to remove documentation and tests from their ZIP.

Yes, during development I usually look at their code and tests to help me understand what's going on - or what SHOULD go on, and isn't.

Conclusion: Composer is NOT a deployment tool. If you care about the size of your application, it is your task to remove everything you don't need or want, and probably optimize other things as well (minify JS and CSS, optimize images etc.). It should not be Composers' or any package maintainers task to do this optimization for you.

like image 193
Sven Avatar answered Nov 15 '22 05:11

Sven