Problem/Motivation

When using a tool like bower or composer to download the slick library for automated deployments, the library will not be installed into the slick folder as is required by the module. It will be installed into slick-carousel instead.
While it is possible to rewrite this folder after download, this is cumbersome and error prone. It should be possible to use the default download folder for the slick library.

Proposed resolution

The easiest solution would be to just change the folder in the modules libraries.yml to slick-carousel, but that would break existing installations. A solution for installations that use the libraries module would be to check for both folders in hook_library_info_alter().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

daniel.bosen created an issue. See original summary.

daniel.bosen’s picture

FileSize
1.06 KB
gausarts’s picture

Status: Active » Needs work

Thank you for the solution.
This had been discussed here: #2792129: bower support

Just a tiny nitpick.

  1. +++ b/slick.module
    @@ -69,8 +69,11 @@ function slick_hook_info() {
    -    $libraries['slick']['js'] = ['/' . libraries_get_path('slick') . '/slick/slick.min.js' => ['weight' => -3]];
    

    Weight is specified to allow inserting extension between main library and initialization script. Useful if you want to act on slick events which are normally required before Slick is initialized.

  2. +++ b/slick.module
    @@ -69,8 +69,11 @@ function slick_hook_info() {
    +      $libraries['slick']['js'] = ['/' . $library_path . '/slick/slick.min.js' => []];
    

    We need to bring back weight here.

I need to read more about the better way to handle this other than hook_library_later(), but I am putting below for discussion.

I am still thinking if we can change the "slick-carousel" into "slick" inside the module's composer.json using the following instruction which requires composer/installers:
https://getcomposer.org/doc/faqs/how-do-i-install-a-package-to-a-custom-...

{
    "extra": {
        "installer-paths": {
            "libraries/{$name}": ["type:drupal-library"]
        }
    }
}

As you know, the {$name} part is a reference to "slick-carousel" which is globally applied to any package.
I haven't tested this, there may be things I am not aware of here, but for just in case you already did:
Does composer allow to hard-code {$name} to just "slick", and automatically update the folder name?

Aside from that, we already had a good lesson from colorbox here: #2814045: composer.json issue in latest dev and 1.2.0

Thoughts?

daniel.bosen’s picture

Ah, missed the weight earlier, will provide a new patch for this. Adding installer-path to your modules composer.json will not work, since this information is not propagated to the root composer file of the projects using the slick module. So everybody would have to add an appropriate line to its composer.json. This is not very desirable.
But in theory it would be possible for people using drupal project to add somthing like this to their composer.json. But it is a bit more complicated, you need to add the asset-packegist repository, require composer/installers and you schould propably require oomphinc/composer-installers-extender also.
With this prerequisites you can add "web/libraries/slick": ["bower-asset/slick-carousel"] to your installer-paths.

daniel.bosen’s picture

FileSize
1.07 KB
gausarts’s picture

Status: Needs work » Needs review

Thank you for valuable info.

...since this information is not propagated to the root composer file of the projects using the slick module

I forgot to mention, my question was also based on deprecated CM command. When I run composer drupal-update, it merged each module's composer.json into merge-plugin of the root composer.json automatically, trimmed down for sanity:

   "extra": {
        "merge-plugin": {
            "include": [
                "core/composer.json",
                "modules/contrib/entity/composer.json",
                "modules/slick8/slick/composer.json"
            ],

Unfortunately CM was deprecated last January.

This made me think a possibility, but didn't actually investigate further as I need to update Slick composer.json at d.o to actually test downloading Slick library in the first place.

Based on your info, I am happy to abandon hope for this for now ;)

Please allow some delay to commit this. Thanks again.

daniel.bosen’s picture

Hallo gausarts,

any news on this? Would be super helpful for beeing able to install the module with composer only.

Best regards,
Daniel

  • gausarts committed bfb0d5e on 8.x-1.x authored by daniel.bosen
    - Issue #2855190 by daniel.bosen: Using bower or composer to download...
gausarts’s picture

Status: Needs review » Fixed

Sorry for delay. And thanks for the sweet solution ;)

daniel.bosen’s picture

Status: Fixed » Closed (fixed)

Nice, thank you! Now how about a new release tag?

gausarts’s picture

I was planning to release a new tag after my wife's birthday 29/3. I will see if I can do a few clicks sooner ;)

Majdi’s picture

@daniel.bosen I try what you describe in comment #4, But its not working, I think that because composer/installers not required by slick-carousel, so its always downloaded in vendor path

maosmurf’s picture

FileSize
863 bytes

While the installation works nicely now, Drupal's status page still complains about missing SlickJS library.

> The Slick library should be installed at /libraries/slick/slick/slick.min.js, or any path supported by libraries.module if installed.

This is due to the fact, that while the actual lookup has a fallback to libraries_get_path('slick-carousel'), the function slick_requirements is still relying solely on libraries_get_path('slick').
?>

This patch applies the previously by @daniel.bosen provided fallback (in slick_library_info_alter) to function slick_requirements as well.

maosmurf’s picture

FileSize
863 bytes
maosmurf’s picture

gausarts’s picture

@maosmurf, thank you.

This part was fixed. Let's focus here for the side or extra issues:
#2907371: Composer / bower integration? Configurable paths?

ñull’s picture

Since this is still not fixed in the release, I based my solution on #2855190-4: Using bower or composer to download the slick library is cumbersome. but it turns out a bit more complex than described there. You need:

composer require oomphinc/composer-installers-extender
composer require fxp/composer-asset-plugin

In your composer.json you need to add inside the extra section:

    "extra": {
        "installer-types": ["npm-asset-library", "bower-asset-library"],
        "installer-paths": {
            "web/libraries/slick": ["bower-asset/slick-carousel","npm-asset/slick-carousel"],
            ......
            ......
        }
    }

After that preparation you can:
composer require npm-asset/slick-carousel

... which will then get nicely installed in web/libraries/slick in stead of web/libraries/slick-carousel . I did not try but with bower it should work as well.

candelas’s picture

@gausarts is patch in #13 needed? Thanks :)

Marc Angles’s picture

As far as I can tell this module does not install cleanly on D8.

Why is this issue closed ?

Running composer require drupal/slick does not download the library. And installing the library is still cumbersome...

SerShevchyk’s picture

Add to key "repositories" in your composer.json :

"repositories": {
    "drupal": {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    },
    "slick": {
      "type": "package",
      "package": {
        "name": "slick",
        "version": "v1.9.0",
        "type": "drupal-library",
        "dist": {
          "url": "https://github.com/kenwheeler/slick/archive/master.zip",
          "type": "zip"
        }
      }
    }
}

and then to key "require" add :

  "require": {
    "slick": "^1.9.0"
}

After this run "composer install" and then you can find new folder with slick code in your libraries folder. It's not a fix for the bug, but can help you quickly get slick library

gausarts’s picture

Why is this issue closed ?
Running composer require drupal/slick does not download the library. And installing the library is still cumbersome...

Please read #3, #6, #21.

Basically consider this:

  • Composer is not designed to manage JS assets. It is npm, bower, etc. jobs. Composer is for third party PHP libraries, not CSS or JS things.
  • It is not the module job to download these assets for you. In term of the latest Composer, without the mentioned deprecated CM module, you must manually add your assets into the top level (docroot) of composer.json. Note the above-mentioned lesson related to Colorbox.
  • There are workarounds to integrate with Composer. Use various solutions mentioned #2907371: Composer / bower integration? Configurable paths?, or jump here #21, or use any of the mentioned distros at project home page. But the underlying procedure is all the same: you (or distros or a Composer plugin) must integrate libraries/ assets into top level composer.json, not module's. It was a breeze (when modules' composer.json were automatically merged into the top level composer.json) until CM was deprecated. This was what you expected, but no longer available now. That is why I said I abandoned hope to integrate this into module since CM was deprecated by Drupal packagist January 2017. What this issue solved was to do the here mentioned workarounds with the help of Libraries module.

Hope that clarifies your concern why this was closed ;)

jcmartinez’s picture

Using @Shefarik solution #20 I got this message from composer:

Deprecation warning: require.slick is invalid, it should have a vendor name, a forward slash, and a package name.

To make it work, I had to tweak a bit. I have it working with:

    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "package",
            "package": {
                "name": "slick/slick",
                "version": "v1.9.0",
                "type": "drupal-library",
                "dist": {
                    "url": "https://github.com/kenwheeler/slick/archive/master.zip",
                    "type": "zip"
                }
            }
        }
    ],

and in the require section, I had to add:

"slick/slick": "^1.9.0"
PhilY’s picture

A little amend to post #22: this is it but don't forget to run composer update --lock right after manually editing the composer.json file (this is a general rule not related to Slick).

plato1123’s picture

#22 worked great for me, nice time saver!

markie’s picture

#22 works for me. Thanks for the lead.

DamienMcKenna’s picture

FYI if you have asset-packagist.org added to the composer.json file you can do it even more simply. To set this up, add these pieces to the composer.json file:

    "repositories": [
...
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
...
    ],
...
    "extra": {
        "installer-types": [
...
            "bower-asset",
            "npm-asset"
        ],
        "installer-paths": {
...
            "web/libraries/{$name}": ["type:drupal-library", "type:bower-asset", "type:npm-asset"],
...
        },
    }

Then just do this:
$ composer require bower-asset/slick-carousel

That works for any NPM package, just prefix the npm package name with "bower-asset/".

BTW the version of the Slick library currently available is 1.8.1, not 1.9.0, you can confirm this by downloading https://github.com/kenwheeler/slick/archive/master.zip and looking at the package.json file.

splash112’s picture

#26 is dependant on composer-installers-extender
Install with:

composer require oomphinc/composer-installers-extender