8

I've got the following composer.json file:

{
    "name": "my-project",
    "type": "project",
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "package",
            "package": {
                "name": "contrib/term-csv-tree-import",
                "version": "dev-master",
                "type":"drupal-module",
                "source": {
                    "url": "https://github.com/grahl/term_csv_tree_import.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],
}

However after composer update, the module is downloaded to the vendor folder as:

./vendor/contrib/term-csv-tree-import/term_csv_tree_import.info.yml
./vendor/contrib/term-csv-tree-import/term_csv_tree_import.module
./vendor/contrib/term-csv-tree-import/term_csv_tree_import.routing.yml

How can I correct above configuration to download the project as a Drupal module under docroot/modules/contrib folder? My Drupal root is under docroot folder.

1
  • 1
    The module hasn't got a composer.json file so that's an impediment.
    – mona lisa
    Aug 10, 2017 at 23:33

1 Answer 1

11

You need Composer Installers for that:

{
    "name": "my-project",
    "type": "project",
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "package",
            "package": {
                "name": "contrib/term-csv-tree-import",
                "version": "dev-master",
                "type":"drupal-module",
                "source": {
                    "url": "https://github.com/grahl/term_csv_tree_import.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],
    "require": {
        "composer/installers": "^1.2"
    },   
    "extra": {
        "installer-paths": {
            "docroot/libraries/{$name}": ["type:drupal-library"],
            "docroot/modules/contrib/{$name}": ["type:drupal-module"],
            "docroot/profiles/contrib/{$name}": ["type:drupal-profile"],
            "docroot/themes/contrib/{$name}": ["type:drupal-theme"]
        }
    }
}
4
  • Any chance of updating the codebase either on each install/update call or allowing composer to track versions for those externally hosted repos (using tags for that purpose)?
    – Pjotr
    Sep 9, 2019 at 12:27
  • 2
    In my experience that will only work if the repo(s) in question each contain a composer.json of their own @Pjotr. So easy to do if you control the code, not so easy if not
    – Clive
    Sep 9, 2019 at 16:11
  • Fortunately, we do control the codebase in our case. The repos are pretty much Drupal 8 modules, except not hosted on the official infrastructure. Could you provide a hint/link to some place that has information to either force pull on each install/update or to trick composer into updating according to tagged releases without additional changes and while still keeping that a simple GitHub repo? I did write a code that would do the pulling post install/update but would prefer not to use it.
    – Pjotr
    Sep 10, 2019 at 10:28
  • I don't know of a way to accomplish either I'm afraid. If you want composer to update based on tags, the project needs a composer.json. I have never found a way to invoke another composer update/install at the end of an update/install, I don't think it's a workflow they've envisaged. You could hack it with bash, obviously, but I doubt it'd be pretty
    – Clive
    Sep 10, 2019 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.