Problem/Motivation

When we using composer manager to manage Drupal module packages with composer we does not add explicitly the dependencies of modules into composer.json of application but we should have all packages required by modules on install it.

To assume composer with Dropzonejs we just need to add an composer.json.

Actually we have the following message when we try to user vcs repositories via github too :

[Composer\Repository\InvalidRepositoryException]
No valid composer.json was found in any branch or tag of git@github.com:drupal-media/dropzonejs.git, could not load a package from it.

Proposed resolution

Add correct composer.json on module basis.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

woprrr created an issue. See original summary.

woprrr’s picture

Status: Active » Needs review
FileSize
1.1 KB
Primsi’s picture

Status: Needs review » Needs work

Great. There was also a pull request on github. Maybe we can use something from there.

+++ b/composer.json
@@ -0,0 +1,33 @@
+      "name": "John McCormick",
+      "homepage": "drupal.org/u/neardark",
+      "role": "Maintainer"

chrfritsch is a maintainer too now, John has not been very active, so I think it's best to put chrfritsch here.

woprrr’s picture

Status: Needs work » Needs review
FileSize
1.38 KB
746 bytes

Here the fix ;), I don't seen the Github PR it's important for contributor to backport her PR into D.O to prevent these problems but it's not easy... I voluntary immoted the libraries require {} because that can introduces few problems with "custom" composer architectures. The require project are not drupal-library it's impossible to place it onto libraries without explicit extra {installer-path:}, that's the responsabilities to manager to add this, BUT we add suggest package to inform composer users to our requirement that reduce hightly the potential miss-configuration etc... In addition we can user libraries API to download/user sources that it's better to take this responsabilites to maintainer of applications.

I've think another wording for suggest like :

"enyo/dropzone": "Required to use drupal/dropzonejs but you are free to add this manually or with libraries module. Dropzone is an easy to use drag'n'drop library."

  • Primsi committed 47a9357 on 8.x-1.x authored by woprrr
    Issue #2853274 by woprrr, Primsi, killua99: Add Composer.json to project
    
Primsi’s picture

Status: Needs review » Fixed

Committed, thanks.

zet’s picture

From https://getcomposer.org/doc/04-schema.md#suggest :

suggest#

Suggested packages that can enhance or work well with this package. These are just informational and are displayed after the package is installed, to give your users a hint that they could add more packages, even though they are not strictly required.

The format is like package links above, except that the values are free text and not version constraints.

Example:

{
"suggest": {
"monolog/monolog": "Allows more advanced logging of the application flow",
"ext-xml": "Needed to support XML format in class Foo"
}
}

so the respond.js should not be a suggestion, because it does not "enhance or work well" with this module.
DropzoneJS library is a actually a requirement for this module to function, and this have nothing to do with the fact that installer-path for libraries should need to be setup after from a project root composer.json

A Drupal 8 site should be easily installed and extended with the "composer create-project ..." command and "composer require ...", without the need to go and manually download required libraries. That's the main purpose of composer, if not we could just stick to drush dl.

So when you install the Drupal 8 project with composer and want to add this module,
"composer require drupal/dropzonejs " and "composer update" should be all.

Primsi’s picture

I agree and share the same frustration with you, it should be easy.

But in this case we are not dealing with a php lib that lives on packegist, it's a js library that lives on a separate repository. And drush dl didn't support pulling this kind of dependencies either.

There are third party libraries that one can include in the composer file, that then download js dependencies, but I don't think I saw much Drupal projects using them. I would be happy to hear more about that though.

woprrr’s picture

Yes, I agree too :( I've opted for the better degraded solution with suggest to insitate manager to dl that but that is an requirement... We have same problem in ImageWidgetCrop module and we have avoid that by not add any mention and use by default External CDNJS and if user want purpose a fallback with Libraries module usage. I suposse is that the "Drupal" right way but not verry good for Composer manager :/ We have possibility to "fork" that libraries and add correct type: drupal-library to permit using that ... I didn't see other better solutions :(

zet’s picture

Since in this specific case dropzonejs is an integration module for the dropzone.js library, clearly listed as a requirement and linked from the module page to the library/project github page, what I don't understand is why the composer.json file included with the drupal module dropzonejs does not contain something like this:

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "enyo/dropzone",
                "version": "4.3.0",
                "type": "drupal-library",
                "source": {
                    "url": "https://github.com/enyo/dropzone",
                    "type": "git",
                    "reference": "origin/master"
                }
            }
        },
    "extra": {
        "installer-paths": {
            "web/libraries/{$name}": [
              "type:drupal-library",
              "enyo/dropzone"
            ],
        }

web/libraries/{$name} is the path that drupal8 project is using.

Then if any distribution wants to include the module in the distribution, the distribution global composer.json should override the module defined "installer-paths" to something like docroot/libraries/{$name} or sites/default/files/libraries/{name} or whatever they desire

Actually the code above is an example from what I included in the Thunder ( https://www.drupal.org/project/thunder ) distribution's main composer.json managing to download the required libraries without nodejs, npm and bower. I guess the distribution is using nodejs, npm and bower to download them ( correct me if I'm wrong)

Status: Fixed » Closed (fixed)

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