Search code examples
phpcomposer-phppackagist

How to set the install directory for a package on the package, instead of on the project?


I am working on creating a custom composer package. The composer package must install to a custom folder instead of vendors/ directory I want it to be installed in packages/. This is how my composer.json looks like:

{
"name": "demo/contentfeed",
"description": "This is yet another Lumen composer package wrapper",
"type": "lumen-plugin",
"version": "1.1.5",
"keywords": ["demo","lumen","drupal"],
"homepage": "https://github.com/gauravmehrasrijan/lumen-feeds",
"require": {
    "composer/installers": "^1.0.24"
},
"autoload": {
    "psr-4": {
        "demo\\Contentfeed\\": "/src"
    }
},
"extra": {
    "installer-name": "packages",
    "installer-paths": {
        "packages": ["demo/contentfeed"]
    }
},
"license": "MIT",
"minimum-stability": "dev",
"authors": [
    {
        "name": "Gaurav Mehra",
        "email": "[email protected]"
    }
]
}

Before jumping here I also tried the solution posted in this link but it didn't work for me, I added installer-name key in extra, but no success.


Solution

  • This is not possible, and the documentation says so explicitly:

    [...] The ability for a package author to determine where a package will be installed either through setting the path directly in their composer.json or through a dynamic package type: "type": "framework-install-here".

    It has been proposed many times. Even implemented once early on and then removed. Installers won't do this because it would allow a single package author to wipe out entire folders without the user's consent. That user would then come here to yell at us.

    (Emphasis mine)

    The two keys you are using (installer-paths and installer-name) serve a different purpose than what you imagine:

    • installer-name: allows the package author (you) to say your package should be installed under a different directory than vendor/name. In your case, instead of being installed on vendor/demo/contentfeed, it would be installed under vendor/demo/packages (because of your setting in composer.json)
    • installer-paths: allows the package consumer to set a custom install path for a certain package or packages or package family. On a package composer.json has no effect, this setting is only for the project configuration.