Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Archive this project? #105

Open
weitzman opened this issue Jun 2, 2023 · 4 comments
Open

Archive this project? #105

weitzman opened this issue Jun 2, 2023 · 4 comments

Comments

@weitzman
Copy link
Member

weitzman commented Jun 2, 2023

IMO this project has lived its useful life and should be archived. In its place we promote the alternatives listed in the README.

Add /path/to/vendor/bin to the front of your $PATH. This is trivial when you have only one Drupal codebase on your system (e.g. site is in Docker). When your system has multiple codebases, consider using direnv to add to $PATH on a per-codebase basis. An example .envrc file.

This project is not up to date with Drush 12 and its not clear how to make it so.

  1. This project uses webflo/drupal-finder to find a Drupal site. Drush no longer uses that, in favor of Composer Runtime API. drupal-finder requires adding paths to composer.json.extra to locate DrupalRoot - Drush doesn't need that. This discrepancy will likely cause issues in both launcher and drush projects.
  2. This project attempts to get the Drush version from drush.info. That file is removed in Drush 12 in favor of Composer Runtime API
  3. Drush 12 uses the new composer bin proxy file to accurately provide its autoloader and vendor/bin locations. This project bypasses vendor/bin/drush and instead calls drush_main() directly. So Drush has to guess these paths for Launcher users.

I'm inclined to throw an Exception in drush_main() in Drush 12 to indicate that Launcher is incompatible.

@chx
Copy link

chx commented Jul 5, 2023

Add

function drush () {
        $(git rev-parse --show-toplevel)/vendor/bin/drush "$@"
}

to your favorite bash/zsh configuration. It will do as long as your vendor dir is always at git top level which is fairly typical. You can of course make a more elaborate finder out of this:

function drush () {
        top=$(git rev-parse --show-toplevel)
        vendor=$(jq -r '.config["vendor-dir"] // "vendor"' < $top/composer.json)
        $top/$vendor/bin/drush "$@"
}

@gagathos
Copy link

We have some environments where we strip our git information after deployment, so @chx functions won't work. However, we were able to have some results with the following:

function drush() {
  # Start at the current directory
  dir=$PWD

  # While not at the root (/)
  while [[ "$dir" != "/" ]]; do
    # If vendor/bin/drush exists, run it
    if [[ -x "$dir/vendor/bin/drush" ]]; then
      "$dir/vendor/bin/drush" "$@"
      return
    fi
    # Go up one directory level
    dir=$(dirname "$dir")
  done

  echo "Could not find drush in any parent directory."
}

@dasginganinja
Copy link

dasginganinja commented Jul 18, 2023

I built off of @gagathos solution and made it replace our existing Drush commands 👍 🥇

Note: This does have issues with -- arguments, such as --version.

Place the file somewhere in your path (for us it was /usr/local/bin/drush to replace drush-global-launcher).

The drush command at the end of the script will pass the variables sent to the script to drush. Voila! We can finally write this off internally now.

#!/bin/bash -u

function drush() {
  local root_dir=''

  # Parse options
  while getopts "r:" opt; do
    case $opt in
      r)
        root_dir=$OPTARG
        ;;
      \?)
        echo "Invalid option: -$OPTARG" >&2
        return 1
        ;;
    esac
  done

  shift $((OPTIND - 1))

  # Start at the current directory or the specified root directory
  if [[ -n "$root_dir" ]]; then
    dir="$root_dir"
  else
    dir=$PWD
  fi

  # While not at the root (/)
  while [[ "$dir" != "/" ]]; do
    # If vendor/bin/drush exists, run it
    if [[ -x "$dir/vendor/bin/drush" ]]; then
      "$dir/vendor/bin/drush" "$@"
      return
    fi
    # Go up one directory level
    dir=$(dirname "$dir")
  done

  echo "Could not find drush in any parent directory."
  return 1
}

drush "$@"

We had so many issues trying to keep this just as a function. We had so many cases where this was failing that we just put the file back in place of the original and made it do what we assumed was the same thing.

Edit: For the time being we're going back to Drush 11 and Drush Global Launcher.

@dasginganinja
Copy link

I decided that bash-based solution wasn't good enough so I went and learned Go.
I have a release on Github for a replacement for this project if anybody is interested in testing:
https://github.com/dasginganinja/drush-launcher

I needed a plan for Drush 12. 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants