-->

Multiple Composer Installs with (Independent) Modu

2020-08-01 05:58发布

问题:

I am trying to find the best way to use composer for a modular structure.

Let's say I have this framework tree:

/cms
/site/addons

Let's say that addons are available for developers to add their projects with their composer.json installs. Like /site/addons/MyNewFeature/composer.json

So the next question is the /vendor location. Should each addon have a /vendor directory and should I autoload them all within the main framework, which I think the performance of that would be too much and multiple composer installs would probably install a lot of the same dependencies. And I can't have them all install within the same /vendor directory like /site/addons/vendor because composer will automatically remove all projects not included in the current install and use its own lock file.

How could you do multiple composer installs for modular project based system; while each project requires its own composer vendor, but for performance it would be best to include only 1 vendor install. I have yet to find a solution to this and wondering if any of you guys have an idea or lead me into the right direction.

This is almost like you need a main composer.json install that automatically goes to each one of the addons and installs them as well...

The other solution is just use composer for all the addon (installs/updates) which gives me less control and poses issues with everything being located in the /vendor directory.

回答1:

After some research and testing, I've come across this concept.

This allows the framework to install/update addons manually the way it was designed, and within the main composer.json file using repositories wildcard path.

"repositories": [
        {
            "type": "path",
            "url": "../site/addons/*",
            "options": {
                "symlink": false
            }
        }
    ]

Now it will check all the addon directories for composer.json files and install all of their dependencies into a universal /vendor directory like I originally wanted.

I am not sure the issues that may arise later by doing this, but so far this gives the control I want.

The framework would just need to make sure the require in the main json has all the addons that are enabled.

https://getcomposer.org/doc/05-repositories.md#path