2012-08-20 16:53:47 +00:00
|
|
|
# How do I install a package to a custom path for my framework?
|
2012-07-19 04:19:03 +00:00
|
|
|
|
2012-08-20 16:53:47 +00:00
|
|
|
Each framework may have one or many different required package installation
|
|
|
|
paths. Composer can be configured to install packages to a folder other than
|
|
|
|
the default `vendor` folder by using
|
|
|
|
[composer/installers](https://github.com/composer/installers).
|
2012-07-19 04:19:03 +00:00
|
|
|
|
2012-07-19 17:40:39 +00:00
|
|
|
If you are a **package author** and want your package installed to a custom
|
2020-10-23 19:52:05 +00:00
|
|
|
directory, require `composer/installers` and set the appropriate `type`.
|
2020-04-07 19:10:00 +00:00
|
|
|
Specifying the package type, will override the default installer path.
|
2012-07-19 04:19:03 +00:00
|
|
|
This is common if your package is intended for a specific framework such as
|
|
|
|
CakePHP, Drupal or WordPress. Here is an example composer.json file for a
|
|
|
|
WordPress theme:
|
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"name": "you/themename",
|
|
|
|
"type": "wordpress-theme",
|
|
|
|
"require": {
|
|
|
|
"composer/installers": "~1.0"
|
2012-07-19 04:19:03 +00:00
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-07-19 04:19:03 +00:00
|
|
|
|
|
|
|
Now when your theme is installed with Composer it will be placed into
|
|
|
|
`wp-content/themes/themename/` folder. Check the
|
2018-01-12 12:37:42 +00:00
|
|
|
[current supported types](https://github.com/composer/installers#current-supported-package-types)
|
2012-07-19 04:19:03 +00:00
|
|
|
for your package.
|
|
|
|
|
2012-08-20 16:53:47 +00:00
|
|
|
As a **package consumer** you can set or override the install path for a package
|
|
|
|
that requires composer/installers by configuring the `installer-paths` extra. A
|
|
|
|
useful example would be for a Drupal multisite setup where the package should be
|
|
|
|
installed into your sites subdirectory. Here we are overriding the install path
|
2020-04-08 07:48:32 +00:00
|
|
|
for a module that uses composer/installers, as well as putting all packages of type
|
|
|
|
`drupal-theme` into a themes folder:
|
2012-07-19 04:19:03 +00:00
|
|
|
|
2014-05-19 10:17:07 +00:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"extra": {
|
|
|
|
"installer-paths": {
|
2020-04-08 07:48:32 +00:00
|
|
|
"sites/example.com/modules/{$name}": ["vendor/package"],
|
|
|
|
"sites/example.com/themes/{$name}": ["type:drupal-theme"]
|
2012-07-19 04:19:03 +00:00
|
|
|
}
|
|
|
|
}
|
2014-05-19 10:17:07 +00:00
|
|
|
}
|
|
|
|
```
|
2012-07-19 04:19:03 +00:00
|
|
|
|
|
|
|
Now the package would be installed to your folder location, rather than the default
|
2020-04-08 07:48:32 +00:00
|
|
|
composer/installers determined location. In addition, `installer-paths` is
|
|
|
|
order-dependent, which means moving a package by name should come before the installer
|
|
|
|
path of a `type:*` that matches the same package.
|
2012-08-20 16:53:47 +00:00
|
|
|
|
|
|
|
> **Note:** You cannot use this to change the path of any package. This is only
|
2012-08-21 07:04:41 +00:00
|
|
|
> applicable to packages that require `composer/installers` and use a custom type
|
|
|
|
> that it handles.
|