Coder Social home page Coder Social logo

drupal-finder's Introduction

Drupal Finder

GitHub Workflow Status Packagist

Drupal Finder provides a class to locate a Drupal installation in a given path.

Usage

$drupalFinder = new \DrupalFinder\DrupalFinder(getcwd());

$drupalRoot = $drupalFinder->getDrupalRoot();
$composerRoot = $drupalFinder->getComposerRoot();
$vendorDir = $drupalFinder->getVendorDir();

Environment variables

If a set of environment variables is specified, then Drupal Finder uses those values to determine the paths of the pertinent directories:

  • DRUPAL_FINDER_DRUPAL_ROOT
  • DRUPAL_FINDER_COMPOSER_ROOT
  • DRUPAL_FINDER_VENDOR_DIR

For example:

  • DRUPAL_FINDER_DRUPAL_ROOT=/var/www/web
  • DRUPAL_FINDER_COMPOSER_ROOT=/var/www
  • DRUPAL_FINDER_VENDOR_DIR=/var/www/vendor

This is useful for situations where you are containerizing an application, directories may be in odd places, or a composer.json might be missing since it is unneeded in a final build artifact.

You are not required to set all the environment variables to use this feature. If you set an environment variable, then its associated getter function will return the value assigned to the environment variable.

Examples

License

GPL-2.0+

drupal-finder's People

Contributors

greg-1-anderson avatar leymannx avatar lpeabody avatar nkazarynava avatar webflo avatar weitzman avatar zaporylie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

drupal-finder's Issues

Add exception for missing composer.json file/document need for composer.json file

A project I worked on removed the composer.json as a security precaution, which in turn broke Drush. It turns out that this is because it uses drupal-finder to ascertain the Drupal root, which uses composer.json to figure that out. It would be handy to throw a specific exception for this instance, and to document it somewhere.

Drush 10.3.1 bootstrap exception when using absolute paths in composer.json "extra"

[Moved here from https://github.com/drush-ops/drush/issues/4488]

Describe the bug
Installing drupal 8.9.2 using composer (1.10.9 2020-07-16 12:57:00) produces a composer.json file with the relative path "web/" in composer.json "extra" (web-root and installer-paths). If I change this to an absolute path (pointing to the same web-folder) before running "composer install", drush commands (e.g. drush si) fail with "Bootstrap error" as it cannot find the drupal-core files.

To Reproduce

I ran these commands (note that I use an absolute path for composer as I have installed the latest composer version locally on a shared webhost):

mkdir -p /home/goforbun/drupal
cd /home/goforbun/drupal
php -d memory_limit=-1 /home/goforbun/composer/composer.phar create-project drupal/recommended-project:^8.9.2 --no-install newsite
cd /home/goforbun/drupal/newsite
sed -i "s/web\//\/home\/goforbun\/drupal\/newsite\/web\//g" composer.json
php -d memory_limit=-1 /home/goforbun/composer/composer.phar install
php -d memory_limit=-1 /home/goforbun/composer/composer.phar require drush/drush:^10.3.1
vendor/bin/drush si -vvv

The last step "drush si" fails with "Bootstrap Error", see "Actual behaviour" below. The relevant parts of my composer.json are

    "extra": {
        "drupal-scaffold": {
            "locations": {
                "web-root": "/home/goforbun/drupal/newsite/web/"
            }
        },
        "installer-paths": {
            "/home/goforbun/drupal/newsite/web/core": [
                "type:drupal-core"
            ],
            "/home/goforbun/drupal/newsite/web/libraries/{$name}": [
                "type:drupal-library"
            ],
            "/home/goforbun/drupal/newsite/web/modules/contrib/{$name}": [
                "type:drupal-module"
            ],
            "/home/goforbun/drupal/newsite/web/profiles/contrib/{$name}": [
                "type:drupal-profile"
            ],
            "/home/goforbun/drupal/newsite/web/themes/contrib/{$name}": [
                "type:drupal-theme"
            ],
            "drush/Commands/contrib/{$name}": [
                "type:drupal-drush"
            ],
            "/home/goforbun/drupal/newsite/web/modules/custom/{$name}": [
                "type:drupal-custom-module"
            ],
            "/home/goforbun/drupal/newsite/web/themes/custom/{$name}": [
                "type:drupal-custom-theme"
            ]
        },

and "ls /home/goforbun/drupal/newsite/web/core" does show the drupal files, so there are no obvious typos etc. The files are there, but drush doesn't find them.

For comparison, the following works (i.e. "drush si" runs) which modifies the default path to add an extra ../ relative level:

mkdir -p /home/goforbun/drupal
cd /home/goforbun/drupal
php -d memory_limit=-1 /home/goforbun/composer/composer.phar create-project drupal/recommended-project:^8.9.2 --no-install newsite
cd /home/goforbun/drupal/newsite
sed -i "s/web\//..\/newsite\/web\//g" composer.json
php -d memory_limit=-1 /home/goforbun/composer/composer.phar install
php -d memory_limit=-1 /home/goforbun/composer/composer.phar require drush/drush:^10.3.1
vendor/bin/drush si -vvv

Expected behavior
I expect "drush si" to run without errors, as long as the paths given in composer.json point to the correct drupal folder.

Actual behavior
"drush si" fails with Bootstrap error:

[goforbun@premium27 newsite]$ vendor/bin/drush si -vvv
 [preflight] Config paths: /home/goforbun/drupal/newsite/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /home/goforbun/drupal/newsite/drush/sites
 [preflight] Commandfile search paths: /home/goforbun/drupal/newsite/vendor/drush/drush/src
 [debug] Starting bootstrap to root [0.09 sec, 8.08 MB]

In BootstrapHook.php line 32:
                                                                      
  [Exception]                                                         
  Bootstrap failed. Run your command with -vvv for more information.  
                                                                      

Exception trace:
  at /home/goforbun/drupal/newsite/vendor/drush/drush/src/Boot/BootstrapHook.php:32
 Drush\Boot\BootstrapHook->initialize() at /home/goforbun/drupal/newsite/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:34
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook() at /home/goforbun/drupal/newsite/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:27
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize() at /home/goforbun/drupal/newsite/vendor/consolidation/annotated-command/src/CommandProcessor.php:145
 Consolidation\AnnotatedCommand\CommandProcessor->initializeHook() at /home/goforbun/drupal/newsite/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:289
 Consolidation\AnnotatedCommand\AnnotatedCommand->initialize() at /home/goforbun/drupal/newsite/vendor/symfony/console/Command/Command.php:221
 Symfony\Component\Console\Command\Command->run() at /home/goforbun/drupal/newsite/vendor/symfony/console/Application.php:1005
 Symfony\Component\Console\Application->doRunCommand() at /home/goforbun/drupal/newsite/vendor/symfony/console/Application.php:255
 Symfony\Component\Console\Application->doRun() at /home/goforbun/drupal/newsite/vendor/symfony/console/Application.php:148
 Symfony\Component\Console\Application->run() at /home/goforbun/drupal/newsite/vendor/drush/drush/src/Runtime/Runtime.php:118
 Drush\Runtime\Runtime->doRun() at /home/goforbun/drupal/newsite/vendor/drush/drush/src/Runtime/Runtime.php:49
 Drush\Runtime\Runtime->run() at /home/goforbun/drupal/newsite/vendor/drush/drush/drush.php:72
 require() at /home/goforbun/drupal/newsite/vendor/drush/drush/drush:4

Workaround
No workaround known to me. I need to specify a non-default path for my "web" folder.

System Configuration

Q A
Drush version? 10.3.1
Drupal version? 8.9.2
PHP version 7.3.20
OS? Linux (on shared host)

Additional information
My ultimate goal here is to have the folder with compose.json and vendor outside my webroot:
/home/account/drupal/newsite - outside webroot, containing composer.json, composer.lock and vendor folder. Not "web".
/home/account/public_html/newsite - for the drupal files, i.e. the "web/" created by composer install with default json.

I also tried using the default drupal-recommended setup, placing the files in the subfolder "web", then moving that folder and replacing it with a symbolic link. This also doesn't work, it seems drupal-finder refuses to follow the symbolic link. That would be an OK behaviour to me, but I think it should accept an absolute path, no matter where it is on the system.

drupal console fails if drupal/web has an empty composer.json file

I was advised in hechoendrupal/drupal-console#2770 (comment) to file this issue here, since drupal console uses this project.

The issue can be seen clearly here:

Normal situation:

[vagrant@local web]$ /vagrant/drupal/current/vendor/drupal/console/bin/drupal site:statistics
 -------------------------- ----------
  Name                       Quantity
 -------------------------- ----------
  Node:"Article"             3
  Node:"Event"               2
  Node:"Place"               2167

But what if you by mistake create an empty composer.json file in the web folder by running composer require drupal/some-drupal-module from the web folder (which you often are when you run drupal console and drush commands) like this:

[vagrant@local web]$ composer require drupal/devel
  [InvalidArgumentException]
  Could not find package drupal/devel at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

The result of this command is and empty composer.json file:

[vagrant@local web]$ cat composer.json
{
}

This is of course a mistake done by me as a developer, and it has happened to me many times - and a Google search for the error messages that show up with the empty composer.json file in place is proof that I am not alone:

[vagrant@local web]$ /vagrant/drupal/current/vendor/drupal/console/bin/drupal
InvalidArgumentException: The file "/vagrant/drupal/current/web/vendor/drupal/console-core//services.yml" does not exist. in /vagrant/drupal/current/vendor/symfony/config/FileLocator.php on line 44 #0 /vagrant/drupal/current/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(42): Symfony\Component\Config\FileLocator->locate('/vagrant/drupal...')
#1 /vagrant/drupal/current/vendor/drupal/console-core/src/Bootstrap/DrupalConsoleCore.php(35): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load('/vagrant/drupal...')
#2 /vagrant/drupal/current/vendor/drupal/console/src/Bootstrap/Drupal.php(101): Drupal\Console\Bootstrap\DrupalConsoleCore->boot()
#3 /vagrant/drupal/current/vendor/drupal/console/bin/drupal.php(48): Drupal\Console\Bootstrap\Drupal->boot()
#4 /vagrant/drupal/current/vendor/drupal/console/bin/drupal(4): require('/vagrant/drupal...')
#5 {main}
InvalidArgumentException: The file "/vagrant/drupal/current/web/vendor/drupal/console-core//services.yml" does not exist. in Symfony\Component\Config\FileLocator->locate() (line 44 of /vagrant/drupal/current/vendor/symfony/config/FileLocator.php).

Deleting the empty composer.json resolves this problem.

My desired situation: That drupal console doesn't stop working even if I have an empty composer.json placed in drupal's web folder.

Problem detecting DrupalRoot on Drupal 8.7

DrupalFinder is unable to detect drupalRoot is /web when using drupal core 8.7 - using wikimedia/composer-merge-plugin. Instead, it thinks the drupalRoot is /.

This issue occurs when running any drush or drupal command.

{
  "require": {
    "drupal/console": "~1.0",
    "drupal/core": "^8.7",
    "drush/drush": "^9.2"
  },
  "extra": {
    "installer-paths": {
      "web/core": [
        "type:drupal-core"
      ],
      "web/modules/contrib/{$name}": [
        "type:drupal-module"
      ],
      "web/profiles/contrib/{$name}": [
        "type:drupal-profile"
      ],
      "web/themes/contrib/{$name}": [
        "type:drupal-theme"
      ],
      "drush/contrib/{$name}": [
        "type:drupal-drush"
      ]
    }
  }
}

From what I gather this is because of a recent change to support Drupal core 8.8 (i.e. https://www.drupal.org/project/drupal/issues/2912387#comment-13188592)

Add method to get the vendor bin directory.

Usually the vendor bin directory is vendor/bin however a configuration can be added to composer.json in config.bin-dir the path to your vendor directory.

Some libraries which use this extension(such as rector) and being able to locate the vendor bin in a standard method will be very helpful.

Drush 9 freaks out when using symlink

I first reported this issue on Drush (see: drush-ops/drush#3098), but according to @weitzman, it's related to drupal-finder, that's why I open a new issue here.

Drush version used: Drush 9.0.0-beta7 (and reproduced also on beta 5 or 6)

With some structure, like the one used by Ansistrano, when we launch drush, it spawn processes indefinitely.

Example structure:

/srv/www/releases/mysite_1.0.2
/srv/www/current -> /srv/www/releases/mysite_1.0.2 (i.e: current is a symlink on mysite_1.0.2)

Inside the mysite_0.2 the Drupal is installed as follow:

  • src/ (contains composer.json (and .lock) for all the project dependencies (drupal modules and others dependencies)
  • src/web (Drupal root).

The core and modules are installed via Composer using composer/installers and the following installer paths, and Drupal Scaffold:

"installer-paths":
{
"drush/contrib/{$name}": [
"type:drupal-drush"
],
"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"
]
},

In this configuration, when we go in /srv/www/current/src/web (drupal root) and type for example "drush status", it nevers return anything and if we do a "ps aux | grep drush" we see numerous drush processes (increasing rapidly) being spawn.

If we go to the /srv/www/releases/mysite_0.2/src/web directory instead (so not using the symlink), it works just fine.

Current workaround so: either go to the original directory (not the symlink) or specify the real path using --root drush option.

Not working with latest acquia/lightning

I got reported DrupalConsole is not working with acquia/lightning and and did tried and seems like drupal-finder is not finding the drupal site.

hechoendrupal/drupal-console#2785 (comment)

I tested by

git clone [email protected]:acquia/lightning-project.git lightning
cd lightning
composer require drupal/console:~1.0

I also tested from my cloned repo of drupal-finder and dos not recognize the site

Not sure if this Installer path for drupal/core missing type acquia/lightning-project#23 is causing this issue.

Problem in drupalRoot and composerRoot detection if the installer paths of package drupal/core is dynamically set and not in composer.json

DrupalFinder is unable to detect drupalRoot and composerRoot in the following cases :

  • a project has a composer.json at its root path but installs drupal core (package drupal/core) in a subdirectory
  • the rule to place the package drupal/core is not written into the composer.json, but it is set inside a composer plug-in which patches the "extra" section when composer runs.

I saw in the source code of Drupalfinder, composer.json files may be opended and parsed to search for the target installation path of the drupal/core package. One way to improve this, if possible, may be to change the code of DrupalFinder to use the composer object and retrieve the content of the extra section directly in PHP...
what do you think?

Incorrect paths on Windows

I was working on mglaman/drupal-check#189 and noticed that weird paths were returned in realpath was called for the Drupal path.

Analyzing path: C:\projects\drupal\web\core\install.php
Using Drupal root: C:\projects\drupal/web
Using vendor root: C:\projects\drupal/vendor

The web and vendor paths have /. I know PHP fixes incorrect directory separators most of the time. But in AppVeyor I get crashes like

The filename, directory name, or volume label syntax is incorrect.
``

And I think it's because `cmd` chokes on `/`.

Drupal Finder does not work with Lightning Core

When Lightning Core is installed at docroot/modules/contrib/lightning_core and $this=>locateRoot('docroot/modules/contrib/lightning_core') is executed, Drupal Finder will incorrectly assume that docroot/modules/contrib/lightning_core is actually the root.

This is due to Lightning Core's composer.json, which contains entries for installer-paths.

It seems like it would be useful to add a couple of extra checks to Drupal Finder ensure that the directory structure looks like Drupal core. For instance, checking for core,index.php,modules, etc. Checking values in composer.json is not sufficient in all cases.

require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead.

[RuntimeException]
require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead.

Version used:
"drupal/core": "8.8.10"
"mikey179/vfsstream": "1.6.8"
"webflo/drupal-finder": "1.2.0"
php: 7.3.22

Today all of a sudden this error has started appearing while installing the site, can anyone update the refererence to mikey179/vfsStream in composer.json with small s rather than S

Drupal Finder does not find root when composer.json is not in root but in a root-subfolder

We have inherited a structure similar to:

/app (project root)
├── public
│   ├── drupal
|   |   ├── core
|   |   ├── autoload.php = <?php return require __DIR__ . '/../../thunder/vendor/autoload.php'; ?>
|   |   ├── index.php
|   |   └── ...
│   └── others
└── thunder
    ├── composer.json
    ├── composer.lock
    ├── sync
    └── vendor

This worked well using drush 8, but bootstrapping failed after upgrading to drush:

[bootstrap] Starting bootstrap to site [0.56 sec, 10.72 MB]
In BootstrapHook.php line 33:
  [Exception]
  Bootstrap failed. Run your command with -vvv for more information.

It seems that the problem lies in DrupalFinder::isValidRoot($path). Hardcoding the drupal-/composer-root and vendor dir there (like below) worked:

$this->drupalRoot = '/app/thunder/../public/drupal';
$this->composerRoot = '/app/thunder';
$this->vendorDir = '/app/thunder/vendor';
return $this->drupalRoot && $this->composerRoot && $this->vendorDir;

So the problem seems to be that the assumptions on the project structure are not universal. I am not sure if this needs to be addressed in drupal-finder or in drush itself by environment variables or drush options similar to --drupal-root in mglaman/drupal-check.

A workaround could be to add a (minimal) composer.json file to /app/public/drupal with following content:

{
    "description": "Workaround for drupal-finder to find drupal-, composer-root and vendor dir, see https://github.com/webflo/drupal-finder/issues/48",
    "extra": {
        "installer-paths": {
            "core": ["type:drupal-core"]
        }
    }
}

Would this be valid or may this introduce problems somewhere else?

DrupalFinder incorrectly assumes that location of composer.json is root.

I have composer.json at the top of my git repository.

I create a webroot folder, cd into that folder, then run composer from there setting COMPOSER=../composer.json

I am trying to build a webroot folder with all composer dependencies in the webroot folder.

This script should not go above the current folder to locate the root or at least somehow honour the fact that my root directory is not the same as my composer.json directory.

The composerRoot property does not contain the correct value.

The return TRUE; at DrupalFinder on line 88 stops the execution and makes $drupalRoot and $composerRoot contains the same value and $composerRoot never obtain the real path where the composer.json file is located.
https://github.com/webflo/drupal-finder/blob/master/src/DrupalFinder.php#L88

You can replicate by creating an example.php file containing:

use DrupalFinder\DrupalFinder;

require_once 'vendor/autoload.php';

$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot('/path/to/drupal/sites/drupal.dev/web');
$drupalRoot = $drupalFinder->getDrupalRoot();
$projectRoot = $drupalFinder->getComposerRoot();
echo 'projectRoot: ' . $projectRoot . PHP_EOL;
echo 'drupalRoot: ' . $drupalRoot . PHP_EOL;

and execute by php example.php and the output will be equal in both:

projectRoot: /path/to/drupal/sites/drupal.dev/web
drupalRoot: /path/to/drupal/sites/drupal.dev/web

Removing the offending line at 88 makes this works as expected.

Small optimisations for DrupalFinder (proposal)

First of all, I want to say that DrupalFinder works great in the current state.
But I've noticed there several places which can be updated/optimised.

/**
     * Drupal package composer directory.
     *
     * @var bool
     */
    private $composerRoot;

type hint should be string.

        $this->drupalRoot = false;
        $this->composerRoot = false;
        $this->vendorDir = false;

Probably will be better set null instead of false here for consistency. Or set false as default value for the properties:

    /**
     * Drupal web public directory.
     *
     * @var string|bool
     */
    private $drupalRoot = false;
  1. The next condition I propose to put into a separate method. It is used two times so it's make sense.
if ($follow_symlinks && is_link($path)) {
    $path = realpath($path);
}
        foreach (array(true, false) as $follow_symlinks) {
            $path = $start_path;
            if ($follow_symlinks && is_link($path)) {
                $path = realpath($path);
            }
            // Check the start path.
            if ($this->isValidRoot($path)) {
                return true;
            } else {
                // Move up dir by dir and check each.
                while ($path = $this->shiftPathUp($path)) {
                    if ($follow_symlinks && is_link($path)) {
                        $path = realpath($path);
                    }
                    if ($this->isValidRoot($path)) {
                        return true;
                    }
                }
            }
        }

else here doesn't have sence, because if statement has return, so it can be skipped.

Also here we have the same code before while loop and inside it. Probably it make sense replace it with do...while loop?

Is this small refactoring make sense? What do you think?

Can't install on Travis CI

Hi,
I am trying to replace webflo/drush-shim with drush/drush-launcher as recommended. On Travis CI builds I am now experiencing following dependency issue (using composer global require drush/drush-launcher):

Using version ^0.4.2 for drush/drush-launcher
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Can only install one of: webflo/drupal-finder[1.0.0, 0.4.2].
    - Can only install one of: webflo/drupal-finder[1.0.0, 0.4.2].
    - Can only install one of: webflo/drupal-finder[1.0.0, 0.4.2].
    - drush/drush-launcher 0.4.2 requires webflo/drupal-finder ^1.0 -> satisfiable by webflo/drupal-finder[1.0.0].
    - Installation request for drush/drush-launcher ^0.4.2 -> satisfiable by drush/drush-launcher[0.4.2].
    - Installation request for webflo/drupal-finder (locked at 0.4.2) -> satisfiable by webflo/drupal-finder[0.4.2].

webflo/drupal-finder, 1.0.0 is included through dependencies in the project's vendor directory already.

Any idea what could cause this issue and how to resolve it?

Code assumes that `installer-paths` elements are _always_ arrays

The current code assumes that elements are always arrays:

if (is_array($json)) {
if (isset($json['extra']['installer-paths']) && is_array($json['extra']['installer-paths'])) {
foreach ($json['extra']['installer-paths'] as $install_path => $items) {
if (in_array('type:drupal-core', $items) ||
in_array('drupal/core', $items) ||
in_array('drupal/drupal', $items)) {

However, upstream "allows" simple strings by casting to array:

https://github.com/composer/installers/blob/2a9170263fcd9cc4fd0b50917293c21d6c1a5bfe/src/Composer/Installers/BaseInstaller.php#L116-L119

Predictably, this causes a crash:

PHP Fatal error:  Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, string given in  /webflo/drupal-finder/src/DrupalFinder.php:113
Stack trace:
#0 webflo/drupal-finder/src/DrupalFinder.php(113): in_array('type:drupal-cor...', 'a-module-name-im-using...')

Whether to follow upstream or not, it would be best to avoid the crash since strings instead of arrays is "not wrong" (?).

1.2.x doesn't work with drupal/recommended-project ?

Hi and thank you very much for this great project!

I recently switched composer.json's to https://github.com/drupal/recommended-project as described here and therefor upgraded from drupal-finder:1.1.0 to drupal-finder:1.2.2. Now all compatible drush versions (8/9/10) are unable to find the Drupal root.

! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.

I wasn't even able to set the root via parameter or any other workaround. 1.1.0 isn't compatible with drupal/recommended-project so I guess this is a critical issue?

Or what am I doing wrong?

Thank you very much for your help and time!

Here's my composer.json:

{
"name": "drupal/recommended-project",
"description": "Project template for Drupal 8 projects with a relocated document root",
"type": "project",
"license": "GPL-2.0-or-later",
"homepage": "https://www.drupal.org/project/drupal",
"support": {
"docs": "https://www.drupal.org/docs/user_guide/en/index.html",
"chat": "https://www.drupal.org/node/314178"
},
"require": {
"composer/installers": "^1.9",
"cweagans/composer-patches": "^1.6.5",
"desandro/imagesloaded": "^4.1",
"desandro/masonry": "^4.2",
"drupal/addanother": "^1.0",
"drupal/address": "^1.3",
"drupal/admin_toolbar": "^2.0",
"drupal/antibot": "^1.3",
"drupal/backup_migrate": "^5.0@rc",
"drupal/blazy": "^2.0@rc",
"drupal/block_component_library": "^1.2",
"drupal/captcha": "^1.0",
"drupal/ckeditorheight": "^1.2",
"drupal/codemirror_editor": "^1.0",
"drupal/config_update": "^1.3",
"drupal/console": "~1.0",
"drupal/cookie_content_blocker": "^1.5",
"drupal/core-composer-scaffold": "^8.9",
"drupal/core-recommended": "^8.9",
"drupal/crop": "2.x-dev@dev",
"drupal/ctools": "^3.0",
"drupal/devel": "^4.0",
"drupal/devel_debug_log": "^1.0",
"drupal/devel_php": "^1.3",
"drupal/dropdown_language": "^2.6",
"drupal/dropzonejs": "^2.1",
"drupal/drowl_admin": "^2.0",
"drupal/drowl_admin_dashboard": "^1.0@alpha",
"drupal/drowl_header_slides": "^3.0",
"drupal/drowl_layouts": "^2.0@beta",
"drupal/drowl_media": "^2.0@beta",
"drupal/drowl_paragraphs": "^3.8",
"drupal/dynamic_entity_reference": "^1.4",
"drupal/editor_advanced_link": "^1.3",
"drupal/embed": "^1.0",
"drupal/entity_browser": "^2.1",
"drupal/entity_embed": "^1.0",
"drupal/entity_reference_display": "^1.1",
"drupal/entity_reference_layout": "^1.0@alpha",
"drupal/entity_reference_revisions": "^1.4",
"drupal/eu_cookie_compliance": "1.x-dev@dev",
"drupal/eva": "^2.0@rc",
"drupal/features": "^3.5",
"drupal/fences": "2.x-dev#ed9aed6",
"drupal/fences_block": "^1.0@beta",
"drupal/field_formatter": "^2.0",
"drupal/field_group": "^3.0",
"drupal/field_tools": "^1.0",
"drupal/flood_unblock": "^3.0",
"drupal/focal_point": "^1.0",
"drupal/foundation_anchor_menu_block": "^1.1",
"drupal/foundation_sites": "^1.0@RC",
"drupal/ga": "^1.4",
"drupal/genpass": "^1.0",
"drupal/honeypot": "^2.0",
"drupal/image_resize_filter": "1.x-dev",
"drupal/improve_line_breaks_filter": "^1.1",
"drupal/inline_entity_form": "^1.0@rc",
"drupal/ip_anon": "^1.2",
"drupal/layout_disable": "^1.0",
"drupal/libraries": "^3.0",
"drupal/link_attributes": "^1.0",
"drupal/linkit": "^6.0@beta",
"drupal/login_security": "^2.0",
"drupal/mailsystem": "^4.1",
"drupal/media_entity": "2.x-dev@dev",
"drupal/media_entity_actions": "^1.0@alpha",
"drupal/media_entity_browser": "^2.0",
"drupal/media_entity_document": "1.x-dev@dev",
"drupal/media_entity_download": "^2.0@beta",
"drupal/media_entity_generic": "^1.0",
"drupal/media_entity_image": "^1.3",
"drupal/media_entity_image_exif": "1.x-dev@dev",
"drupal/media_entity_instagram": "2.x-dev@dev",
"drupal/media_entity_slideshow": "^2.0@alpha",
"drupal/media_entity_twitter": "^2.0@alpha",
"drupal/menu_block": "^1.6",
"drupal/menu_force": "^1.0",
"drupal/menu_item_extras": "^2.3",
"drupal/metatag": "^1.5",
"drupal/micon": "^1.5",
"drupal/page_manager": "4.x-dev@dev",
"drupal/paragraphs": "^1.9",
"drupal/pathauto": "^1.6",
"drupal/perimeter": "^1.0@alpha",
"drupal/permissions_dragcheck": "^1.1",
"drupal/photoswipe": "^3.0@alpha",
"drupal/quick_node_clone": "^1.12",
"drupal/rabbit_hole": "^1.0@beta",
"drupal/rabbit_hole_href": "^2.0",
"drupal/readmore_extrafield": "^3.0",
"drupal/redirect": "^1.2",
"drupal/reroute_email": "^1.2",
"drupal/responsive_background_image": "^1.0@alpha",
"drupal/responsive_favicons": "^1.4",
"drupal/scheduler": "^1.1",
"drupal/search404": "^2.0",
"drupal/search_api": "^1.10",
"drupal/search_api_page": "^1.0@alpha",
"drupal/security_review": "1.x-dev",
"drupal/shield": "1.x-dev@dev",
"drupal/simple_megamenu": "^1.0@beta",
"drupal/simple_megamenu_bonus": "^1.0@alpha",
"drupal/simple_sitemap": "^3.0@rc",
"drupal/simplei": "^1.2",
"drupal/simplify": "^1.0",
"drupal/site_settings": "^1.19",
"drupal/sitemap": "^2.0@beta",
"drupal/slick": "^2.2",
"drupal/slick_entityreference": "^2.0",
"drupal/slick_paragraphs": "^2.0",
"drupal/slick_views": "^2.0",
"drupal/smart_trim": "^1.1",
"drupal/spamspan": "^1.0",
"drupal/svg_image": "^1.9",
"drupal/swiftmailer": "^2.0@alpha",
"drupal/token": "^1.1",
"drupal/token_custom": "^1.0",
"drupal/token_filter": "^1.0",
"drupal/twig_field_value": "^2.0",
"drupal/twig_tweak": "^2.0",
"drupal/unset_html_head_link": "^1.0",
"drupal/upgrade_status": "^3.0",
"drupal/user_current_paths": "^2.0",
"drupal/user_permission_condition": "1.x-dev",
"drupal/video_embed_field": "^2.0",
"drupal/video_embed_html5": "^1.1",
"drupal/view_modes_display": "^2.3",
"drupal/views_accordion_foundation": "^2.0",
"drupal/views_bulk_edit": "^2.0",
"drupal/views_bulk_operations": "^3.2",
"drupal/views_linkarea": "^1.0@beta",
"drupal/views_menu_children_filter": "^1.0",
"drupal/viewsreference": "^2.0",
"drupal/webform": "^5.0",
"drupal/zurb_foundation": "^6.0@alpha",
"drush/drush": "^10.0",
"joachim-n/composer-manifest": "^1.1",
"kenwheeler/slick": "dev-master-patched",
"npm-asset/ckeditor-autogrow": "^1.0",
"npm-asset/codemirror": "^5.42",
"npm-asset/drag-check-js": "^2.0",
"npm-asset/dropzone": "^5.7",
"npm-asset/exif-js": "~2.3",
"npm-asset/font-awesome": "^4.7.0",
"npm-asset/photoswipe": "^4.1",
"npm-asset/verge": "^1.10",
"oomphinc/composer-installers-extender": "^2.0",
"tijsverkoyen/css-to-inline-styles": "^2.2",
"vardot/blazy": "^1.8"
},
"require-dev": {
"drupal/core-dev": "^8.9",
"szeidler/composer-patches-cli": "^1.0"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"platform": {
"php": "7.3.24"
}
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"composer-exit-on-patch-failure": true,
"enable-patching": true,
"patchLevel": {
"drupal/core": "-p2"
},
"patches": {
"drupal/video_embed_field": {
"Provide a URL field formatter (#2879932)": "https://www.drupal.org/files/issues/2018-12-18/video_embed_field-url-formatter-2879932-18.patch"
},
"drupal/fences": {
"Add optional wrapper around field items and correct class structure (#1343578)": "https://www.drupal.org/files/issues/2019-08-08/fences_8.x-3.x_add_items_wrapper__3018654-based__1343578-54.patch"
},
"drupal/micon": {
"https://www.drupal.org/files/issues/2018-08-16/micon-2950435-2replace-tags-with-name.patch": "https://www.drupal.org/files/issues/2018-08-16/micon-2950435-2replace-tags-with-name.patch"
},
"drupal/site_settings": {
"[DIRTY HACK, REMOVE ASAP:] How to get rendered value of Site Settings formatted text field in token (#2943440)": "https://www.drupal.org/files/issues/2019-07-23/site_settings_text_format_rendered_quickfix-2943440-11.patch"
},
"drupal/ga": {
"[GDPR:] COMBINED: Integration with EU Cookie Compliance module and DNT #3011324-8 + gaOptout() (#3073077-6)": "https://www.drupal.org/files/issues/2019-08-07/ga_optout-combined-eu_cookie_compliance-3073077-3011324-6.patch"
},
"drupal/cookie_content_blocker": {
"Add comparison for cookie does NOT contain or cookie does not exist (#3153845)": "https://www.drupal.org/files/issues/2020-09-11/not_exists_or_not_contains_operators-3153845-5.patch"
},
"drupal/eu_cookie_compliance": {
"[GDPR:] Option to place Withdraw Button anywhere on site (e.g. in block) (#2985390)": "https://git.drupalcode.org/issue/eu_cookie_compliance-2985390/-/commit/d95c84df4376ebd537150f41d305b0410a7da405.patch"
},
"drupal/rabbit_hole": {
"Required only for rabbit_hole_href: #3095653: Split performAction() into submethods in PageRedirect Behaviour": "https://www.drupal.org/files/issues/2019-11-21/3095653-5.patch"
},
"drupal/entity_browser": {
"Add Modal Class, Remove term entity from title, adjust width (#3112356)": "https://www.drupal.org/files/issues/2020-02-10/3112356-fix-modal-dialog.patch"
},
"drupal/core": {
"[8.8 RTBC Views] Cannot use relationship for rendered entity on Views (#2457999)": "https://www.drupal.org/files/issues/2020-05-30/cannot-use-relationship-2457999-236.patch",
"Localization update feature logs 404 errors too agressively (#2879998)": "https://www.drupal.org/files/issues/2018-05-04/locale-add_ignore_404_option-2879998-9.patch",
"[Layout-Builder] Error: Call to a member function getLabel() after enable layout_builder with media in core (#2985882)": "https://www.drupal.org/files/issues/2020-04-08/2985882-field-85.patch",
"[Layout-Builder] Callers of LayoutEntityHelperTrait::getEntitySections() do not account for the view mode - InvalidArgumentException: Invalid UUID (#3008924)": "https://www.drupal.org/files/issues/2019-06-20/3008924-5.patch",
"[Token] Add a token for the site logo (#2842780)": "https://www.drupal.org/files/issues/2019-07-12/2842780-110.patch",
"[Layout-Builder] Layout builders use of sample data can cause exceptions during rendering of default entity view displays (#3069001)": "https://www.drupal.org/files/issues/2019-07-19/3069001-force-placeholders-sample-data-field-blocks.patch",
"Drupal.views.ajaxView is not initializing pagers in nested views": "https://www.drupal.org/files/issues/2019-11-14/2858890-43.patch"
},
"drupal/slick": {
"Add option to wrap slick field markup into field.html.twig (#3134342)": "https://www.drupal.org/files/issues/2020-05-07/slick_entityreference-3134342-19.patch"
},
"drupal/captcha": {
"Fix Image CAPTCHA settings form (#2501699)": "https://www.drupal.org/files/issues/2020-02-03/2501699-38.patch"
},
"drupal/entity_reference_layout": {
"Element selection is broken - missing paragraph thumbnails (#3134453)": "https://www.drupal.org/files/issues/2020-06-10/3134453-get-paragraph-icon-url-5.patch"
}
},
"installer-types": [
"npm-asset",
"bower-asset"
],
"installer-paths": {
"web/core": [
"type:drupal-core"
],
"web/modules/contrib/{$name}": [
"type:drupal-module"
],
"web/modules/custom/{$name}": [
"type:drupal-custom-module"
],
"web/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"web/themes/contrib/{$name}": [
"type:drupal-theme"
],
"web/themes/custom/{$name}": [
"type:drupal-custom-theme"
],
"web/libraries/{$name}": [
"type:npm-asset",
"type:bower-asset",
"type:drupal-library"
],
"drush/Commands/contrib/{$name}": [
"type:drupal-drush"
],
"web/libraries/ckeditor/plugins/{$name}": [
"vendor:ckeditor-plugin"
]
},
"_require-candidates": {
"drupal/markup": "^1.0",
"drupal/markup_twig": "^1.0",
"drupal/menu_multilingual": "1.x-dev@dev",
"drupal/revision_log_default": "^1.0",
"drupal/recaptcha": "^2.3"
},
"_require-dev-candidates": {
"sensiolabs/security-checker": "~4.0"
},
"_patch-candidates": {
"drupal/officialfacebookpixel": {
"[GDPR:] Settings, GDPR and CSP by libraries": "https://www.drupal.org/files/issues/2019-08-07/official_facebook_pixel-settings_csp_gdpr_8.x-2.x-candidate-3073070-2.patch"
},
"drupal/cookiebot": {
"Blockmode Auto will not work in Drupal 8 with core's domready library (#3091260-30)": "https://www.drupal.org/files/issues/2020-01-29/cookiebot-attach_behaviors-3091260-30.patch"
},
"drupal/php": {
"Text format with system name php_code is deleted when you view admin/modules/uninstall (#3016061)": "https://www.drupal.org/files/issues/2019-01-04/php-remove_filter_validator_uninstall-3016061-21.patch"
},
"drupal/views_infinite_scroll": {
"After update to Drupal 8.4 VIC replace results instead of appending, requires drupal/core: #2858890 (#2918352-19)": "https://www.drupal.org/files/issues/2020-06-29/filter-nested-views-2918352-19.patch"
}
}
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "composer",
"url": "https://asset-packagist.org"
},
{
"type": "package",
"package": {
"name": "kenwheeler/slick",
"version": "dev-master-patched",
"type": "drupal-library",
"_readme": "!! PATCHED !! We're using the patch from here https://github.com/kenwheeler/slick/pull/3674/commits/2a68c0bf58026d66838f9656d93527046646b4fb Without this patch Slick removes all events from subelements, e.g. photoswipe images within Slick.",
"dist": {
"url": "https://github.com/webksde/slick/archive/patch-1.zip",
"type": "zip"
}
}
}
]
}

getDrupalRoot fails for Drupal 7 project

I did not find any information this project is limited to Drupal 8, but it fails when I try it against https://github.com/drupal-composer/drupal-project/tree/7.x.

When I use it with D7 projects \DrupalFinder\DrupalFinder::getDrupalRoot(); returns /var/www/html/dr for core located in /var/www/html/drupal/

This part causes problems:
https://github.com/webflo/drupal-finder/blob/master/src/DrupalFinder.php#L110-L114

Do you have plans to add D7 support? Are you willing to accept eventual PR adding D7 support?

Support non-composer D7 installs

While in a D7 root directory, I can't use drush launcher because it does not recognize a Drupal installation.

project/www $ drush --version
Drush Launcher Version: 0.5.1
The Drush launcher could not find a Drupal site to operate on. Please do *one* of the following:
  - Navigate to any where within your Drupal project and try again.
  - Add --root=/path/to/drupal so Drush knows where your site is located.
project/www $ drush --root=. --version
Drush Launcher Version: 0.5.1
The Drush launcher could not find a Drupal site to operate on. Please do *one* of the following:
  - Navigate to any where within your Drupal project and try again.
  - Add --root=/path/to/drupal so Drush knows where your site is located.

My D7 is not installed via composer (5 years old project).
It is in a www folder, at the same level of the composer.json that's used to require drush 8.

project $ tree -L 2 .
.
├── composer.json
├── composer.lock
├── drush
│   └── contrib
├── README.md
├── scripts
│   └── [...]
├── vendor
│   ├── autoload.php
│   ├── bin
│   ├── [...]
│   ├── drush
│   └── [...]
└── www
    └── [Drupal root]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.