webflo / drupal-finder

GNU General Public License v2.0
125 stars 27 forks source link

Support non-composer D7 installs #35

Open DuaelFr opened 6 years ago

DuaelFr commented 6 years ago

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]
webflo commented 6 years ago

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

DuaelFr commented 6 years ago

Sure! Prepare to be stunned ;)

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

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

webflo commented 6 years ago

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 commented 6 years ago

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

DuaelFr commented 6 years ago

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

markusd1984 commented 6 years ago

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

DuaelFr commented 6 years ago

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.

capynet commented 6 years ago

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"
      ]
    }
  }
}
wdseelig commented 5 years ago

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?

leymannx commented 5 years ago

@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.

capynet commented 5 years ago

@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.

vickyhawley commented 3 years ago

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!