6

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

2
  • Composer will adhere to them automatically. Example, modules will go to modules/contrib, themes go to themes/contrib, etc, depending on what you have in installer-paths.
    – Kevin
    Commented May 24, 2018 at 19:06
  • 1
    so how do I run composer to get the library automatically ? for a module I will say composer require drupal/devel but what do I do for an external library ?
    – GiorgosK
    Commented May 24, 2018 at 19:07

3 Answers 3

12

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.

2
7

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

See the documentation section on downloading third-party libraries using Composer for more information about using asset-packagist. This is a widely-used method for obtaining NPM or Bower packages with Composer.

1
4

Don't forget to add Composer Installers Extender by oomphinc for the installer paths to work.

composer require oomphinc/composer-installers-extender
1
  • 1
    Thank you, man! It is not working without the extender, I was scratching my head why...
    – Verter
    Commented Apr 26, 2021 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.