How to install with composer external library that drupal module depends on
-
22-01-2021 - |
Question
Module bootstrap_languages depends on external library of same name how do we ask composer to require the external library that needs to go to libraries/bootstrap_languages
folder
The project's composer.json
already includes installer-paths but how can I make use of them ?
"installer-paths": {
"core": [
"type:drupal-core"
],
....
"libraries/{$name}": [
"type:drupal-library"
]
NOTE: the module itself has not taken care of this dependency
Solution
You should be able to include this package via composer by adding some repository info.
Add a package definition to your repositories
section in your composer.json. The resulting repositories
section may look like this:
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "package",
"package": {
"name": "usrz/bootstrap-languages",
"type": "drupal-library",
"version": "dev-master",
"dist": {
"url": "https://github.com/usrz/bootstrap-languages/archive/master.zip",
"type": "zip"
}
}
}
]
Then you can just use composer require like:
composer require usrz/bootstrap-languages
This will add a new line to your require
section in composer.json like
"usrz/bootstrap-languages": "dev-master"
Normally I would try to use this approach with a release tag of a package, rather than the master branch, but no tag exists for this repository.
OTHER TIPS
You can do this by using Asset Packagist. Add repository and installer-types, installer-paths to your composer.json
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"extra": {
"installer-types": ["bower-asset", "npm-asset"],
"installer-paths": {
"docroot/libraries/{$name}": ["type:drupal-library", "type:bower-asset", "type:npm-asset"]
},
Then you can add package
composer require bower-asset/bootstrap-language
Don't forget to add Composer Installers Extender by oomphinc
for the installer paths to work.
composer require oomphinc/composer-installers-extender