I'm using the Superfish library in my Drupal 8.7.x project. I included it in composer.json like this:

 "repositories": [
            "type": "composer",
            "url": "https://packages.drupal.org/8"
            "name": "mehrpadin/superfish",
            "version": "2.1",
            "type": "drupal-library",
            "source": {
                 "url": "https://github.com/amclin/Superfish-for-Drupal.git",
                 "comment": "use amclin because of pull request 29",
                 "type": "git",
                 "reference": "c11a5ac10f8c99f809858c0384a4c415411778ce"
            "require": {
                 "composer/installers": "~1.0"

Now I found a patch to a problem I have, so I'd like to apply the patch to the JS file automatically. Much like the way I can apply patches to Drupal modules. Specifically this one:


Any idea how to do that?

  • 1
    Look into composer-patches. Does your composer file include it?
    – Kevin
    Jul 21, 2019 at 15:52
  • Yes, I'm already using it to patch Drupal modules. I didn't know I could use it to patch the JS libraries as well.
    – hepabolu
    Jul 21, 2019 at 15:55

1 Answer 1


As Kevin already mentioned: it can be done using 'composer-patches' in a similar way to patching a Drupal module.

The mentioned patch contained more than I wanted to patch, so I downloaded the patch and added it to a local 'patches' directory. Also, the patch uses a path that starts at 'libraries', while the patch configuration starts one level deeper.

So the patch configuration becomes:

patches {
    "mehrpadin/superfish": {
        "Fixed nested UL accordion functionality": "./patches/smallscreen_patch.diff"

And the patch itself is changed from:

diff --git a/libraries/superfish/sfsmallscreen.js b/libraries/superfish/sfsmallscreen.js
index 9765fed..f5722a9 100644
--- a/libraries/superfish/sfsmallscreen.js
+++ b/libraries/superfish/sfsmallscreen.js


diff --git a/superfish/sfsmallscreen.js b/superfish/sfsmallscreen.js
index 9765fed..f5722a9 100644
--- a/superfish/sfsmallscreen.js
+++ b/superfish/sfsmallscreen.js

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.