Score:0

How exactly does drush determine PROJECTROOT and WEBROOT for a project?

ph flag

In the Drush Configuration section of the official documentation it is said:

drush.yml files are discovered as below, in order of precedence:

  1. Drupal site folder (e.g. sites/{example.com}/drush.yml).
  2. sites/all/drush, WEBROOT/drush, or PROJECTROOT/drush.
  3. ...

There you can see "WEBROOT" and "PROJECTROOT", but there's no explanation on what they are. In the Drush code there's no mention either apart from the configuration itself:

$ grep PROJECTROOT * -r
drush/docs/using-drush-configuration.md:2.  `sites/all/drush`, `WEBROOT/drush`, or `PROJECTROOT/drush`.                                                                                                                                

$ grep WEBROOT * -r 
drush/docs/using-drush-configuration.md:2.  `sites/all/drush`, `WEBROOT/drush`, or `PROJECTROOT/drush`.                 

How Drush determines the values of PROJECTROOT and WEBROOT?

The questions is what those names means, but how Drush decide what they are. If they are used to search for different configuration files it means that Drush resolved those names to actual folders or paths in the current system. How Drush resolves them?

My guess is that Drush takes the root folder of the site (defined ion the Drush alias. If that folder is a Drupal root then WEBROOT and PROJECTROOT are the same, the defined root folder. If the configured root folder has a composer.json and a web folder then PROJECTROOT is the confiugred root path, and the web folder is the WEBROOT... but it is just a guess.

cn flag
I’d imagine it literally means the root folder of your project vs the folder in your project which contains the web root.
sanzante avatar
ph flag
Yes, that's true. But how Drush knows that? In the alias configuration you define the root path. That could be the webroot, but that's not true because you can point to the folder that contains the composer.json. I guess Drush is intelligent enough to check if the root configuration value is a drupal root (in that case WEBROOT and PROJECTROOT are that folder) or is boilerplate scheme like the one created by `composer create-project`, so the folder with composer.json is PROJECTROOT and the web folder is WEBROOT... but I would like a confirmation.
cn flag
Yes, drush is clever enough to traverse up the folder structure until it can find something it identifies as a Drupal project root (you'd have to look at the code to get the exact criteria). Similar to how Git, Composer and other tools work
Score:3
in flag

Drush uses webflow/drupal-finder to determine these directories. The logic is in the DrupalFinder::findAndValidateRoots()

WEBROOT is the Drupal root folder and PROJECTROOT is the folder where the composer.json file is placed.

DrupalFinder is used in several places, but the interesting part is the Preflight::setSelectedSite function.

There Drush locates the "Drupal Root" and the "Composer Root". The "Drupal Root" is... well, the Drupal Root folder and what the Drush documentation calls WEBROOT. And the "Composer Root" is the folder where composer.json file is located and it is what the documentation calls PROJECTROOT.

sanzante avatar
ph flag
Yes, I understand that, the question is more about how Drush determines the values for those folders. I've updated my question.
sonfd avatar
in flag
Updated @sanzante
sanzante avatar
ph flag
Thanks! That's what I was looking for! I'm updating my question with my findings.
Score:0
de flag

When you download Drupal using Composer, you get directory (folder) with some files. This is the project root, as it is the top-level of the entire project.

However, when viewing a Drupal site through a browser, you are not viewing the project root, rather, you are viewing one directory below it; by default, this folder is called /web (though it can be changed in composer.json). The web folder is the webroot, as it is the top-level folder that is viewed when accessing the project through the web.

sanzante avatar
ph flag
That's the standard definition of a web root and a project root. I already know that. What I am asking is how Drush determines the value of WEBROOT and PROJECTROOT, not the general definition of web and project root in the context of a web project.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.