Before the 2.9 update I was requiring harvesthq/chosen
in my project's composer.json
file and specifying that its package type is drupal-library
to add it to the libraries folder.
After updating drupal/chosen
to 8.x-2.9 where the package is added as a dependency, composer now installs it in the vendor folder instead. I believe the composer.json
file needs to provide the repository information and give it the drupal-library
type (instead of the default library
) for it to be in the correct folder.
Comments
Comment #2
cantrellnm CreditAttribution: cantrellnm at Oxbow Labs commentedComment #3
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedHi!
Did you follow the updated readme of the module?
https://git.drupalcode.org/project/chosen/blob/8.x-2.x/README.txt
Comment #4
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedThe link to the original discussion: #2918901: Fix documentation for composer library setup
Comment #5
cantrellnm CreditAttribution: cantrellnm at Oxbow Labs commentedOh! No, I hadn't seen those, thank you for the links.
I'd prefer the module specify the package type of its dependency as
drupal-library
instead of putting the work on the user to override their installer-paths for one exception, but at least the documentation already provides an easy fix.Comment #6
colanI agree. Do we really need a custom installer? Installing the module normally via Composer should put everything where it's supposed to go. Other modules requiring libraries don't need any of this.
As per How to install with composer external library that drupal module depends on, the above patch should be the right way to do it, but I can't find a way to test it (unless it's not working). When I apply the patch above using Composer patching, it still goes in
/vendor
. I'm assuming this is because the patch gets applied after the library gets installed, which doesn't help.#2: Is there another way this should be tested?
Alternately, could we not access the library from
/vendor
? Does it really need to go in/web/libraries
? Obviously, other modules in Drupal can access the vendor branch.Comment #7
colanComment #8
hussainwebUnfortunately, composer cannot load repositories this way (for a good reason). So, the patch cannot work even if merged because composer will never read this repositories entry. The repository has to be added to the root composer.json (the main composer.json for the site). This was covered in the documentation changes introduced in #2918901: Fix documentation for composer library setup.
@cantrellnm, I know what you mean and I had submitted a PR to the package but not yet merged. Hopefully, the maintainers review it soon and merge it which will make the process easier.
Comment #9
matthiasm11 CreditAttribution: matthiasm11 at MM-Experience commentedI had to add the following code to the repositories in composer.json to make it work:
Mind the version is written without
^
, the url is ending with.git
and the reference starting with av
.The library can be required with:
No need to execute the steps in the readme adding
oomphinc/composer-installers-extender
andinstaller-paths
, seems overkill to me.Comment #10
alisonWondering if patch is still needed? And/or if any instructions should be added to the other issue or README, either for installation or for updating.
(But overall, just wanted to check whether work is needed on this thread?)
Comment #11
PlayfulWolf CreditAttribution: PlayfulWolf commentedCan confirm, that solution in #9 works, chosen appears in libraries directory.
Readme file is incorrect.
Comment #12
hussainwebI want to point out that while the method in #9 would work, it doesn't mean that the method in README is incorrect. The method in #9 depends on adding a custom repository for the library which is not necessary (as that library is already available on Packagist). However, the package is of type
library
which causes it to be placed in thevendor
directory. This was discussed extensively in #2918901: Fix documentation for composer library setup. There is also a PR to update the composer package type so that we could place it without using the package name in the custom installers path.Between the two methods, I would prefer the method where we can use the package info from packagist rather than us specifying it in the repositories section. The simple reason is that updates are available without changing anything in composer.json file. Another reason is that this method involves changing very few lines compared to adding an entire repository section. Still, both methods work and someone who is well-versed with composer could choose to use the method which overrides repositories if that is what they need.
Comment #13
calbasiI can confirm this issue.
#3: @nagybalint, Readme is not running, because the chosen library is being installed at /vendor folder
Comment #14
SerShevchykI have tried to add the library to my composer.json like #9 and like
+
"harvesthq/chosen": "^1.8.7",
and get en error :
Comment #15
hussainweb@SerShevchyk, that's because you're specifying zip file for source attribute. I would suggest following the README.txt file for the instructions. I'll try to provide a more detailed walkthrough this week.
Comment #16
Rar9 CreditAttribution: Rar9 commentedfor D9 with added
{
"type": "package",
"package": {
"name": "harvesthq/chosen",
"version": "1.8.7",
"type": "drupal-library",
"source": {
"url": "https://github.com/harvesthq/chosen-package.git",
"type": "git",
"reference": "v1.8.7"
}
}
}
"harvesthq/chosen": "^1.8.7",
composer show harvesthq/chosen
outputs wrong path
/vendor/harvesthq/chosen
instead of /web/libraries/chosen
Comment #17
hussainwebI realise this is a cause for confusion for many, which is why I created a video and posted it on YouTube. In the video, I walk through the README in this module and install the module along with the JavaScript library in the correct location. I hope it is useful. Here's the link: https://youtu.be/Lo3ChjQkzok
Comment #18
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedNice! Thank you!
Would you like to link this video on the module page?
Comment #19
hussainweb@nagy.balint, if you like it, please do. I appreciate you asking before putting it there.
Comment #20
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedDid some reorganization on the module page.
Let me know if some text should be changed.
Comment #21
JThan CreditAttribution: JThan as a volunteer commentedOkay, I am fairly new at composer - but wasn't composer used exactly to avoid stuff like this were you are downloading dependencies manually or wih extra work? If I read this issue correctly, we can download the package but it lands in "vendor" - what has to be done to use it from there and get rid of this whole problem?
Again: I am new to composer and this is just me trying to understand the underlying problem. Thank you.
Comment #22
JThan CreditAttribution: JThan as a volunteer commentedComment #23
hussainweb@JThan, composer does a decent job at managing PHP dependencies. There are only workarounds to manage JS dependencies.
The steps to install the dependencies for this module are in the README file, or you can look at this video if you prefer: https://youtu.be/Lo3ChjQkzok
Comment #24
JThan CreditAttribution: JThan as a volunteer commentedThank you for clearing that up for me, I did not know that composer is mostly only for php-packages. DOes not make me happier right now - starting with composer is hard ;). And thanks for the video.
I did uninstall the module for now because of this, but when I later come back I will be glad to have this cleared up. Thanks.
Comment #25
scott.whittaker CreditAttribution: scott.whittaker commentedThe instructions in the README do not work for me. If I add "library" to "installer-types" composer errors out with the message
#9 does work for me and is consistent with other libraries I'm including for other modules (google/charts, jackmoore/colorbox).
Comment #26
selwynpolit CreditAttribution: selwynpolit commentedI just watched the video created by @hussainweb (thanks for that - lovely job!) and followed the steps from him and the readme pretty carefully but I also get
I haven't tried the #9 variation but I'm curious why it isn't working.
Comment #27
DaringDV CreditAttribution: DaringDV commentedI was also getting the message as in #25 and #26 even after following the README.
When I watched the video from #17 for the second time, I realized that the only difference is that I downloaded
oomphinc/composer-installers-extender
using commandcomposer require oomphinc/composer-installers-extender
which dowloaded version 2.0 while @hussainweb is using version 1.x (version 1.1 to be precise).So I did like this:
composer remove drupal/chosen
to uninstall the harvesthq/chosen from vendor directory."oomphinc/composer-installers-extender": "^2.0"
to"oomphinc/composer-installers-extender": "^1.0"
and runcomposer update
.composer require drupal/chosen
and voila the chosen library was installed in "web/libraries" directory.
Btw I followed the README for this to work except downgrading
oomphinc/composer-installers-extender
. However as perComposer Installers Extender
README version 2.0 should have worked for me as I'm using php version 7.4.Hope this will help somebody.
Comment #28
hussainwebThanks @DaringDV. The only difference with version 2 of
oomphinc/composer-installers-extender
is that it adds Composer 2 support. In terms of functionality, both versions should do the same job.Comment #29
hussainwebAnd thanks @selwynpolit for your comments. :)
Comment #30
DaringDV CreditAttribution: DaringDV commentedThanks @hussainweb for clarification. Now I understand that I've
"composer/installers": "^1.9"
in mycomposer.json
file and that's why version 1 ofoomphinc/composer-installers-extender
was required.And if I will update composer/installers to version 2 then version 2 of
oomphinc/composer-installers-extender
will be required.I think most of the persons are facing issues may be due to unmatched versions of both
composer/installers
andoomphinc/composer-installers-extender
.Thanks once again.
Comment #31
mautumn CreditAttribution: mautumn as a volunteer commentedI really appreciate all the work done by the contributors of this module and the support given - especially @hussainweb on this topic. No one in Drupal is responsible for Composer, most of the time it is brilliant, but it can be a pig of a thing to work with at times! Like most people, I have spent far too long trying to get Chosen installed using composer - something that should have taken no more than a minute to do!
Like most people, I wanted everything placed in the "preferred" directories - the chosen js to go in
web/libraries/chosen
and the drupal chosen module to go inweb/modules/contrib/chosen
. I followed the Readme to the letter but I kept getting the. I didn't want to frig it as in #9. I tried @DaringDV's #27 but was still getting
.
The way I got it working in the end was the following do's and don'ts :-
1. Do not - as the Readme instructs - add the installer-types line to the "extras" section of composer.json - yet...!
If I did, I always got the error :-
2. Do not run
composer require drupal/chosen
yet...! If you have, remove it withcomposer remove drupal/chosen
.3. Vital step: check your composer.json require section for
"oomphinc/composer-installers-extender"
. If it is >= 2.0 change it to "^1.0" and then runcomposer update
.4. Now add the installer-types line as the Readme instructs :-
to the "extras" section of composer.json.
5. Run
composer require drupal/chosen
.Good luck!
Comment #32
srjoshRan into this today. #31 was a win for me. Thanks mautumn!
Comment #33
MatroskeenI ran into the issue (Package type "library" is not supported) and decided to go another way and install chosen library from bower-asset repository.
See for more details: https://asset-packagist.org
I already had https://asset-packagist.org in the repositories list, so all I had to do was:
composer require bower-asset/chosen
I think it can be a nice replacement for the existing instructions because many projects already have asset-packagist repository in place.
___
Here is a list of required sections in composer.json files:
Comment #34
colanFrom #12:
How does this sound for a plan to fix this without requiring workarounds?
I've done this for other modules, and as a concept, it seems to work fine.
It it ever does get fixed upstream, we can simply switch back to that, and then dump the fork.
Comment #35
hussainweb@colan, that would work, yes, but it would also mean that the module will have to pay attention to the fork and revert to the original package name when (if) it gets merged. Also, chosen seems to be deprecated. So, a fork may have to pick up significant maintenance.
Comment #36
Elvin - Albania Drupal Developer CreditAttribution: Elvin - Albania Drupal Developer commentedThank you mautumn!.
#31 solved it for me too on Drupal 8
Comment #37
colan@hussainweb: There are two (2) possibilities: Either the library is maintained, or it isn't. If it is, problems like this get fixed and we'd need to track it (and don't need the fork). If it isn't, no changes are being made upstream anyway. So there's nothing to track, and we can do what we want in the fork as there's nothing to sync with (as the origin is dead).
Creating a fork would allow us to fix anything that's not being handled upstream, and in this case, it's only the one particular issue. If we run into other problems, then yes, we can fix those in there too, but that's outside this issue's scope. But having our own fork allows us to do that for anything else that comes up later.
Yes, but that's an easy change, and it's unlikely given that it appears dead. (And to be frank, we only need to worry about this until the real issue here gets fixed in core, which is #3076171: Provide a new library to replace jQuery UI autocomplete.)
Why? I don't see any need for that. In our fork, we'd only need to fix things we care about. So for this issue, we just need to merge the upstream one that we're tracking. We don't need to waste time fixing other problems we don't care about.
Comment #38
elioshThak you mautumn!!!
Ran into this today.
#31 was the solution.
Composer 1.10
Drupal Core 9.0.8
Comment #39
Rar9 CreditAttribution: Rar9 commentedI dont know what could be wrong but i still are seeing this error that prevent drupal/chosen to be written to composer.json
Comment #40
james.williams CreditAttribution: james.williams at ComputerMinds commentedThe oomphinc/composer-installers-extender plugin does not yet support moving the chosen library to the right place under composer 2. See https://github.com/oomphinc/composer-installers-extender/issues/26 - there is also a suggested workaround there, which is similar to the patch on this issue. I suspect that needs to be fixed; but in the meantime, is it worth changing the recommended instructions? Or at least making it explicit that it cannot yet be done with Composer 2?
Comment #41
colanAll: Please review the plan I proposed in #34, and provide feedback. The current state of this issue is meant for it. It solves problems such as #40, that we'll no longer need to worry about. Thanks!
Comment #42
james.williams CreditAttribution: james.williams at ComputerMinds commented@colan thanks for providing a clear plan - I agree that the module installation instructions could be changed whilst we wait for upstream fixes. How comfortable would you be with committing to maintaining that fork whilst it's needed? e.g. updating the code, especially for security fixes, from the original library project?
Could this module just change to use npm-asset/chosen-js or bower-asset/chosen via asset-packagist.org as per comment #33? Those already work fine as they don't use the default 'library' package type, so it seems unnecessary to me to create another clone of the original package.
Comment #43
colanThere wouldn't be much work involved as upstream is currently unsupported.
I think it should be the job of the maintainers to maintain the fork as these things have to be kept synchronized. Having said that, however, we'd be willing to co-maintain the module. If myself or one of my colleagues were given maintainer access, we'd be happy to set up the fork, and grant access to all other maintainers. (We're already doing this kind of thing for Aegir.) Having said that, though, if the current maintainers want to do this themselves, that would be fantastic.
This may be a better idea, but I don't know much about asset-packagist.org so I'll let someone else comment on this approach.
Comment #44
PhilYStep 3 on #31 is the one that saves me ;-)
Thanks mautomn.
Using Composer 1.10.19 & Drupal 9.1.0
Comment #45
DuneBLI will add my 2 cents:
As there are other modules which are using this library (ex: lang_dropdown), I assume we should stick to the default installation behavior of Drupal.
Without installing this module, if I run
composer require harvesthq/chosen
(D 9.1) the chosen library will be installed in/libraries/jquery.chosen
like any other jquery libraries (/libraries/jquery.xxxxx
)Thus, we don't need any installation instruction except
composer require harvesthq/chosen
as it runs out of the box.(We can add other instructions to add an "installer-paths" for those who like to go deeper...)
...And the only thing to change would be the chosen library path in
chosen.libraries.yml
Doing this way will allow other modules to re-use chosen for other purposes and will decrease the installation steps for all users.
Comment #46
andres.torres CreditAttribution: andres.torres commentedI had to follow this comment https://github.com/oomphinc/composer-installers-extender/issues/26#issue... to get composer working on Drupal 9.1.3 using Composer 2, and update the entry on composer.json to:
"oomphinc/composer-installers-extender": "^1.1 || ^2" otherwise the Library no supported error always triggers.
Comment #47
hanoiiIf I am not mistaken, this issue which goes back a few years became an issue after chosen was added as a composer package and the instructions changed, which then caused issues as `composer-installers-extender` v2.0 (needed for composer 2) doesn't accept type library.
While I managed to also installed chosen as an npm-assets like other js libraries, as chosen still requires the library from composer I ended up with the two libraries.
In the end, taking the hint from https://github.com/oomphinc/composer-installers-extender/issues/26#issue..., I managed to make this work by using the following composer plugin: https://github.com/mnsami/composer-custom-directory-installer
So the step to make this work would be:
1
composer require mnsami/composer-custom-directory-installer
2. Add to the "installer-paths" section in "extra" the following:
I added before
"web/libraries/{$name}": [
just in case there are issues in the order, but you can also add it the the current web/libraries/${name}:3.
composer require drupal/chosen
This should be enough to put the chosen library in the correct destination.
Comment #48
DuneBLI don't think we should have:
1-Added composer tools
2-Complex instructions on how to install the library
The best way is to follow the default drupal composer process like explained in #45
Thus, we ONLY need to update the code in
chosen_lib.module / _chosen_lib_get_chosen_path()
by prepending 'jquery.' to 'chosen' as showed here:Doing this will eliminate all the painful installation steps and avoid any added composer stuff.
Comment #49
DuneBLHere is the patch which implement #48
Comment #50
james.williams CreditAttribution: james.williams at ComputerMinds commentedcomposer require harvesthq/chosen
would normally put the library in thevendor
directory, so I don't think it's quite that simple? What plugin are you using to move it to thelibraries
directory under the webroot instead?Comment #51
DuneBL@james.williams you are completly right... I don't remember how I get it there...
...Thus we need installation steps...
But,
I think that my patch is valid because many jquery plugins are stored with this pattern (libraries/jquery.xxxx)
This could ease the plugins sharing.
Ex: the lang_dropdown module is expecting the chosen library at this place.
Comment #52
james.williams CreditAttribution: james.williams at ComputerMinds commented@DuneBL I don't believe your patch solves the issue at hand though, sorry. Are you using composer 2? It doesn't put the library under
libraries/jquery.chosen
either, it puts it outside the webroot undervendor/harvesthq/chosen
.Comment #53
DuneBL@james.williams sorry, I was not clear enough, my patch doesn't solve the issue, you are right.
You are also right regarding
vendor/harvesthq/chosen
: this is wherechosen
will be downloaded.What I am trying to say is that we should target the
ibraries/jquery.chosen
folder to be insync with other modules and other jquery libraries which are stored this way.Comment #54
james.williams CreditAttribution: james.williams at ComputerMinds commentedhttps://www.drupal.org/project/libraries is the best solution for allowing external libraries to be shared by multiple projects. So if we want to solve that problem, then this module should integrate with that. But that's for a separate ticket, and I don't think should help solve this ticket's problem, as using that to solve this ticket just means adding another dependency.
I think that brings us back to what colan said in comment 43 in response to the suggestion to use & document that asset-packagist.org should be used:
Acquia lightning uses it (see https://lightning.acquia.com/blog/round-your-front-end-javascript-librar...), so does commerce (https://www.drupal.org/project/commerce/issues/2916058) and it's being considered for the drupal-composer/drupal-project composer template project, which even refers to this project in its documentation: https://github.com/drupal-composer/drupal-project/pull/286/files#diff-b3....
I'll also link to these relevant discussions around how this stuff should generally be done in Drupal projects, which are both long-running and not conclusive.
#2605130: Best practices for handling external libraries in Drupal 8/9 and 10
#2873160: Implement core management of 3rd-party FE libraries
In short - the best solutions will be made upstream. In the meantime, major players are using asset-packagist.org - let's do the same here, or at least make it easier for other ways to be used to get the library in place. I propose:
How's that?
Comment #55
colanThat all makes sense; thanks for providing the missing context.
If that's true (and obviously I'm in agreement), I'm certainly not clear on why we're not getting any thumbs on that idea (especially since upstream is dead so we won't have to worry about merging all the time). It's the cleanest from a DX (and site-builder experience) perspective as there's nothing special to do when installing the module. It makes all of this go away.
In fact, we probably wouldn't even need to maintain our own fork; just find one that fixes this particular issue, and use that.
Comment #56
DuneBLI can't answer on #54 as this is outside of my skills. But I think I found why my chosen library was in jquery.xxx: I think this is coming from the webform module...
As this module is handling the chosen library, we could make proposal for a unique destination folder to all the other modules which are using it. (As far I know
lang_dropdown
andwebform
... I assume there are others)Comment #57
hanoiiI still think, that for the time being, deciding on a proper documentation steps is what's needed. Either npm-assets or what I mentioned on #47 which I am using on several projects now.
Shall we make this a documentation issue and submit a patch? I lost a bit the discussion about creating a fork, would that mean a fork of the actual chosen library? Maybe take that discussion elsewhere?
If that were the case, I would chip in with https://github.com/harvesthq/chosen/pull/2618 which is a long standing PR I have for chosen which obviously needs work as its pretty outdated but I was happy with the solution. Can also attempt to help with maintaining the chosen fork.
Comment #58
james.williams CreditAttribution: james.williams at ComputerMinds commentedSure - the current options seem to be either:
1) Use a fork of the chosen library itself (making & maintaining one if necessary).
Or:
2) Continue using the current library, which means deciding on the recommended way to use it instead, and updating the documentation for that.
Both options will require at least a change to the module's composer.json file, so even option 2 isn't 'just' a documentation change.
Comments 47 (using mnsami/composer-custom-directory-installer), 54 (npm-asset/chosen-js) and 57 (hanoii's fork) seem to provide the most concrete proposals.
How do we decide? Ultimately, it's probably up to the module maintainers, but I don't think we've heard from them since nagy.balint posted about the video & readme instructions, which no longer work with
oomphinc/composer-installers-extender
2.0 (and therefore composer 2).Comment #59
colanGood summation, which should be put in the IS.
Aside: I'm pulling out of working on a solution here given my thoughts in #3203875: Consider deprecating module as library is deprecated, and will no longer be helping. This may or may not affect what you folks decide to do here.
Comment #60
hanoiiWith #47 you really don't need any change on either composer.json (module or library). I am installing chosen fine this way.
Comment #61
james.williams CreditAttribution: james.williams at ComputerMinds commentedOh OK, I see what you mean. So it just makes it necessary for the user to manually add that plugin as a dependency before requiring this module, at least as long as the underlying issue is unresolved?
How do
mnsami/composer-custom-directory-installer
andoomphinc/composer-installers-extender
(and evencomposer/installers
) interact? I feel like because they're doing almost the same job, and both make use of the 'installer-paths' config section of composer.json, they might have unintended conflicts or overwrite each others' behaviour? (Not that I have any actual evidence for that though, just the concern!)Comment #62
hanoiiI haven't found any issues. https://github.com/mnsami/composer-custom-directory-installer explains it nicely. Basically this plugin only allows you to move composer packages outside of vendor, it only works with the standard composer types, like library. Not sure how composer-installers-extender will work with library once that issue is fixed, but other than both doing the same, I wouldn't expect any issues.
Comment #63
BramDriesen#47 did the trick for me. I also encountered some library issues with other modules on composer 2. This might resolve that as well.
There is also an open issue for composer installers that seems similar. https://github.com/oomphinc/composer-installers-extender/issues/26
Comment #64
alphex CreditAttribution: alphex commentedJust saying that comment 47 worked for me also.
Comment #65
carchekyeasy way
and
note:
if you install webform dependencies with this method you download chosen library 2 times (libraries/chosen & libraries/jquery-chosen)
Comment #66
gnugetJust like #64, the comment 47 fixed the issue for me.
Thanks!
Comment #67
loopy1492 CreditAttribution: loopy1492 commentedSimilar to #27, I straight-up removed everything and reinstalled with ^3.0
Then, I required the most recent version of drupal/chosen and ran composer update.
And now all the files are in the right place. It's weird. It's almost as if it checks the vendor folder first to see if it exists and just decides to give up if it sees it instead of checking the location it SHOULD be going to.
Comment #68
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedWe could also think about switching to a fork, like https://github.com/jjj/chosen
However I dont see that one on packagist.
As anyways the original chosen is not supported anymore, maybe switching to a fork would be a good idea.
Comment #69
hussainwebThanks for finding the fork. I created an issue to suggest to the maintainer to add it on packagist. It should be simple as there is a composer.json already there. See https://github.com/JJJ/chosen/issues/40.
Comment #70
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedPerfect, thanks!
Comment #71
pbone3b CreditAttribution: pbone3b commented#33 Worked great for me
composer require bower-asset/chosen
Comment #72
delacosta456 CreditAttribution: delacosta456 commentedhi
#47 is also the one that worked for me
thanks
Comment #73
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedWell I see we have 4200 forks of chosen, if somebody has an active one we could use here would be welcome!
https://github.com/harvesthq/chosen/network/members
Comment #74
kodffe CreditAttribution: kodffe as a volunteer commentedI think the cleanest solution is in #47, that worked for me as well.
Comment #75
isaac77 CreditAttribution: isaac77 commentedThe procedure in comment #47 worked for me (Drupal 9, Composer 2). Thank you to everyone working on this and posting helpful tips.
Until this is resolved, can someone add a link to this thread (and perhaps comment #47) on the main project page so people do not waste time following the steps in the video and current readme file?
Comment #76
nagy.balint CreditAttribution: nagy.balint at Agence Inovae commentedDone.
But a working fork would be welcome, so we could make it work out of the box.
Comment #77
alexharries CreditAttribution: alexharries commentedI've found a workaround using Drupal Scaffold operations.
I got utterly fed-up of the Chosen library sometimes installing in the right place, and sometimes not, despite having followed the guides above and the work of several other people with the same problems.
As an example, out of the nine D9 sites I maintain - which all use the same composer.json file - Composer on five of the nine sites abjectly refused to put the Chosen library in the correct location, while on the other two sites it worked just fine.
A diff of the composer.jsons between working and non-working sites showed no obvious differences.
So, I'm using Drupal Scaffold as follows:
1: In the root of the repo at the same level as composer.json, I created a build-assets/ directory and added chosen.jquery.js and chosen.jquery.min.js, giving a directory structure of:
2: In composer.json, in the extra > drupal-scaffold > file-mapping section, add maps which will copy the two Chosen JS files into web/libraries/chosen/ after build:
(Obviously the above sections in your composer.json will have other entries in them.)
To test, I ran `rm composer.lock; composer install -vvvv` and confirmed that the Chosen files appeared in the correct place, every time.
Hopefully this helps someone else! :)
Alex
Comment #78
blainelang CreditAttribution: blainelang commentedThanks #33 Worked great for me
composer require bower-asset/chosen
Comment #79
hussainwebFWIW, the fork mentioned in #68 and #69 is now available on packagist. See https://github.com/JJJ/chosen/issues/40.
Comment #80
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedWhen we add this new fork to the module, I think that we should create a new branch of the chosen module because it is the only safe way.
- We have already done new branches for modules with minimal changes due to the semver releases.
- We can explain the new branch in the release notes and the module page (and the fact that likely not much needs to be done)
- This would force the site owners to at least check if their sites work properly with the new library, and to make sure that the library is correctly installed, instead of updating with no or minimal checking, and then having an issue somewhere.
- This way we can be sure that this new branch of chosen uses the new fork, and nothing else.
Comment #81
DYdave CreditAttribution: DYdave at Code Enigma commentedThanks @carcheky, we would like to confirm solution from #65, based on adding a package to project's
composer.json
file, fixed the problem.- Modified the composer file to add package.
- Executed
composer require
command.- Verified the files were under the
libraries
folderThanks again to everyone for your great help and feedback on this issue!
Comment #82
manuel.adanNew approach here based on wikimedia/composer-merge-plugin. The composer information about the chosen library is stored in a new file named composer.libraries.yml and merged by the mentioned plugin into the main composer information.
This is the way that the Webform module and others, like Toc JS, install their library dependencies.
README.txt updated accordingly.
Comment #83
tlo405 CreditAttribution: tlo405 commentedI've been using this module and have noticed several accessibility issues with the current library (1.8.7). I checked out the fork at https://github.com/JJJ/chosen and it looks like that version (2.2.1) fixes those accessibility issues. As mentioned by @nagy.balint, I think a new branch that just uses this new fork would be a great idea. I guess it doesn't make much sense to keep using 1.8.7 as that repo (https://github.com/harvesthq/chosen) is deprecated.
Comment #84
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedIdeally what I hoped that we could achieve is to get to a point where if I install the module with -W then it would automatically install the library as well in the correct directory.
Not sure at this point if we can get to that, seeing as it is not defined as drupal library, but nevertheless we could have the new branch to switch to the fork.
Any help is welcome!
Comment #85
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedI made a new branch.
However for now I could not make it work out of the box. Even if I specify the library as a custom repository (package) it will still not put it in the right directory.
If I copy the same to the main composer.json then it works, so maybe we just need to add some dependency there?
Alternatively we could create a wrapper library, or use the merge plugin.
Comment #86
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedAfter further checks, It seems that indeed #82 is the best option.
Will create a patch for 4.0.x in the coming days.
Comment #87
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedComment #89
DuneBL@nagy.balint
I have chosen 3 installed and if I run
composer require drupal/chosen:^4.0@RC
, I got the following:Same thing if I
composer remove drupal/chosen
beforeComment #90
james.williams CreditAttribution: james.williams at ComputerMinds commented@DuneBL would
composer require drupal/chosen:^4.0@RC -W
work any better? (The-W
flag encourages composer to update dependencies... in this case, such as drupal/chosen_lib perhaps.)Comment #91
DuneBL@james.williams
-W
doesn't solve this issueComment #92
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedCan you check if your root composer.json contains chosen_lib separately?
Sometimes it gets added there.
Then adding that to the require might help.
composer require drupal/chosen:^4.0@RC drupal/chosen_lib:^4.0@RC -W
Comment #93
DuneBL#92 solved my issue (FYI no require of
chosen
orchosen_lib
was present in my composer.json as Icomposer remove drupal/chosen
before)Comment #94
nagy.balint CreditAttribution: nagy.balint at Webbtik.io commentedFor me the following worked fine on a new install:
composer require drupal/chosen:^4.0@RC -W
And it only added
"drupal/chosen": "^4.0@RC", in the require
However if I then add chosen_lib specifically with:
composer require drupal/chosen_lib:^4.0@RC -W
Then I get
"drupal/chosen": "^4.0@RC",
"drupal/chosen_lib": "^4.0@RC",
In my composer.json
And after that If I do
composer remove drupal/chosen
Then it will throw an error, but it does remove the chosen from my composer.json and leaves chosen_lib there
"drupal/chosen_lib": "^4.0@RC",
And so if at remove chosen_lib is not specifically removed, can perhaps cause issues later when installing updates to chosen.
Comment #95
siddharthjain CreditAttribution: siddharthjain commentedI came late to this issue queue, but after going through all the comments #47 worked for me.
If you are following comment #17 then you must have composer-installers-extender to be ^1.0 version("oomphinc/composer-installers-extender": "^1.0") otherwise you will get the same error "Package type "library" is not supported"(as per #27).
Comment #96
jacobupal CreditAttribution: jacobupal commentedJust to lay it out, to install
drual/chosen
(and therefore installjjj/chosen
to the correct place) with composer you need to do the following:composer require wikimedia/composer-merge-plugin
composer require 'drupal/chosen:^4.0' -W
Comment #97
codesmithPer https://www.drupal.org/node/3069730 to not use wikimedia/composer-merge-plugin I was able to get drupal/chosen and jjj/chosent to install correctly by:
1) Manually add to "repositories" section
2) Then from your project's root directory