Loading one specific composer package from monolithic repository

546 Views Asked by At

I'm searching a way to separate an active composer package with many Symfony bundles in.

Currently the package have one global composer.json file in the root directory and its looking like that.

Package

  • src/DIRECTORY_WITH_MULTIPLE_SYMFONY_BUNDLES

  • composer.json

I want to make every bundle with a separate composer.json file, so I can require only the bundles I need, not the whole package.

I don't want to publish the package through Packagist and want to only load it directly from my repo, to be something like

"repositories": {
   "composer": {
       "type": "composer",
       "url": "https://packagist.org"
   },
   "mypackagerepo": {
       "type": "path",
       "url": "https://github.com/PATH_TO_MY_PACKAGE_REPO"
     }
   }

and then to require the bundles I need from the directory like this

"require": {
   "bundle1": "~1.8.1",
   "bundle2": "~2.18.2"
}
1

There are 1 best solutions below

0
dbrumann On

If this is for a commercial product I recommend considering Private Packagist. You will support your critical infrastructure and you will get what you want out of the box, as described in this blog post: https://blog.packagist.com/installing-composer-packages-from-monorepos/

For non-commercial use paying for private packagist is probably not easily possible. You could use something like subtreesplit to split up your repository into smaller read-only packages (see also https://lostechies.com/johnteague/2014/04/04/using-git-subtrees-to-split-a-repository/), which you can then use in your project, either by publishing the packages on packagist.org or by registering the git-repositories in your composer.json as you describe above.

If you don't want to split the repository, you could keep it on your hard drive and then register a path repository to its location instead (see https://getcomposer.org/doc/05-repositories.md#path). This is probably the least favorable option, as you cannot easily reuse this. Another developer may use a different location, directory structure or even operating system and the same goes for different environments (development, staging, production) making it harder to reuse and maintain.