From 8dc6fd42f8b414e169f97c05d33c9974606e1307 Mon Sep 17 00:00:00 2001 From: Karoun Kasraie Date: Mon, 25 Jun 2018 13:27:28 -0700 Subject: [PATCH] [TEMP] Supporting our vendor/ structure --- src/ComposerPlugin.php | 6 ++++-- src/builders/RootImporter.php | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ComposerPlugin.php b/src/ComposerPlugin.php index 457fa00..9fca05a 100644 --- a/src/ComposerPlugin.php +++ b/src/ComposerPlugin.php @@ -30,7 +30,8 @@ public function activate(Composer $composer, IOInterface $io) { $vendor = $composer->getConfig()->get('vendor-dir', '/'); $this->vendor = $vendor; - $this->root = dirname($vendor); + // TODO: Remove this hard-coded path in favor of config + $this->root = dirname(dirname($vendor)); } public static function getSubscribedEvents() { @@ -55,7 +56,8 @@ public function onPostAutoloadDump(Event $event) { $this->root, $event->isDevMode() ? IncludedRoots::DEV_AND_PROD - : IncludedRoots::PROD_ONLY + : IncludedRoots::PROD_ONLY, + $this->vendor ); $handler = $event->isDevMode() diff --git a/src/builders/RootImporter.php b/src/builders/RootImporter.php index 6dcb539..3fb4006 100644 --- a/src/builders/RootImporter.php +++ b/src/builders/RootImporter.php @@ -18,6 +18,7 @@ final class RootImporter implements Builder { public function __construct( string $root, IncludedRoots $included = IncludedRoots::PROD_ONLY, + ?string $vendor = null, ) { $this->hh_importer = new HHImporter($root, $included); $this->builders[] = $this->hh_importer; @@ -27,15 +28,17 @@ public function __construct( return; } - foreach (glob($root.'/vendor/*/*/') as $dependency) { - if (file_exists($dependency.'/hh_autoload.json')) { + $vendor = $vendor ?? $root.'/vendor'; + + foreach (glob($vendor.'/*/*/', GLOB_ONLYDIR | GLOB_MARK) as $dependency) { + if (file_exists($dependency.'hh_autoload.json')) { $this->builders[] = new HHImporter( $dependency, IncludedRoots::PROD_ONLY, ); continue; } - $composer_json = $dependency.'/composer.json'; + $composer_json = $dependency.'composer.json'; if (file_exists($composer_json)) { $this->builders[] = new ComposerImporter($composer_json, $config); continue;