wp-cli/wp-cli — pull request #618 by danielbachhuber (2013-07-28 04:17:42+00:00)
Title: Broken code to install community packages outside project root

I guess I need to put a non-exhausted brain on it, but here's how I see it:

* `~/.wp-cli/composer.json` is the root project which requires WP-CLI. Now that we've shipped this `composer.json`, we shouldn't put WP-CLI requirements in it — doing so would require users to update the file (manually or otherwise) outside the established `cd ~/.wp-cli/; composer update` workflow.
* We can, however, put declarations of community packages in `~/.wp-cli/composer.json`. Those are decided on a user-by-user basis, and can easily be managed by WP-CLI through `wp package install / uninstall`
* `~/.wp-cli/vendor/wp-cli/wp-cli/composer.json` defines WP-CLI's dependencies (e.g. php-cli-tools). This file is tracked in version control, and shouldn't ever be edited by the user. Any new dependencies will be declared in this file; user edits would conflict with `composer update`.

*However:*

* Because community packages are installed in the root project's `vendor`, they aren't included in `~/.wp-cli/vendor/wp-cli/wp-cli/vendor/autoload.php`.
* Community packages will require WP-CLI to be loaded first; most will have `WP_CLI::add_command(...`.
* `\WP_CLI\Utils\load_dependencies();` loads `~/.wp-cli/vendor/wp-cli/wp-cli/vendor/autoload.php` just fine.
* `\WP_CLI\Utils\load_dependencies();` *can't* require ` ~/.wp-cli/vendor/autoload.php`, as doing so loads php-cli-tools again.

Specifically, ` ~/.wp-cli/vendor/autoload.php` fatals with:

```
PHP Fatal error: Cannot redeclare cli\register_autoload() (previously declared in /home/vagrant/.wp-cli/vendor/wp-cli/wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/cli.php:20) in /home/vagrant/.wp-cli/vendor/wp-cli/php-cli-tools/lib/cli/cli.php on line 32
```

I suppose Composer is trying to be smart by installing php-cli-tools in the same namespace (install dir) as WP-CLI.

On top of all of this, once I accidentally reset the entire working directory, `composer update` in the root no longer installed the "composer/composer" requirement declared in `~/.wp-cli/vendor/wp-cli/wp-cli/composer.json`

What am I missing?

See https://github.com/wp-cli/wp-cli/pull/602#issuecomment-21674731