I wanted to make sure I created and issue here to help track a pull request I've made to the fontawesome-iconpicker library. I've requested composer support. If the author accepts my PR then we could include a composer.json file that imports the fontawesome and fontawesome-iconpicker libraries into the libraries folder.
https://github.com/itsjavi/fontawesome-iconpicker/pull/40
Plan:
This is definitely open for discussion but I feel it's important to talk about the goals of composer integration:
1. As a developer with an advanced developer workflow, I want to be able to use this module without having to commit the dependent libraries to source control. Because I have a package manager in control of that.
2. As a site builder I want to be able to download this module and use it without having to invest an unreasonable amount of effort.
Comment | File | Size | Author |
---|---|---|---|
#34 | fontawesome_iconpicker-composer_integration-2841406-34.patch | 586 bytes | Andrew Answer |
Comments
Comment #2
cosmicdreams CreditAttribution: cosmicdreams commentedHere's a patch.
What this does is bring in the iconpicker from a fork of the main library I made. (Hopefully we'll be able to switch this to a main library if they accept my PR. I'll create a follow up issue and postpone it.)
It also includes a composer directive called installer-paths that can be used to tell composer where to put the libraries. In our case, into the libraries folder.
Without this patch the fontawesome-iconpicker module doesn't work out of the box.
Comment #3
cosmicdreams CreditAttribution: cosmicdreams commentedOops, here's the patch.
Comment #4
geerlingguy CreditAttribution: geerlingguy at Acquia commentedComment #5
geerlingguy CreditAttribution: geerlingguy at Acquia commentedNote that it's depending on
cosmicdreams/fontawesome-iconpicker
, which is a fork of the main one by itsjavi (see issue in that repo to add it to Packagist someday, Composer compatibility for itsjavi/fontawesome-iconpicker).One other thing: the way
installer-paths
is configured in the proposedcomposer.json
requiresoomphinc/composer-installers-extender
. This module may need to change the way it includes the files instead (coming from avendor/
path instead of defaulting todocroot/libraries
maybe?In general, third party libraries used by Drupal contrib modules is a very annoying thing to get right currently. See #2605130: Best practices for handling external libraries in Drupal 8/9 and 10 for notes.
Comment #6
cosmicdreams CreditAttribution: cosmicdreams commentedComment #7
geerlingguy CreditAttribution: geerlingguy at Acquia commentedSo, it seems the best way to do this currently, is to add a Composer
repository
for each of the fontawesome libraries. So in your project'scomposer.json
, add the following two repositories:Then run the following command to require the given versions of the libraries:
It's still not very intuitive, but at least this way you can require the source libraries, and don't need to necessarily hack around the install location using
oomphinc/composer-installers-extender
. You still need to set a custom installer path like:Comment #8
geerlingguy CreditAttribution: geerlingguy at Acquia commentedNote that the previous comment's contents came out of a discussion around how to do this in a BLT project, in the issue BLT 8.7.0 upgrade wipes out custom installer-paths configuration.
Comment #9
AnybodyAfter several tests I can confirm that #7 is the best solution. I think we should create a patch and commit this to have proper integration.
Thank you very much, geerlingguy. Do you already have a patch for this available?
Comment #10
AnybodyPatch attached. Please review.
Comment #11
AnybodyFurthermore I just found out that the libraries file has to be changed. The correct name of the font awesome library folder is "font-awesome" not "fontawesome". Otherwise the library can not be loaded. The README.txt must be changed accordingly.
Comment #12
AnybodyThere is a comma missing before "repositories" in patch #10 and here:
"require": {
"fortawesome/font-awesome": "^4.6"
"fortawesome/fontawesome-iconpicker": "^1.3"
}
Needs reroll.
Comment #13
D34dMan CreditAttribution: D34dMan as a volunteer and commented@Anybody, if we change the library folder name, it can create problems for existing installations right? We have to have a solution that should work for old as well as new installations
Comment #14
AnybodyOk in @D34dMan, in that case we should change "installer-name": "fontawesome" to "installer-name": "font-awesome" and things should be fine?
Could someone reroll the patch? I can't do it currently, sorry.
Comment #15
D34dMan CreditAttribution: D34dMan as a volunteer and commented@Anybody yes i will do it while testing it today
Comment #16
D34dMan CreditAttribution: D34dMan as a volunteer and commentedRe Rolling patch to fix the composer.json file.
NOTE: I didn't change the library folder name, since `fontawesome` is the recommended way to name it on https://www.drupal.org/project/fontawesome project.
Comment #18
D34dMan CreditAttribution: D34dMan as a volunteer and commentedCommited to 8.x-1.x Thanks for the contribution everybody!
Comment #19
D34dMan CreditAttribution: D34dMan as a volunteer and commentedSorry, i have to reopen this issue as the patch doesn't work. I tried to fix the url i composer to get it working, but still stuck couldn't get to work.
Having following errors while trying to run
composer require 'drupal/fontawesome_iconpicker:1.x-dev'
Comment #20
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedAltered the composer file, composer install in the module works now on my local machine.
Can you please commit this to dev when it has been tested? We can't just add the patch through composer now, since composer will first try to resolve the broken dependency (and crash) and afterwards will try to add the patch with the fix.
Comment #21
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedComment #22
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedCan someone check and commit this patch to dev please?
Thanks!
Comment #23
D34dMan CreditAttribution: D34dMan as a volunteer and commented@matthiasm11 waiting for RTBC :)
Comment #24
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedQuite difficult to test, since composer will crash without the patch being present in the dev branch. ;)
But I'll ask a colleague to test it manually.
Comment #26
D34dMan CreditAttribution: D34dMan as a volunteer and commentedAfter going through the patch, i have decided to commit it.
From what i understand, the patch in #20 enforces a correct order of repositories by discarding the keys (See Composer.json schema documentation for detail : https://getcomposer.org/doc/04-schema.md#repositories).
Please test and let me know if we need any further adjustments. hope this fix it :) Thanks for contribution @matthiasm11
Comment #27
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedWhile running composer install works in the module directory, it will not within the Drupal webroot directory.
The composer file from fontawesome_iconpicker will not know where to save the libraries.
https://www.drupal.org/project/drupal/issues/2873160
Some other information
https://drupal.stackexchange.com/questions/212360/adding-a-library-to-a-... Dependencies only work for modules that will be downloaded to the vendor map outside the Drupal webroot, this will not work for downloading a library to the web/libraries directory.
Workaround (this should be added to the installation instructions)
Comment #28
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedComment #29
D34dMan CreditAttribution: D34dMan as a volunteer and commented@matthiasm11 i know it sucks. Well let us wait for better integration in core itself. We had discussed about this in slack too and didn't reach a conclusion on best way to do it. In my personal projects, am adding the required dependencies manually to composer.json
May i change its status to postponed until core has some solution?
Comment #30
matthiasm11 CreditAttribution: matthiasm11 at Randstad Digital commentedSure!
Comment #31
micbar CreditAttribution: micbar commentedWhat about asset packagist?
This is the way of the lightning distribution.
In the root composer.json, they define a second repository:
and then require:
composer require bower-asset/fontawesome
composer require bower-asset/fontawesome-iconpicker
installer paths would look like:
Comment #32
micbar CreditAttribution: micbar commentedLet me add this:
the current composer.json of this module doesn't work, unless you modify your root composer.json and add those git repositories.
Comment #33
D34dMan CreditAttribution: D34dMan as a volunteer and commentedI have not verified this, but I think we would also need to inspect the strategy that the user's project uses when trying to add `fontawesome_iconpicker`. There are three strategies discussed in the Drupal's Documentation - https://www.drupal.org/node/2718229.
Comment #34
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedI think this issue will be fixed by updating the package name.
Comment #35
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPrevious test was failed because of it can't patch composer.json.
Comment #36
stevendeleus CreditAttribution: stevendeleus commentedId like to contribute to this issue, but I don't know how.
Comment #37
AnybodyComment #34 makes sense to me and should fix the problems IF npm sources are used via https://asset-packagist.org.
So we would have to add the requirement for:
plus suggestion for:
on the module page, but I think this is both widely used already.
As drupal/recommended-project uses it, I'd vote for RTBC #34.(wrong assumption)Perhaps one day we'll have a standard to use asset-packagist as further source in drupal/recommended-project to solve these kind of problems.
I'm sorry for the unexpected trouble with my patch. Situation can only become better.
Comment #38
mmjvb CreditAttribution: mmjvb as a volunteer commentedDon't think that belongs on the project page. Would prefer a link to a document page on how to use asset-packagist for your site.
Also recommend the use of a composer command to add a repository due to different syntax in json. The command will deal with the differences, editing manually will cause issues for those unfamiliar with json syntax. The command would be: composer config repo.asset composer https://asset-packagist.org
Comment #39
Andrew Answer CreditAttribution: Andrew Answer as a volunteer commentedPlease review this issue because it blocks upgrading module with Composer without adding custom repositories.
Comment #40
AnybodyRTBC for #34 which I just tested, it works great, brings us closer to best practices and makes the module installable via composer again on a more lightweight basis.
Finally Drupal will have to provide a best-practice for this kind of problems. See issues like #3086725: How to add support for asset-packagist.org ? or #2974100: Add the asset composer repository [asset-packagist.org], and switched all used libraries to use asset packaging
https://www.agoradesign.at/blog/asset-packagist-state-art-3rd-part-libra...
I didn't find the core discussion on that yet, but #34 seems to be a better solution than the current.
Comment #41
D34dMan CreditAttribution: D34dMan as a volunteer and commentedThe patch in #34 was applied via https://www.drupal.org/project/fontawesome_iconpicker/issues/3259802. However since the credits were not distributed properly, I am going to mark this issue as fixed and distribute the credits. Am sorry for not noticing the duplicate patch.