drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.33k stars 1.08k forks source link

Any alternatives of drush launcher for Drush 12 (drush command does not work with drush 12,instead we have to run drush command with vendor/bin/drush) #5825

Closed sananeyazi-voya closed 9 months ago

sananeyazi-voya commented 9 months ago

Describe the bug

We have Acquia/BLT basedDrupal 10 (10.0) site and usingDRUSH as a dependency in our site. We have to update the latest blt library (acquia/blt 13.7.4) which requires drush version 12. But when we run drush commands with drush12, we are getting below message

The Drush launcher could not find a local Drush in your Drupal site.
Please add Drush with Composer to your project.
Run 'cd "/var/www/html/drupal-platform" && composer require drush/drush'

So we have to run drush with vendor/bin/drush instead of only drush

Found few issues which states drush-launcher does not support by drush12 https://github.com/Islandora-Devops/isle-buildkit/pull/286 https://github.com/Islandora-Devops/isle-buildkit/issues/283 https://github.com/drush-ops/drush-launcher/issues/106

Also tried suggesstions given in above links, but nothing works in our case.

Can anyone please suggest any alternatives of drush-launcher or solution to fix this problem? Your help would be much appreciated

To Reproduce Install drupal 10.0 Install drush 12( with drush launcher) php 8.1 Run any command suppose 'drush cr'

Expected behavior Drush command should run without adding vendor/bin

System Configuration

| --------------- | --- | Drush version? | 12.4.3 | Drupal version? | 10.0.11 | PHP version | 8.1 | OS? | Linux

gitressa commented 9 months ago

I just tested this, and following this guide seems to work:

  1. Execution. Change your working directory to your project root, and call Drush via vendor/bin/drush. To make this easier, append ./vendor/bin to the end of your $PATH; this allows you to call Drush via drush once your working directory is set. If you only have only one Drupal codebase on your system, you may put /path/to/vendor/bin/drush in your $PATH; if you do this, then it is not necessary to set your working directory before calling Drush.

From https://www.drush.org/latest/install/.

This works well in my ~/.profile file, allowing me to use drush st:

# add Drush, see https://www.drush.org/latest/install/
PATH="./vendor/bin:$PATH"

I also tried with /path/to/vendor/bin/drush but that does not work ...

gitressa commented 9 months ago

Like I wrote, I tried the "run Drush from any folder" option, which never worked for me before. I realized it is due to a wrong path in the documentation, so I have created the merge request #5826, which fixes this.

YahyaAhmad commented 8 months ago

I made a fork which supports Drush 12 https://github.com/YahyaAhmad/drush-launcher Release https://github.com/YahyaAhmad/drush-launcher/releases/tag/0.10.3

gitressa commented 8 months ago

Thanks! Feel free to share it in #5828, where this is dicussed.

derjochenmeyer commented 6 months ago

PATH="./vendor/bin:$PATH"

This works but only in the root directory of the Drupal instance.

The following works in all sub directories.

function drush() {
    local dir=$(pwd)
    while [ "$dir" != "/" ]; do
        if [ -x "$dir/vendor/bin/drush" ]; then
            "$dir/vendor/bin/drush" "$@"
            return
        fi
        dir=$(dirname "$dir")
    done
    echo "Drush executable not found."
}

Test it with drush status