digitalutsc / islandora_lite_docs

Contains a Wiki with documentation for the UTSC Library's Islandora Lite System
GNU General Public License v3.0
2 stars 0 forks source link

Setup composer.json for installing modules and all its dependencies by `composer require` #47

Closed kylehuynh205 closed 2 years ago

kylehuynh205 commented 2 years ago

In composer.json of a Drupal module, make sure to have:

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

Because by default, composer is looking for package in packagist.org, but Drupal has their own place for its modules and themes, the code block above redirected to Drupal's package site.

Next, include all the dependencies in the "require" block, ie.

     "require": {
        "react/child-process": "*",
        "react/event-loop": "*",
        "drupal/advancedqueue": "*"
    },

Implemented:

kylehuynh205 commented 2 years ago

For JS library required by Drupal module, for example: PDF module needs pdf.js library to be cloned and place under libraries directory (ie. drupal/web/libraries). To have it run automatically with composer, place the following code in composer.json at root of Drupal site (for site level),

  "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        },
        {
            "type": "package",
            "package": {
                "name": "mozilla/pdf.js",
                "version": "2.10.377",
                "type":"drupal-library",
                "source": {
                    "url": "https://github.com/mozilla/pdf.js.git",
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    ],

   "require": {
        "mozilla/pdf.js": "2.10.377"
    },

Make sure to have:

"composer/installers": "^1.0"
 "installer-paths": {
            "web/core": ["type:drupal-core"],
            "web/libraries/{$name}": ["type:drupal-library"],
            "web/modules/contrib/{$name}": ["type:drupal-module"],
            "web/profiles/contrib/{$name}": ["type:drupal-profile"],
            "web/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/Commands/{$name}": ["type:drupal-drush"]
        },

Source: https://stefvanlooveren.me/blog/how-add-github-repository-composerjson-be-used-library-drupal-8-solved

kylehuynh205 commented 2 years ago

Clone the repository with a zip file instead:

{
   "name":"smarty/smarty",
   "version":"3.1.7",
   "dist":{
      "url":"https://www.smarty.net/files/Smarty-3.1.7.zip",
      "type":"zip"
   }
}