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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cosmicdreams created an issue. See original summary.

cosmicdreams’s picture

Here'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.

cosmicdreams’s picture

FileSize
1019 bytes

Oops, here's the patch.

geerlingguy’s picture

Status: Active » Needs review
geerlingguy’s picture

Status: Needs review » Needs work
Related issues: +#2605130: Best practices for handling external libraries in Drupal 8/9 and 10

Note 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 proposed composer.json requires oomphinc/composer-installers-extender. This module may need to change the way it includes the files instead (coming from a vendor/ path instead of defaulting to docroot/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.

cosmicdreams’s picture

Issue summary: View changes
geerlingguy’s picture

So, 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's composer.json, add the following two repositories:

    "repositories": {
        [...]
        "font-awesome": {
            "type": "package",
            "package": {
                "name": "fortawesome/font-awesome",
                "version": "v4.7.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "fontawesome"
                },
                "dist": {
                    "url": "https://github.com/FortAwesome/Font-Awesome/archive/v4.7.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        },
        "fontawesome-iconpicker": {
            "type": "package",
            "package": {
                "name": "itsjavi/fontawesome-iconpicker",
                "version": "v1.3.0",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "fontawesome-iconpicker"
                },
                "dist": {
                    "url": "https://github.com/itsjavi/fontawesome-iconpicker/archive/1.3.0.zip",
                    "type": "zip"
                },
                "require": {
                    "composer/installers": "~1.0"
                }
            }
        }

Then run the following command to require the given versions of the libraries:

composer require fortawesome/font-awesome:v4.7.0 itsjavi/fontawesome-iconpicker:v1.3.0

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:

    "extra": {
        "installer-paths": {
            "docroot/core": [
                "type:drupal-core"
            ],
            [...]
            "docroot/libraries/{$name}": [
                "type:drupal-library"
            ]
        },
    }
geerlingguy’s picture

Note 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.

Anybody’s picture

After 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?

Anybody’s picture

Status: Needs work » Needs review
FileSize
1.7 KB

Patch attached. Please review.

Anybody’s picture

Furthermore 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.

Anybody’s picture

There is a comma missing before "repositories" in patch #10 and here:

"require": {
"fortawesome/font-awesome": "^4.6"
"fortawesome/fontawesome-iconpicker": "^1.3"
}

Needs reroll.

D34dMan’s picture

@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

Anybody’s picture

Ok 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.

D34dMan’s picture

@Anybody yes i will do it while testing it today

D34dMan’s picture

Re 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.

  • 60885fb committed on 8.x-1.x
    Issue #2841406 by cosmicdreams, Anybody, D34dMan: Composer Integration
    
D34dMan’s picture

Status: Needs review » Fixed

Commited to 8.x-1.x Thanks for the contribution everybody!

D34dMan’s picture

Status: Fixed » Active

Sorry, 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'

composer require 'drupal/fontawesome_iconpicker:1.x-dev'                                                                   Sat Dec  9 16:29:35 2017
    1/2:	https://packages.drupal.org/8/drupal/provider-2017-4$e5d2581297beee6bcdef3de64dd5f831db60bbf60c85c0dc1193707b5d84ce53.json
    2/2:	https://packages.drupal.org/8/drupal/provider-2017-3$faafc04803c9788f3d21c044506604c4e529bc59ae0c5881626a0bbdd86d0a29.json
    Finished: success: 2, skipped: 0, failure: 0, total: 2
    1/4:	http://packagist.org/p/provider-latest$6a0c34dd8f9dd48e680fe6d89be937a7fedc2c4ace70bfd31861289834474782.json
    2/4:	http://packagist.org/p/provider-2017-01$085df845c3bdac3c7d997b3fc25e52d099c17fd088a22994c49b936265a8c3b8.json
    3/4:	http://packagist.org/p/provider-2017-10$c8b3c88447c0f93bd2dd86eee34f0ccd7fdc13a023ce7456716622c6e9068299.json
    4/4:	http://packagist.org/p/provider-2017-07$11eb16e59a3a4084482964e1ca96f0afd5b09b84154269ba2fae51a32a53a8ef.json
    Finished: success: 4, skipped: 0, failure: 0, total: 4
./composer.json has been updated
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for drupal/fontawesome_iconpicker 1.x-dev -> satisfiable by drupal/fontawesome_iconpicker[1.x-dev].
    - drupal/fontawesome_iconpicker 1.x-dev requires farbelous/fontawesome-iconpicker ^1.3 -> no matching package found.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.
matthiasm11’s picture

Altered 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.

matthiasm11’s picture

Status: Active » Needs review
matthiasm11’s picture

Can someone check and commit this patch to dev please?

Thanks!

D34dMan’s picture

@matthiasm11 waiting for RTBC :)

matthiasm11’s picture

Quite 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.

  • matthiasm11 authored 0d3bfc1 on 8.x-1.x
    Issue #2841406 by D34dMan, cosmicdreams, Anybody, matthiasm11: Composer...
D34dMan’s picture

After 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

matthiasm11’s picture

Status: Needs review » Needs work

While 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

Things like CKeditor JS and CSS can't be autoloaded like PHP can, modules need a way of getting libraries in a web-accessible path. Traditionally sites/all/libraries but /libraries seems to be most common in D8.

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)

  • Download the required libraries and add them to your web/libraries directory.
  • Or add the dependencies to your Drupal composer file, the same file where you add this module the Drupal:
{
  "type": "package",
  "package": {
    "name": "fortawesome/font-awesome",
    "version": "v4.7.0",
    "type": "drupal-library",
    "extra": {
      "installer-name": "fontawesome"
    },
    "dist": {
      "url": "https://github.com/FortAwesome/Font-Awesome/archive/v4.7.0.zip",
      "type": "zip"
    },
    "require": {
      "composer/installers": "~1.0"
    }
  }
},
{
  "type": "package",
  "package": {
    "name": "farbelous/fontawesome-iconpicker",
    "version": "v1.3.1",
    "type": "drupal-library",
    "extra": {
      "installer-name": "fontawesome-iconpicker"
    },
    "dist": {
      "url": "https://github.com/farbelous/fontawesome-iconpicker/archive/1.3.1.zip",
      "type": "zip"
    },
    "require": {
      "composer/installers": "~1.0"
    }
  }
}
matthiasm11’s picture

D34dMan’s picture

@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?

matthiasm11’s picture

Status: Needs work » Postponed

Sure!

micbar’s picture

What about asset packagist?

This is the way of the lightning distribution.
In the root composer.json, they define a second repository:

"repositories": {
        "drupal": {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        "assets": {
            "type": "composer",
            "url": "https://asset-packagist.org"
        },

and then require:
composer require bower-asset/fontawesome
composer require bower-asset/fontawesome-iconpicker

installer paths would look like:

],
        "installer-paths": {
            "docroot/core": [
                "type:drupal-core"
            ],
            "docroot/libraries/{$name}": [
                "type:drupal-library",
                "type:bower-asset",
                "type:npm-asset"
            ],
            "docroot/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "docroot/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "docroot/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/contrib/{$name}": [
                "type:drupal-drush"
            ]
        },
micbar’s picture

Let 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.

D34dMan’s picture

I 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.

Andrew Answer’s picture

Andrew Answer’s picture

Previous test was failed because of it can't patch composer.json.

stevendeleus’s picture

Id like to contribute to this issue, but I don't know how.

Anybody’s picture

Comment #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:

"repositories": [
    [ ... ]
    {
      "type": "composer",
      "url": "https://asset-packagist.org"
    }
]

plus suggestion for:

      "libraries/{$name}": [
        "type:npm-asset",
        "type:bower-asset",
        "type:drupal-library"
      ],

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.

mmjvb’s picture

Don'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

Andrew Answer’s picture

Please review this issue because it blocks upgrading module with Composer without adding custom repositories.

Anybody’s picture

Status: Needs review » Reviewed & tested by the community

RTBC 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.

D34dMan’s picture

Status: Reviewed & tested by the community » Fixed

The 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.

Status: Fixed » Closed (fixed)

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