1

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"
}
  • Symfony uses 'submodules' to manage some 75 packages or so with a single github repository. You could search for some of the details but it's not a straight forward task. No idea what it would take to retrofit an existing repository and divide it up. Your best bet would probably be to just break your current repository into individual repositories and go from there. Before you do that, verify your bundles are truly independent. It's not uncommon for unnoticed cross dependencies to creep in. – Cerad Mar 22 '21 at 12:12

1 Answers1

1

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.

dbrumann
  • 16,803
  • 2
  • 42
  • 58