This is based on my understanding of how things work and may be flawed to to lack of complete understanding...

My struggle with the current state of things when installing the external libraries with composer is two fold. It requires:

  1. Running a drush command, and
  2. Manually modifying a composer.json file.

Additionally, this process must be repeated if there is any modification to the generated composer.json by the module maintainer.

It would be much better in my opinion to simply include the libraries in the webform module's composer.json file by default. This way the dependencies area automatically installed once the module is installed/required via composer. Drush commands could live on for Drush Make users or tar.gz installers.

Short of that I'm considering a contrib module "Webform Libraries" or such that simply has the same composer.json that drush generates so that it can be required via composer to download the libraries. It feels hacky, and would create some maintenance to keep it inline with Webform but unless the dependencies end up in the Webform composer file, I think it makes the most sense.

Ideas, thoughts, corrections?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

artis created an issue. See original summary.

artis’s picture

Title: "Webform Libraries" with composer.json generated by 'drush webform-libraries-composer' as submodule or contrib? » Composer.json generated by 'drush webform-libraries-composer' included in module or as "Webform Libraries" contrib?
jrockowitz’s picture

Drupal's testbot does not support dependencies in a module's composer.json file.

Also most libraries are optional so we can't assume all libraries should be installed.

Another option could be to create a drush command that updates the entire installations /composer.json file to include the selected webform libraries.

jrockowitz’s picture

I think writing a `drush webform-composer-update` might be the best solution.

One trick would be to add an _webform: true property to any composer.json repository managed using this command

artis’s picture

The additional drush command is better, but still runs into an issue where when `composer update` is run and there is a new version of Webform the composer.json file will be overridden, right?

Here is a thought...other modules use bower for js/css dependencies, then we can maintain/update them through bower. Providing that as an optional way to install the webform dependencies, if possible, would help with the maintenance issue since many of us are already maintaining bower packages separate to composer.

This seems like a larger issue than just Webform, I'll try to find out where that discussion is happening and weight in there too.

Thanks!

BTW, this module is mind-blowing! You've done a phenomenal job!

jrockowitz’s picture

I think it is worth experimenting with the drush command because webform libraries are optional and can be enabled/disabled via the UI. This is a unique requirement/feature.

BTW, the drush command would update the composer.json for the entire Drupal installation not the Webform module.

I would be open to adding a drush command that generates the needed bower file but I am not actively using Bower.

also @see #2605130: Best practices for handling external libraries in Drupal 8/9 and 10

jrockowitz’s picture

Status: Active » Needs review
FileSize
5.56 KB

Once you apply the patch, make sure to backup your site and composer.json, and then execute `drush webform-composer-update`.

  • jrockowitz committed 23d88de on 8.x-5.x
    Issue #2884234 by jrockowitz: Composer.json generated by 'drush webform-...
jrockowitz’s picture

  • jrockowitz committed 096c79a on 8.x-5.x
    Issue #2884234 by jrockowitz: Composer.json generated by 'drush webform-...

Status: Fixed » Closed (fixed)

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