问题
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": "gauravmehra1987@gmail.com"
}
]
}
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.
回答1:
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 thanvendor/name
. In your case, instead of being installed onvendor/demo/contentfeed
, it would be installed undervendor/demo/packages
(because of your setting incomposer.json
)installer-paths
: allows the package consumer to set a custom install path for a certain package or packages or package family. On a packagecomposer.json
has no effect, this setting is only for the project configuration.
回答2:
You can add the config section into your composer.json
, and define "vendor-dir" inside it
{
"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"
}
},
"license": "MIT",
"minimum-stability": "dev",
"authors": [
{
"name": "Gaurav Mehra",
"email": "gauravmehra1987@gmail.com"
}
],
"config": {
"vendor-dir": "packages/"
}
}
Reference:
https://getcomposer.org/doc/06-config.md#vendor-dir
来源:https://stackoverflow.com/questions/59048491/how-to-set-the-install-directory-for-a-package-on-the-package-instead-of-on-the