Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer dependency with minor differences in composer.json file

I'm creating an application that is going to work on two separate versions of the same software. These frameworks will have completely different modules with a shared dependency to a JavaScript framework I've built.

Let's say

dave/version1
dave/version2

Which both share the dependency via a require of

dave/framework

I want to maintain this framework (dave/framework) in one repository that both of the parent modules can require. However the location that these framework files need to be placed are slightly different between the two modules, along with slightly different requirements for the composer.json files to ensure everything gets moved around correctly (the two versions of these software implement composer rather differently).

With my limited knowledge of composer and Git I've formulated a couple of solutions:

  1. Create three repositories, two wrapper repositories with specific composer.json files to support each different version of the software. With another dependency to a third repository which contains the actual framework. I'm unsure if this would ever work outside of a theory. Also ends up being a little messy.

  2. Use some form of clever tagging and have version1 and version2 depend on separate versions of the framework which would in turn have slightly different makeup. Composer would then struggle with pulling the latest version of the module as we'd be running two ever so slightly different code bases in weird versions.

However both of these seem potentially messy and the incorrect way of structuring what I'm trying to achieve.

Is there a nice way to achieve this? or am I better of maintaining two separate repositories for the framework?

like image 541
Dave Avatar asked Nov 08 '22 19:11

Dave


1 Answers

With some correct planning, your first option is going to be easier than you think.

Git has a system called Submodules built right in.

Version1 and Version2 repos would include the Frameworks repo within them. Then when you update Framework, you can pull those updates no problem in Version1/2. You control when and how to, so you can make sure you don't introduce a bug down the road either.

Here is some documentation for submodules: https://git-scm.com/book/en/v2/Git-Tools-Submodules https://git-scm.com/docs/git-submodule

like image 154
Tobiah Zarlez Avatar answered Nov 15 '22 04:11

Tobiah Zarlez