Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am wondering if it would be good to add composer integration for library dependencies. Alternatively maybe make library paths configurable? I am using https://asset-packagist.org/ with my local composer file so that I can use bower to grab slick carousel and jquery.easing respectively. As a stop-gap I created a local patch (see attached) so that I can reference the bower paths. This is not ideal. Another option would be to just make those paths configurable so that you could override locally.
Comment | File | Size | Author |
---|---|---|---|
#26 | 2907371-composer-integration-23.patch | 603 bytes | drupalninja99 |
| |||
#22 | 2907371-composer-integration-22.patch | 3.09 KB | gausarts |
#6 | slick-bower-paths-1.patch | 3.78 KB | drupalninja99 |
slick-bower-paths.patch | 3.43 KB | drupalninja99 | |
Comments
Comment #2
teknikqaRather than modifying the module, it might be worthwhile to configure composer to install/update into the correct directory.
Include this at the bottom of your composer.json -
Comment #3
drupalninja99 CreditAttribution: drupalninja99 at Mediacurrent commentedThat will help but that's not as ideal as making those paths not hardcoded in my opinion. Many modules that integrate libraries like this with make those paths configurable.
Comment #4
teknikqaThere is already a commit for 8.x that uses the slick-carousel path. See issue: #2855190: Using bower or composer to download the slick library is cumbersome.
Comment #5
gausarts CreditAttribution: gausarts commentedThanks for the catch.
It seems we have a few issues to address:
slick_requirements()
This appears to be an obvious miss from my end when I committed the fix here:
https://www.drupal.org/node/2855190#comment-11987678
We can commit this part.
slick_library_info_alter()
The deleted line was already correct. The new one was repeating the same thing
'slick-carousel'
.This issue was addressed as mentioned above #12261678. Thanks.
Also Drupal always puts site builders first over DX, IMHO. So this is actually not an issue as long as correctly put.
This cannot be in. CMMIW.
slick.libraries.yml
The easing library can follow the above-mentioned line:
$easing_path = libraries_get_path('easing') ? libraries_get_path('easing') : libraries_get_path('jquery.easing');
This may need work. No need to touch
slick.libraries.yml
, let's just do it atslick_library_info_alter()
.Comment #6
drupalninja99 CreditAttribution: drupalninja99 at Mediacurrent commentedFYI here is a patch that updates the path for slick.css. This updates my original path (For POC only).
Comment #7
gausarts CreditAttribution: gausarts commentedShall we change library path aggressively from "slick" to "slick-carousel"?
The library namespace is "slick". Not "slick-carousel".
And remains "slick" when bower was added, too.
And this module was created with the same namespace as original author's namespace, too.
My own two cents would be to still accommodate "slick" namespace like this:
$library_path = libraries_get_path('slick') ? libraries_get_path('slick') : libraries_get_path('slick-carousel');
You are happy. The original intention is still respected, too.
What you changed was perhaps just a typo as it appears to repeat
libraries_get_path('slick-carousel')
:+ $library_path = libraries_get_path('slick-carousel') ? libraries_get_path('slick-carousel') : libraries_get_path('slick-carousel');
This is not as hard as changing religion, however let's hear for more suggestions ;)
Comment #8
drupalway CreditAttribution: drupalway as a volunteer and commentedI use Drupal VM and Composer's create-project as a site deployment strategy.
This composer.json code delivers the Slick library to the right place (in my case).
Comment #9
pimok3000 CreditAttribution: pimok3000 commented#8 works fine for me. The only additional step (using thunder-8.4.3) is to rename
thunder/docroot/libraries/slick-carousel
to
thunder/docroot/libraries/slick
Comment #10
Zerdiox CreditAttribution: Zerdiox at iO commented#7 Slick-carousel bower uses slick-carousel as a name, slick on bower and npm is a different library. I say slick should follow the standard in bower.
#8 We shouldn't have to add this to composer.json because it does not support versioning. If older versions exist they get thrown out to the wind.
Comment #11
candelas CreditAttribution: candelas commentedHello
@gausarts as the module maintainer what do you recomend? I have to use Composer in my project. Thanks :)
Comment #12
candelas CreditAttribution: candelas commentedBesides slick library, shouldn't jquery.easing be installed with Composer too?
Comment #13
teknikqaOf late, I have been creating symlinks for libraries whose names differ in the module from that in other JS repositories. This can be handled by Composer. You just need to add it as a post-install command.
This works if you are installing the libraries for the first time. If the libraries already exist, you only need to run the command manually once.
I have found this to be the easiest solution that will work without needing modifications to the module code.
Here is my complete composer.json file -
Comment #14
kay_v CreditAttribution: kay_v as a volunteer commentedFwiw, here's an alternative for dependency handling that seems more consistent (thanks in part to Vardot supporting blazy and slick composer packages, and gymadarasz supporting the jQuery.easing package):
composer require drupal/blazy drupal/libraries drupal/slick gymadarasz/jquery.easing vardot/blazy vardot/slick
Is it sufficient, or do others see something more that is needed? (naturally it will be best to handle dependencies in the composer.json vs doing it manually).
Comment #15
gappleI think when using composer to install the library, a better solution to changing the paths than using a post-install command is to use the installer-paths configuration.
You can change the path of individual libraries, in addition to setting rules by type. Composer will apply the first matching rule, so the individual package paths need to be specified before the rule for the package type.
For asset-packagist:
Comment #16
kay_v CreditAttribution: kay_v as a volunteer commentedSeems there are several very different proposals. Anyone able to compare them and help settle on a 'supported' approach? If so, I'm happy to help get the recommendation into docs.
Comment #17
bryancs CreditAttribution: bryancs commentedI tried #15 but I can't get it to work.
It just gets installed in vendor/npm-asset/slick-carousel.
I've read at getcomposer faq that to use installer-paths, the package needs to have a type and should require 'composer/installers'.
After installing npm-asset/slick-carousel, you can see in your composer.lock that it does have a type of 'npm-asset' but no requirement for 'composer/installers' hence it goes to vendor.
To fix this, you need 'oomphinc/composer-installers-extender' and add "installer-types": ["npm-asset"] to the extra bit.
More at asset-packagist
My working set-up are as follows:
Comment #18
teknikqa@bryancs It doesn't work for you because packages declared in the require field are in the wrong order. Packages from asset packagist can only be installed in the appropriate folder if you declare them after the Composer Installer Extender package.
Change your require to
Comment #19
teknikqaFWIW, #15 is the approach that I now use. It is better than the symlink method that I mentioned in #13
Comment #20
bryancs CreditAttribution: bryancs commented@teknikqa sorry I should've made it clear.
The setup I posted is actually the one that's working.
My concern with #15 is that for packages that doesn't include "composer/installers", one can use "oomphinc/composer-installers-extender" and add the appropriate "installer-types" (and installer-paths) on the extra block.
Yes, I agree with you on using #15 rather than symlink.
Comment #21
gausarts CreditAttribution: gausarts commentedFYI: Below only addresses the composer workflow part, not the issue about configurable paths, yet.
Another alternative to install assets with Composer:
https://github.com/fxpio/composer-asset-plugin?
https://github.com/fxpio/composer-asset-plugin/blob/master/Resources/doc...
Requires defining the install paths under config directive:
https://github.com/fxpio/composer-asset-plugin/blob/master/Resources/doc...
A few things to note:
$ composer global require "fxp/composer-asset-plugin:~1.3"
composer require ....
for initial setups, e.g.:Thoughts, or any issue I am not aware of?
Comment #22
gausarts CreditAttribution: gausarts commentedAttempts to address the paths.
FYI:
If any improvement, please post your patches.
I am willing to get this in before the next release. Thanks.
Comment #24
gausarts CreditAttribution: gausarts commentedLet's get the ball rolling.
Feel free to re-open if any improvement, or flaw found. Thanks!
Comment #26
drupalninja99 CreditAttribution: drupalninja99 at Mediacurrent commentedAfter enabling the libraries module I was able to get this close to working. There is I think a typo in the line that includes jquery.easing so I have included a patch for that. After this change I did not see any errors.
Comment #27
gausarts CreditAttribution: gausarts commentedThanks!
Comment #32
gausarts CreditAttribution: gausarts commentedCommitted. Thank you for contribution!
Comment #34
Giuseppe87 CreditAttribution: Giuseppe87 at Elicos commentedThe suggested command
To download the libraries didn't work for me, as I got the following error:
as composer tried to download the "^2.0@RC" version "for drupal/blazy"
was the way to make it work.
Comment #35
Back From 7 CreditAttribution: Back From 7 commentedI am getting the following error using #34 above:
Comment #36
zuhair_akI am using with the following workingconfig
Following is the part of the composer config relevant
My composer command is then
I added slick seperately to avoid renaming it.
Comment #37
nhoeller CreditAttribution: nhoeller as a volunteer commented@zuhair_ak, I am testing out Drupal 9 and trying to figure out Composer. How do I apply the configuration in #36? I am guessing I append these lines to the existing composer.json in the project root. If I have already installed the Slick and Blazy contributed modules, do I need to install them, install the preq-reqs, and then reinstall Slick/Blazy?
It looks like the packages are installed to the /web/libraries directory, rather than the /vendor directory where I see other packages being installed by Composer. I assume this is for consistency with the slick.libraries.yml in /modules/contrib/slick.
Does the Drupal Libraries API module need to be installed? It looks like Drupal 8 migration of this module is still in progress.
Thanks, Norbert
Comment #38
zuhair_ak@nhoeller You have to make changes in the composer.json in the project root. Composer is for managing PHP libraries, there are javavscript library in the list (for eg. slick/slick), that is why we are adding it in the "repositories". If already installed,composer will skip the installed packages.
I think for Drupal 9 as far as I can see from the Readme file, libraries module is not needed.
Comment #39
nhoeller CreditAttribution: nhoeller as a volunteer commented@zuhair_ak Thanks for the fast response! I freely admit that I am playing catch-up.
Regards, Norbert
Comment #40
nhoeller CreditAttribution: nhoeller as a volunteer commented@zuhair_ak I think I figured out the updates to composer.json. It took a while to get commas in the right place - a JSON viewer saved the day.
I ran individual "composer require ...' commands, starting with "bower-asset/blazy" which downloaded slick/slick and the four bower-asset packages. I skipped the drupal/blazy and drupal/slick because I had already installed them, and I need Blazy 2.x or higher for my version of the Drupal Slick module.
I see the slick v1.8.1 library installed to web/libraries/slick/slick. However, the other libraries (blazy 1.8.2, jquery 3.5.1, jquery-mousewheel 3.1.13, and jquery.easing 1.3.1) were all loaded to vendor/bower-asset. The Drupal 9 status report indicates Drupal found the slick library but not the blazy library.
It looks like the slick/slick library is associated with "type": "drupal-library" - I found an associated "installer-paths": that referenced "web/libraries/($name)". Should the code you showed below "extra": have been added below "installer-paths": ?
Thanks, Norbert
Comment #41
sakiland CreditAttribution: sakiland as a volunteer commented@zuhair_ak thank you for your suggestion. Using
asset-packagist.org
is definitely the right way how to fix this issue.Here's link to official documentation. @nhoeller, there you can see that your code need to be added below "installer-paths"
Current fix for this issue use
fxp/composer-asset-plugin
that need to be installed globally. Here's is some issues from asset-packagist.org regarding this:Comment #42
joey-santiago CreditAttribution: joey-santiago commentedmhm i'm trying to install everything i need with composer, but when i run:
composer require bower-asset/blazy bower-asset/slick-carousel:^1.8 bower-asset/jquery-mousewheel bower-asset/jquery.easing drupal/blazy:~1.0 drupal/slick
i get:
has the bower-asset/blazy package been moved somewhere else?
Comment #43
pixelsweatshop CreditAttribution: pixelsweatshop commented@joey-santiago, just modify what you run into composer to use blazy 2.
Comment #44
vrwired CreditAttribution: vrwired commentedI also was encountering drupal/photoswipe (in #42) at first which not what wanted. #41 did it for me. Also #26 & 27 from this issue helped a lot: https://www.drupal.org/project/slick/issues/2855190#comment-13824992. After putting that all together, I was then able to run #43 on this issue and all was installed via composer, including the slick-carousel and blazy libraries I needed.
Comment #45
arx-e CreditAttribution: arx-e commentedI did the installation today on a Drupal 9.2.0-beta3 and the code in 43 fails at the slick/slick part
After adding the asset-packagist repository and the installer types and paths and oomphinc/composer-installers-extender as explained at #26 and #27 here i used the following code:
composer require bower-asset/blazy bower-asset/slick-carousel bower-asset/jquery-mousewheel bower-asset/jquery.easing drupal/blazy drupal/slick
And this worked without errors.
Comment #46
oheller CreditAttribution: oheller at Electric Citizen commentedI've noticed a couple of modules (webform and dropzonejs) starting to use composer.library.json with the wikimedia/composer-merge-plugin package.
This would allow for the module to dictate what is needed instead of requiring us to try and add everything.
Comment #47
DuneBL#46 +1