Force PHP composer to create relative, not absolute, symlinks of local repositories

Viewed 840

I have a docker container with a host's directories mapped like this - /app (project itself) and /packages (local dependencies). Then I have /app/composer.json file in which I define local repositories which reside in /packages like this

"require": {
    "myvendor/mypackage": "^1.0",
},
"repositories": [
    {
        "type": "path",
        "url": "./../packages/mypackage"
    }
]

The problem is that after running composer install/update it symlinks my packages with an absolute path so /app/vendor/myvendor/mypackage directory is symlinked as /packages/mypackage. While that's working from the composer's point of view I would prefer it to be a relative symlink - ../../../packages/mypackage - because otherwise my IDE is not able to index mypackage source code (different absolute paths on my Ubuntu host than they are inside docker's container) unless I change the symlink path manually. I was looking for composer's configuration options to force absolute/relative with no luck. Is there any way to accomplish what I want, am I missing something?

1 Answers

As an alternative to symlinks, you can configure composer to mirror the local path instead of creating a symlink, with COMPOSER_MIRROR_PATH_REPOS=1 environnent variable.

https://getcomposer.org/doc/03-cli.md#composer-mirror-path-repos

It may not be what you really need, because change in the local package will not be propagated automatically and will require to run composer install again for the local path to be mirrored again.

Related