Chosen 4.x composer installation recommends composer-merge-plugin, switch to path repository instead

Created on 8 August 2023, over 1 year ago
Updated 17 August 2024, 4 months ago

Problem/Motivation

Installation of Chosen 4.x recommends using the composer-merge-plugin. This change record recommend using path repositories: https://www.drupal.org/node/3069730 β†’

This plugin is also not compatible with Pantheon's Integrated Composer, which is where we noticed the issue: https://docs.pantheon.io/modules-known-issues#composer-merge-plugin

Proposed resolution

Update readme to recommend a path repository installation instead.

Thanks!

πŸ› Bug report
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States vinmassaro

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @vinmassaro
  • πŸ‡ΊπŸ‡ΈUnited States vinmassaro
  • πŸ‡ΊπŸ‡ΈUnited States vinmassaro

    Here is a minimal example composer.json that installs the jjj/chosen library via path repository into web/libraries/chosen:

    {
        "name": "vinmassaro/chosen-install-example",
        "require": {
            "composer/installers": "~1.0",
            "oomphinc/composer-installers-extender":"2.0.0",
            "jjj/chosen": "2.2.1"
        },
        "extra": {
            "installer-types": ["npm-asset"],
            "installer-paths": {
                "web/libraries/chosen": ["jjj/chosen"]
            }
        },
        "config": {
            "allow-plugins": {
                "composer/installers": true,
                "oomphinc/composer-installers-extender": true
            }
        }
    }
    
  • πŸ‡­πŸ‡ΊHungary nagy.balint

    Hi!

    Thanks!

    I would say however that we should have both in the Readme.

    As far as I understand the path repository is a manual process, and it was always possible in the past to do that manually.
    But the disadvantage is that if the module changes the dependency, then the user might not update his own composer json manually, so that could be an issue.

    While the merge plugin solved that issue by including the composer json from the module.

    I think the deprecation happened when the merge plugin was not maintained temporarily, but now it is actively maintained actually.

    But I think we should have this other option in the Readme anyways, because if merge plugin cannot be used on Pantheon, or there are other cases where it's not possible to be used then there should be this other way of managing it.

  • πŸ‡¨πŸ‡¦Canada robbdavis

    Thanks for this. Merge plugin stopped working on Pantheon and having the library disappear caused a few errors:

    An error occurred during the execution of the Ajax response: The following files could not be loaded: //chosen.css

    Getting the library back with the posted method fixed. So, yeah, this alternative method should be in the read me.

  • πŸ‡ΊπŸ‡ΈUnited States vinmassaro

    @robbdavis: thanks for confirming that is working. I will get a MR going with a readme change

  • πŸ‡­πŸ‡ΊHungary nagy.balint

    So basically what we can add to the README is the following:

    Add the following entry to the root composer.json inside the "repositories" section:

            {
                "type": "package",
                "package": {
                    "name": "jjj/chosen",
                    "version": "2.2.1",
                    "type": "drupal-library",
                    "source": {
                        "url": "https://github.com/JJJ/chosen.git",
                        "type": "git",
                        "reference": "2.2.1"
                    }
                }
            },
    

    Then you can run the following command to install the library to the right folder:
    composer require jjj/chosen:2.2.1

  • πŸ‡¬πŸ‡ͺGeorgia iamdroid

    Hi folks,

    Thanks for the suggestions. From my end, I'd like to share an even simpler solution: since jjj/chosen is already available as a composer package there is no need to specify any repository for it. The only thing left to do is to specify the path to the libraries folder, like this:

    "extra": {
        "installer-paths": {
            "web/libraries/{$name}": [ "jjj/chosen" ]
        }
    }
    

    and then run composer require jjj/chosen

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Hi iamdroid,

    I added jjj/chosen to composer json as described, however when I run composer require jjj/chosen composer downloaded libraries to vendor folder /jjj... And I can still see message in Drupal :

    You need to download the Chosen JavaScript file and extract the entire contents of the archive into the libraries/chosen directory in your Drupal installation directory.

    I have also created libraries folder under web and moved downlaoded libary files there with no luck.

    My steps:
    1.composer require wikimedia/composer-merge-plugin
    2.added to extra: "installer-paths": {
    "web/libraries/{$name}": [ "jjj/chosen" ]
    }
    3.composer require jjj/chosen
    4. added to extra:

    "merge-plugin": {
        "include": [
            "web/modules/contrib/chosen/composer.libraries.json"
        ]
    }

    5.composer require oomphinc/composer-installers-extender
    6.composer require drupal/chosen
    7.installed chosen
    8.Refresh cache
    9.You need to download the Chosen JavaScript file and extract the entire contents of the archive into the libraries/chosen directory in your Drupal installation directory.

    What I am missing ?

  • πŸ‡ΈπŸ‡°Slovakia coaston

    it seems this #comment-13324021 β†’ helped, but not sure why I had to do that manually. When I tried before I used folder in root libraries/jjj/chosen but it has to be libraries/chosen only...

  • πŸ‡¬πŸ‡ͺGeorgia iamdroid

    Hi @coaston,

    I just double checked on a fresh Drupal installation, and you are right, it didn't work out of the box.

    Initially, I tried it on the working project which already has oomphinc/composer-installers-extender plugin installed. Also, it somehow depends on the installer-types option which seems unrelated at all but without it, nothing is working.

    So the complete setup looks like this:

    1. composer require oomphinc/composer-installers-extender
    2. update composer.json by adding
      "extra": {
        "installer-types": [
          "npm-asset",
          "bower-asset"
        ],
        "installer-paths": {
          "web/libraries/{$name}": [
              "jjj/chosen"
          ],
        }
      }
      
    3. composer require jjj/chosen

    No need to do steps 1 and 4 from your list.

    I have to admit that the full setup looks more or less like previously suggested options in terms of complexity unless you already using composer-installers-extender for managing npm and bower assets.

    And it is odd it is not working out of the box because it is what the official doc said https://www.drupal.org/docs/develop/using-composer/manage-dependencies#installer-dirs

    Good luck.

  • πŸ‡­πŸ‡ΊHungary nagy.balint

    Then we can have 3 options in the readme.

    1. merge plugin - if possible, is the better approach as then it takes the version defined in the module.

    but it is sometimes not possible or problematic so the other two options:
    2. defining the repository as #7
    3. defining the installer-paths as #11

  • πŸ‡ΊπŸ‡ΈUnited States sonfd Portland, ME

    I came here because I also ran into the issue with wikimedia/composer-merge-plugin on pantheon.

    Thank you, @iamdroid - I can confirm that the steps recommended in #11 work. (I was already using oomphinc/composer-installers-extender so this was ideal.)

    RE: @iamdroid's note:

    Also, it somehow depends on the installer-types option which seems unrelated at all but without it, nothing is working.

    This is required because the composer-installers-extender plugin only acts on packages with the types specified in installer-types. Without npm-asset listed there, the plugin will just ignore the package. Basically, oomphinc/composer-installers-extender will look at packages and install them them to directories other than vendor. It works by first checking if an installed package has a type that matches one of the types in installer-types. It then checks if one of the paths defined in installer-paths fits the package. It will use the first match found (i.e. the highest in the file) and the package will go to vendor if no installer path fits the installed package.

  • πŸ‡ΊπŸ‡ΈUnited States bburch

    I tried a 3-4 different methods proposed in the Chosen doc., this thread, and issue #3102250.
    Google's Bard LLM came up with the winning approach.
    ALL HAIL THE ALGORITHM! And the person(s) whose work it copied.

    1. Install the plugin:
    composer require oomphinc/composer-installers-extender

    2. Configure composer.json by adding the Chosen library under the "require" section:
    "require": {
    "jjj/chosen": "^2.2"
    }

    Add an extra section with an installer-paths configuration:
    "extra": {
    "installer-paths": {
    "web/libraries/chosen": [
    "jjj/chosen"
    ]
    }
    }

    3. Run Composer update:
    composer update

    4. Enable the module:
    Navigate to Administration > Extensions.
    Search for "Chosen" and enable the "Chosen Library" module.

  • πŸ‡ΊπŸ‡ΈUnited States Prodigy Atlanta, Georgia

    Correct there is a composer.libraries.json file which specifies the location of the chosen library, so you can get away with just:

    "extra": {
        "installer-paths": {
            "web/libraries/{$name}": [ "jjj/chosen" ]
        }
    }

    Although this works as well inside composer.json
    Add the following entry to the root composer.json inside the "repositories" section:

            {
                "type": "package",
                "package": {
                    "name": "jjj/chosen",
                    "version": "2.2.1",
                    "type": "drupal-library",
                    "source": {
                        "url": "https://github.com/JJJ/chosen.git",
                        "type": "git",
                        "reference": "2.2.1"
                    }
                }
            },

    Then you can run the following command to install the library to the right folder:
    composer require jjj/chosen:2.2.1

  • πŸ‡ΊπŸ‡ΈUnited States butterwise

    Thank you, @Prodigy. Your second snippet got me back on track.

    For those as novice as I when it comes to composer, note that you need to add "jjj/chosen": before the first left curly bracket.

  • Status changed to Fixed 5 months ago
  • πŸ‡­πŸ‡ΊHungary nagy.balint

    The Readme is updated since in 4.0.x, feel free to reopen if we need to add more information.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024