Faking a Composer Repo

This is just a quick tip. How can you have a project behave like a Composer repository, but where the packages are in subdirectories of a git repository.

First, if the package is the only package in the git repository and the composer.json file for the package is in the root directory, composer can reference that git repository directly. See https://getcomposer.org/doc/05-repositories.md#vcs. I am not going to talk about that case here.

But what if the packages are in a subdirectory? The following is a quick workaround to experiment with using the Composer “path” repository type. This is not a perfect solution, but it can be a useful temporary fix.

First, check out the git repository holding the packages alongside your main project. E.g. If you main project is in /var/www/htdocs/foo, then check out the other git repo in /var/www/htdocs/bar. What we are going to do in the foo/composer.json file is reference ../bar/ as a relative path. (You can use any path you like in practice.)

Let’s say all the packages are in a “packages” subdirectory (might be app/code/Magento for Magento modules). The trick is to add a new “repository” entry of type “path” with a URL of “../bar/packages/*” (or “../bar/app/code/Magento/*”). Composer will look for a composer.json file in the top directory of each package directory matching the path. If you reference exactly the same name and version number as in the composer.json file, it will be a match and Composer will use that package. There is a “symlink” property that if true will cause a symlink to be created, if false a copy of the package will be made.

See https://getcomposer.org/doc/05-repositories.md#path for complete details.

Example

    "repositories" : [
        {
            "type": "path",
            "url": "../bar/packages/*",
            "symlink": true
        },
        . . .
    ]

2 comments

  1. Hi Alan,

    Thank you for sharing this. I’ve had experience to work with this for Magento 2 modules and it happened that if you use “path” as your repository for custom Magento 2 module and include your module to Magento 2 project via “path” and symlink the static files from custom module won’t be visible for Magento 2. The only workable solution I found is to you Modman. So far I have 15 independent repositories for single Magento 2 project. Works like a charm.

    Thanks

    1. Curious. Could you explain a bit more why? I know of two potential problems – one some web server config bans symlinks, and the other if the ../magento2ee path is out of the approved area it might be rejected – but you are talking about symlinking static files. Just want to make sure I understand what you had go wrong better to see if its fixable.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: