wikimedia / composer-merge-plugin

Merge one or more additional composer.json files at Composer runtime
MIT License
923 stars 160 forks source link

Declare Dependency Between Modules #263

Open XedinUnknown opened 1 year ago

XedinUnknown commented 1 year ago

I use this awesome plugin to create modular software, each module having its own composer.json. This allows me to keep declarations of module dependencies together with modules, greatly simplifying understanding and portability. So, there's an e.g. my/main package, which uses the plugin to merge modules/module1/composer.json and modules/module2/composer.json. Feels like this is exactly what the plugin is made for.

Now, module2 depends on symbols from module1. If the symbols were in an external package, I could just have both modules depend on that package, and it would work, as it has for a number of years now. But most often, local modules are local because they have something that is considered not worth extracting into a separate package (at that time). Still, symbols need to be shared, and so in my/module2 I tried declaring dependency on my/module1: *. This serves as an explicit dependency declaration, providing a logical link between modules. When/if the modules need to be extracted into separate packages, I wouln't have to go through the code looking for class usages, and resolving them to their respective packages, which is a long-term added benefit of such a declaration.

Alas, it gives the Root composer.json requires my/module1, it could not be found in any version, there may be a typo in the package name error. Is this supposed to be working, and I just need to fix some configuration? If not, is this something you are planning to add? Is it possible at all?

Thanks! 🙏

jbrada commented 1 year ago

Hi @XedinUnknown,

I just came across this issue. Have you been able to figure out how to deal with internal dependencies? So far the replace section works for me as a workaround, but it's not quite what I'm looking for.

XedinUnknown commented 1 year ago

Hi @jbrada!

I have put this on pause for now, as it doesn't block anything. However, now thinking about it a bit more, I guess you could add your internal dependencies as local path repositories. Don't know if this will work, but at least this is how I'd address the immediate error message.

If you try it, I'd be curious if it works. I guess, adding those to the composer config "automatically" by the plugin would be a step in supporting this.