PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, January 24, 2022

[FIXED] Composer dependency with minor differences in composer.json file

 January 24, 2022     composer-php, git, json     No comments   

Issue

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?


Solution

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



Answered By - Tobiah Zarlez
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing