Problem/Motivation
Site Maintainers ought to be able to utilize custom dependencies in their Drupal projects.
These dependencies could be:
- Composer package such as Guzzle OAuth Subscriber
- Drupal module such as Insert Field.
- Drupal theme such as Omega
- Drupal site such as davidwbarratt
All of these things (plus anything else that can be managed with Composer) should be able to be managed withing a Drupal Project, as if it were any other PHP project. Since Composer handles dependencies recursively, any of the above mentioned dependencies could have dependencies of their own and these will be managed within the same instance of Composer.
Since Drupal's composer.json file is in the root directory (which is far better than it being in the core directory), the question has been raised: Is it acceptable to modify Drupal's composer.json file?
This is an important question, however, it appears that the Drupal best practice of never modifying core still remains true.
In naderman& RobLoach's presentation at DrupalCon Munich, it was recommended that Drupal core become a dependency of Drupal. This would allow end-users to modify Drupal's composer.json file, while at the same time maintaining Drupal core's own composer.json file that would not be touched.
Proposed resolution
- Essentially revert #1805316: Move composer.json to the project root
- Create a new composer.json file in the project root
- #2372815: Make the <root>/composer.json file a working example
- Document how to use Composer with Drupal (i.e. modify index.php and change vendor directory)
The <root>/composer.json
name
will be:drupal/drupal
The core/composer.json
name
will be:drupal/core
The <root>/composer.json
file would only have one requirement: drupal/core
and the type would change to project
Pros
- Users can use Composer without modifying a core file.
- Drupal Core is a dependency of the Drupal project
- Drupal's dependencies remain in-tact.
- Composer users can exclude
core
andvendor
directories from their repositories - Allows users to manage contrib modules via Composer (like #1886820: Packagist for Drupal Projects)
- Only requires changes to two
json
files. - Does not require rewritting all current patches
- Does not require any changes to the packaging script
- Allows the
core/vendor
directory to remain in Drupal's repositories - Changes should be transparent to all users, minor changes for core maintainers.
Cons
- Disruption: Drupal hosts may want/need to re-work their hosting platforms for Drupal 8 (to take advantage of this). This is also a benefit?
<root>/composer.json
file is a non-working example until #2372815: Make the <root>/composer.json file a working example is resolved- Executing
composer install
from the root of the project would delete thecore
directory and add it back. Any changes to the folder would be destoryed. - Composer users will need to modify
index.php
in order to use Composer with Drupal.
Remaining tasks
- Test the most recent patch
- #2372815: Make the <root>/composer.json file a working example
- Document how to use Composer with Drupal (i.e. modify index.php and change vendor directory)
Testing
You can test the most recent patch by:
- Modify the example
<root>/composer.json
.- Add this repository:
{
"type": "vcs",
"url": "git@github.com:davidbarratt/drupal-core.git"
}Not necessary when/if #2372815: Make the <root>/composer.json file a working example lands.
- Require this custom installer
"davidbarratt/custom-installer": "~1.0"
Not necessary when/if #2372815: Make the <root>/composer.json file a working example lands.
- Add the necessary config for the custom installer in
extra
"custom-installer": {
"drupal-core": "core"
}Not necessary when/if #2372815: Make the <root>/composer.json file a working example lands.
For your conveince I've compiled all of these changes into this composer.json file.
- Add this repository:
- Modify index.php
Change this line from:$autoloader = require_once __DIR__ . '/core/vendor/autoload.php';
to:
$autoloader = require_once __DIR__ . '/vendor/autoload.php';
Not necessary when/if #2380389: Change index.php to use a vendor directory in the root or move code out of index.php and into core lands.
API changes
Core contributors will need to change their working directory to /core
before executing a composer
command. However, this is the same as it was before #1805316: Move composer.json to the project root.