drupal-project
drupal-project copied to clipboard
How to switch from this composer template to the drupal/recommended-project template?
If I have a site with a codebase that was originally built with this Composer project template, I would like to know what steps are required to convert the codebase into one that is like drupal/recommended-project would produce.
As an example, I noticed that this project includes drush/drush (and a number of other dependencies the core template does not). It also has a ScriptHandler.php class that is required to be present for CLI stuff to work, which is referenced in the project composer.json (core does not have this, at least not in any non-vendored location).
Is there any easy way to switch a project built with this to the 'recommended-project' template? Or is it manual picking-apart to try to get the composer.json changes matched up?
Thank you, @geerlingguy ! I would also like to know.
+1 Thanks
Maybe I can share a diff where I did this:
diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -19,20 +18,20 @@
- "drupal-composer/drupal-scaffold": "^2.5",
- "drupal/core": "^8.8.0",
+ "drupal/core-composer-scaffold": "^8.8",
+ "drupal/core-recommended": "^8.8",
@@ -47,18 +46,15 @@
- "webflo/drupal-finder": "^1.0.0",
- "webmozart/path-util": "^2.3",
"zaporylie/composer-drupal-optimizations": "^1.0"
},
"require-dev": {
+ "drupal/core-dev": "^8.8",
- "webflo/drupal-core-require-dev": "^8.8.0"
},
@@ -71,49 +67,25 @@
- "autoload": {
- "classmap": [
- "scripts/composer/ScriptHandler.php"
- ],
- "files": ["load.environment.php"]
- },
- "scripts": {
- "pre-install-cmd": [
- "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
- ],
- "pre-update-cmd": [
- "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
- ],
- "post-install-cmd": [
- "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
- ],
- "post-update-cmd": [
- "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
- ],
- "post-create-project-cmd": [
- "DrupalProject\\composer\\ScriptHandler::removeInternalFiles"
- ]
- },
"extra": {
+ "drupal-scaffold": {
+ "locations": {
+ "web-root": "web/"
+ }
+ },
"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"]
- },
- "drupal-scaffold": {
- "initial": {
- ".editorconfig": "../.editorconfig",
- ".gitattributes": "../.gitattributes"
- }
+ "drush/Commands/contrib/{$name}": ["type:drupal-drush"],
+ "web/modules/custom/{$name}": ["type:drupal-custom-module"],
+ "web/themes/custom/{$name}": ["type:drupal-custom-theme"]
Note that the above diff has been edited to remove non-related lines.
In addition to this, I deleted the scripts/composer/ScriptHandler.php file.
is this the new "drupal" core way to do things?
@worthwhileindustries According to this Drupal documentation it is: https://www.drupal.org/docs/8/update/update-core-via-composer#s-special-considerations-for-upgrading-to-drupal-880-and-later
@worthwhileindustries i would think of it as "an emerging, minimalist, canonical example" and you'd stick with drupal-composer/drupal-project for a practical real-world example, at least for now.
https://www.drupal.org/docs/8/update/update-core-via-composer#s-special-considerations-for-upgrading-to-drupal-880-and-later provides a working, excellent recipe to move away from webflo/drupal-core-strict and start with the new drupal/core-recommended.
We need to provide an equally clear step-by-step documentation about how to migrate from drupal-composer/drupal-project to drupal/core-recommended.
Can someone post step by step instructions? I don't know enough about the inner working of drupal-composer/drupal-project and composer to be confident.
I did that. Do not follow blindly, you may want to keep some stuff.
Migrate from .env
Update web/sites/default/settings.php if you migrate from .env
cleanup
rm .env
rm .env.example
rm load.environment.php
rm -r drush
rm -r scripts
Update your .gitignore
Compare your .gitignores with the default one from drupal => in particular rm settings.php from being commited if it was
Fix composer packages
rm composer.lock
composer remove drupal-composer/drupal-scaffold --no-update
composer remove drupal/core --no-update
composer remove webflo/drupal-finder --no-update
composer remove webmozart/path-util --no-update
composer remove webflo/drupal-core-require-dev --no-update
composer remove cweagans/composer-patches --no-update
composer remove vlucas/phpdotenv --no-update
composer remove zaporylie/composer-drupal-optimizations --no-update
composer require 'composer/installers:^1.7' --no-update
composer require 'drupal/core-composer-scaffold:^8.8' --no-update
Replace extra section in composer.json
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"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/contrib/{$name}": ["type:drupal-drush"],
"web/modules/custom/{$name}": ["type:drupal-custom-module"],
"web/themes/custom/{$name}": ["type:drupal-custom-theme"]
}
}
Install drupal/core-recommended
rm -r vendor
composer require drupal/core-recommended:^8.8 --update-with-dependencies
Hi, @gagarine. Unfortunately I could just follow you blindly, since I'm a damn newbie struggling to get out of a nightmare.
You suggested a "rm -r scripts", though I got what mentioned below.
[RuntimeException]
Could not scan for classes inside "scripts/composer/ScriptHandler.php" which does not appear to be a file nor a folder
So I supposed the directory should be left where it is, shouldn't it?
Besides, I really hope, once the recommended project is in place, migrating to drupal 9 will be easy........
Thanks for you contribution and thanks in advance for what you may answer.
Andrea
@AppLEaDaY in your composer.json you may have something like:
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php"
],
"files": ["load.environment.php"]
},
Try to delete this autoload section.
I would also delete the scripts part if you have one
"scripts": {
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"pre-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
]
},
@gagarine, thanks.
I did try, with no luck, unfortunately.
I report below the last command you suggested.
composer require drupal/core-recommended:^8.8 --update-with-dependencies
It seems this command is dependent on the cli php version, anyway I get, alternatively
- Your requirements could not be resolved to an installable set of packages (I suppose with php 8.1.16 in the path)
- A blank page (after I specify a php 7.2.34 before ~/bin/composer)
What did I do wrong? I'm confused.
And besides I was wondering what .gitignore you were referring to.
Anyway I came across a guide that looks encouraging.
https://drupalize.me/tutorial/update-drupal-versions-prior-88x-using-composer
What about that?
Thanks in advance!
Andrea
P.S. For the sake of completeness, I have to say the drupal-composer/drupal-project where I started didn't look in good order, since I was facing some dependency problem (I can't recall how many) even if tried to remove a module with composer. How much does this matter?