From 13166fcf2b9fcd66763716d8ca0b78419e582fa2 Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 14 Mar 2017 16:46:49 -0400 Subject: [PATCH] Adding validation for installers-path. --- src/Composer/Plugin.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Composer/Plugin.php b/src/Composer/Plugin.php index 6554f9de0..c2bf0e833 100644 --- a/src/Composer/Plugin.php +++ b/src/Composer/Plugin.php @@ -68,10 +68,37 @@ public static function getSubscribedEvents() { return array( PackageEvents::POST_PACKAGE_INSTALL => "onPostPackageEvent", PackageEvents::POST_PACKAGE_UPDATE => "onPostPackageEvent", + ScriptEvents::PRE_INSTALL_CMD => 'checkInstallerPaths', ScriptEvents::POST_UPDATE_CMD => 'onPostCmdEvent', ); } + /** + * Verify that composer.json contains correct values for installer-paths. + * + * Unfortunately, these values cannot be placed in composer.include.json. + * + * @see https://github.com/wikimedia/composer-merge-plugin/issues/139 + * + * @param \Composer\Script\Event $event + */ + public function checkInstallerPaths(Event $event) { + $extra = $this->composer->getPackage()->getExtra(); + if (empty($extra['installer-paths'])) { + $this->io->write('Error: extras.installer-paths is missing from your composer.json file.'); + } + else { + $composer_include_json_filename = $this->getVendorPath() . '/acquia/blt/template/composer.json'; + if (file_exists($composer_include_json_filename)) { + $composer_include_json = json_decode(file_get_contents($composer_include_json_filename), TRUE); + if ($composer_include_json['extra']['installer-paths'] != $extra['installer-paths']) { + $this->io->write('Warning: The value for extras.installer-paths in composer.json differs from BLT\'s recommended values.'); + $this->io->write('See https://github.com/acquia/blt/blob/8.x/template/composer.json'); + } + } + } + } + /** * Marks blt to be processed after an install or update command. * @@ -191,7 +218,6 @@ public function getVendorPath() { protected function getOptions() { $defaults = [ 'update' => TRUE, - 'composer-exclude-merge' => [], ]; $extra = $this->composer->getPackage()->getExtra() + ['blt' => []]; $extra['blt'] = $extra['blt'] + $defaults;