Custom Module Dependencies

Modules can define package dependencies in their own composer.json.

{
    "name": "drupal/views_sql_query_formatter",
    "type": "drupal-custom-module",
    "require": {
        "jdorn/sql-formatter": "^1.2.17"
    }
}

To include these required packages, declare the custom module's local path to the root composer.json.

"reppositories": [
    {
        "type": "path",
        "url": "web/modules/custom/views_sql_query_formatter"
    }
]

Require the module with composer to install dependencies.

composer require drupal/views_sql_query_formatter
Using version dev-dev for drupal/views_sql_query_formatter
./composer.json has been updated
Running composer update drupal/views_sql_query_formatter
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
  - Locking drupal/views_sql_query_formatter (dev-dev)
  - Locking jdorn/sql-formatter (v1.2.17)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Installing jdorn/sql-formatter (v1.2.17): Extracting archive
  - Installing drupal/views_sql_query_formatter (dev-dev): Source already present
Generating autoload files
60 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

Required dependencies are now available in module code.

$sql = 'SELECT "node_field_data"."changed" AS "node_field_data_changed", "node_field_data"."nid" AS "nid"
FROM
{node_field_data} "node_field_data"
LEFT JOIN {node__body} "node__body" ON node_field_data.nid = node__body.entity_id AND (node__body.deleted = '0' AND node__body.langcode = node_field_data.langcode)
WHERE ("node_field_data"."type" IN ('class')) AND ((node_field_data.status = 1 OR (node_field_data.uid = 1 AND 1 <> 0 AND 1 = 1) OR 1 = 1)) AND ("node__body"."body_value" IS NOT NULL)
ORDER BY "node_field_data_changed" DESC';

$output = SqlFormatter::format($sql);