drupal-finder icon indicating copy to clipboard operation
drupal-finder copied to clipboard

Support non-composer D7 installs

Open DuaelFr opened this issue 7 years ago • 12 comments

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]

DuaelFr avatar Feb 01 '18 10:02 DuaelFr

@DuaelFr Could you post your composer.json as well?

webflo avatar Feb 01 '18 14:02 webflo

Sure! Prepare to be stunned ;)

$ cat composer.json 
{
    "require": {
        "drush/drush": "~8.0"
    }
}

(I told you it is not a project built with composer ^^)

DuaelFr avatar Feb 05 '18 10:02 DuaelFr

drupal-finder relies on the configuration for composer installers. You could try to make it work. If you configure these path accordingly to your structure. Even if you don't install drupal core via composer.

webflo avatar Feb 05 '18 11:02 webflo

https://github.com/webflo/drupal-finder/blob/master/src/DrupalFinder.php#L106

webflo avatar Feb 05 '18 11:02 webflo

It works, thanks! It would be great if it was documented, maybe in your readme? :)

DuaelFr avatar Feb 05 '18 11:02 DuaelFr

How did you make it work? Sorry for n00b question, which path did you put where @DuaelFr ?

I got the same issue on my D7 non-composer install :D

markusd1984 avatar Mar 07 '18 10:03 markusd1984

Here is my composer.json file. My drupal root is located in the www directory.

{
    "require": {
        "drush/drush": "~8.0"
    },
    "extra": {
        "installer-paths": {
            "www": ["type:drupal-core"],
            "www/sites/all/libraries/{$name}": ["type:drupal-library"],
            "www/sites/all/modules/contrib/{$name}": ["type:drupal-module"],
            "www/profiles/contrib/{$name}": ["type:drupal-profile"],
            "www/sites/all/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        }
    }
}

I suppose the only important line is the type:drupal-core one but I don't really know.

DuaelFr avatar Mar 07 '18 17:03 DuaelFr

Ok there you are. This is my working composer.json for D7 installations.

{
  "require": {
    "drush/drush": "~8.0",
    "webflo/drupal-finder": "^1.0.0"
  },
  "extra": {
    "installer-paths": {
      ".": [
        "type:drupal-core"
      ]
    }
  }
}

capynet avatar Jun 27 '18 15:06 capynet

Sorry to bother, but could you please point me to where I could learn how to use this composer.json to enable drush for my non-composer created vagrant D7 site? Where do I put his file, and what do I then to to run it and enable drush?

wdseelig avatar May 13 '19 19:05 wdseelig

@wdseelig – Seems off-topic to me, as this is the drupal-finder repo, not drush-launcher. But for what it's worth: It's absolutely not recommended (not supported) to use a local Drush in a non-Composer managed site. See https://github.com/drush-ops/drush-launcher/issues/33 (read until the end).

You are putting your site at risk doing it that way. Since running drush up for example can potentially delete your whole web directory (tracked or untracked files all gone).

Instead consider to Composerize your project using https://github.com/grasmash/composerize-drupal first.

normanlolx avatar May 14 '19 07:05 normanlolx

@wdseelig what's saying @leymannx have a lot of sense. I did this for a custom need so please keep this in mind.

In my example I just added a composer.json with the mentioned code inside at the D7 root dir and runned composer install.

capynet avatar May 14 '19 11:05 capynet

Hiya, I also had this issue, but I am being told to not use drush launcher by a colleague, so how do I get rid of drush launcher? sorry if this is a stupid question!

vickyhawley avatar Feb 19 '21 09:02 vickyhawley