drupal-project icon indicating copy to clipboard operation
drupal-project copied to clipboard

Add documentation on how to install libraries using composer.json

Open hussainweb opened this issue 8 years ago • 9 comments

The composer.json in the project allows placing components marked as drupal-library in the correct directory, but most libraries are not available to composer by default. We should add documentation on how to add a repository with an example to help get users started.

hussainweb avatar Oct 31 '16 04:10 hussainweb

I think inline package definitions are not a best practice. We should at least mention the limitations. See the blue box on https://getcomposer.org/doc/05-repositories.md#package-2

webflo avatar Nov 05 '16 11:11 webflo

It's a fair point. Even though there are limitations, it is still essential in many cases. You may use bower or npm for your theme but that approach doesn't really work well here where this needs to be present site-wide in libraries directory. I have added the warning with a link back to getcomposer.org.

hussainweb avatar Nov 05 '16 13:11 hussainweb

I ma finding more and more js libraries available via Composer. Maybe we should mention those as well (use installer-paths to place them in web/libraries)

weitzman avatar Jan 06 '17 17:01 weitzman

Another options is Asset Packagist which makes Bower and NPM available through Composer.

I like the idea there are currently some caveats regarding placement that I am not too keen on - hiqdev/asset-packagist#20. Perhaps they can be addressed.

kasperg avatar Jan 08 '17 00:01 kasperg

Trying to figure out how to deal with deleting test folders that come with packages https://www.drupal.org/node/1189632 Indicated on this project: https://www.drupal.org/project/dropzonejs

joelpittet avatar Mar 29 '17 22:03 joelpittet

@joelpittet You could try to creata a subclass \Drupal\Core\Composer\Composer and override \Drupal\Core\Composer\Composer::$packageToCleanup. Add add the subclass to your composer.json as additional script.

webflo avatar Mar 30 '17 09:03 webflo

Toying with who will get the responsibility, possibly npm/yarn, but maybe composer, thanks for the suggestion @webflo

joelpittet avatar Mar 30 '17 18:03 joelpittet

I found a way that can make the installation of external libraries from npmjs.org or bower into the folder /web/libraries/ easier

Recently this composer repo was created https://asset-packagist.org/ but there still the problem that this libraries do not set a "type" for "composer/installers" to use so is difficult to set a path like /web/libraries/$name

There is this plugin that add a default type to all packages https://github.com/oomphinc/composer-installers-extender

So we modify this project to add the assets repo, the plugin and write something like the following in the composer.json

"installer-types": ["library"],
"installer-paths": {
  "web/libraries/{$name}": [
    "type:drupal-library",
    "vendor:npm-asset",
    "vendor:bower-asset"	
  ],
}

So we can do things like composer require "npm-asset/jquery.easing":"~1.0"

and it will place the library into /web/libraries/jquery.easing

There is another explanation here https://asset-packagist.org/site/about

No need to duplicate js libraries in packagist for a drupal "version". In projects with a lot of external libraries the repositories section can get quite messy and https://github.com/fxpio/composer-asset-plugin is slow and complicated. Also overcomes the limitations referenced in this PR about changing the library version.

Is it interesting to add this to the drupal composer project?

rodrigoaguilera avatar Apr 25 '17 16:04 rodrigoaguilera

I submitted a PR with the idea from last comment https://github.com/drupal-composer/drupal-project/pull/286

I think it will make this one obsolete.

rodrigoaguilera avatar Jun 25 '17 22:06 rodrigoaguilera