Reputation: 301
I am developing a PHP framework as a composer package that will be reused in 50+ projects (web sites) in my company.
Every website is relatively small (15-20 PHP files, less than 1-2 MB total). The websites will also use composer.
The framework package:
The websites:
Both framework and website are private projects and due to company policy, cannot be shared neither in GITHUB, nor Packagist.
{
"name": "Company/Framework",
"require": {
"php": ">=5.6.4",
"mpdf/mpdf": "dev-master",
"monolog/monolog":"1.2"
},
"autoload": {
"psr-4": {
"Company\\Framework\\": "src/"
}
}
}
{
"repositories": [
{
"type": "path",
"url": "../Framework/",
"options": {
"symlink": false
}
}
],
"require": {
"Company/Framework": "dev-master",
"mpdf/mpdf": "dev-master"
},
"autoload": {
"psr-4": {
"Company\\Site01\\": "src/"
}
}
}
My problem is, that composer populates every website's vendor directory with its dependencies and entire framework directory.
Finally, All ended up with a huge ammount of disk space used, about 40+ GB, mainly with a same VENDOR packages, repeated over and over again.
Our PHP code is less than 1% of the entire project.
My questions are:
What are the best practices to develop my private packages (not shared in the public) and reuse them in other projects?
How can I properly reuse common composer libraries, without duplicating hude ammount of Vendor code over and over again?
Upvotes: 1
Views: 735
Reputation: 1470
For your second question (avoiding duplicating vendors):
You will be out of luck with composer only:
symlinking, which could have helped, is only available on unstable package versions (@dev); you probably want production-grade, thus stable, packages.
(see a related question at https://stackoverflow.com/questions/47231676; and a rejected proposal #1940 at Composer to ease this)
Creating a wrapper around composer to symlink vendors to a shared directory may be a solution,
but requires extra precaution (never use composer directly) to avoid unexpected overwriting by composer (see issue #4174 at Composer).
Upvotes: 0
Reputation: 7343
You shouldn't keep the vendor folders inside your libraries code. Delete the vendor folders, and just have the libraries' dependencies declared in the libraries' composer.json.
When you run composer install
from the project, composer will copy your libraries to the project's vendor folder, and install the libraries' dependencies inside the project.
An even better alternative is to use private repositories, from GitHub or Bitbucket, cause you can control who has access to it, but you can still use things like tags for versioning.
Upvotes: 1