- Issue created by @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 theinstaller-types
option which seems unrelated at all but without it, nothing is working.So the complete setup looks like this:
composer require oomphinc/composer-installers-extender
- update
composer.json
by adding
"extra": { "installer-types": [ "npm-asset", "bower-asset" ], "installer-paths": { "web/libraries/{$name}": [ "jjj/chosen" ], } }
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
. Withoutnpm-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 ininstaller-types
. It then checks if one of the paths defined ininstaller-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-extender2. 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 update4. 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 4:14pm 3 August 2024 - ππΊ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.