Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloned project with dynamic includes in composer.json

I have an application server, it is like a blog system (my wordpress killer). It is based in php hosted in github and using composer to manage dependencies. Each installation is hosted in my server (I make the installation for them). When a client requires a new "addon/plugin" I create a new package and host it in a private repository hosting. The problems comes when I need to add new package:

Client 1.
- package for calculate prices

Client 2.
- package for show a welcome message

Client 3.
- package for add a calendar

My application will have every package ready to be used in all instances because I am requiring them via composer:

"require": {
        "killer/calculate": "dev-master",
        "killer/message": "dev-master",
        "killer/calendar": "dev-master"
}

Now image if I have 2K clients and everyone of them are requesting custom packages. How can I provide an application (cloned massively) but just keeping in the each installation just the packages that each client need?

Hypothetical solution

I was searching (if it is possible) for something like the following. For each installation, create a file manually where its content specifies the package to be required. For example, let's say each client's installation has something like this:

//composer.json
"require": {
}

//plugins.json  (this file is ignored via .gitignore)
{
    "killer/calculate": "dev-master"
}

Then, somehow tells to composer.json to require the data from plugins.json. By this way I am avoiding to create a huge composer.json sharing unnecessary packages for all clients.

like image 604
manix Avatar asked Sep 18 '15 22:09

manix


1 Answers

There is a feature request for allowing composer.json to extend another file. You should go comment on it to draw some attention to it.

The way you would use that feature is to create a default.json file that contains all your regular composer.json contents, including a require section that lists all the common packages you need.

// default.json
{
    "require": {
        "php": ">=5.4.0"
    }
}

Then have a composer.json file for each project that extends and/or overrides default.json like this:

// composer.json
{
    "require": {
        "killer/calculate": "dev-master"
    },
    "extends": "default.json"
}

The final result would be:

{
    "require": {
        "php": ">=5.4.0",
        "killer/calculate": "dev-master"
    }
} 

If you can't wait on the merge request, then you can go checkout the composer fork from the merge request's author and try it out.

like image 62
BrokenBinary Avatar answered Oct 05 '22 03:10

BrokenBinary