From 651f1f13af563dfdd9e9d5ff9af94993af9a91af Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Mon, 10 Jul 2017 13:59:00 +1200 Subject: [PATCH] BUG Fix recipes not being un-installed after inlining Improve format of output logging --- src/RecipeCommandBehaviour.php | 5 ++++- src/RecipeInstaller.php | 28 ++++++++++++++++++++++------ src/RecipePlugin.php | 1 + 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/RecipeCommandBehaviour.php b/src/RecipeCommandBehaviour.php index 017d28f..aeabd09 100644 --- a/src/RecipeCommandBehaviour.php +++ b/src/RecipeCommandBehaviour.php @@ -74,6 +74,9 @@ trait RecipeCommandBehaviour throw new InvalidArgumentException("Invalid composer.json data with error: " . json_last_error_msg()); } file_put_contents($path, $content); + + // Reset composer object + $this->resetComposer(); } /** @@ -235,7 +238,7 @@ trait RecipeCommandBehaviour foreach ($installedRecipe->getRequires() as $requireName => $require) { $requireVersion = $require->getPrettyConstraint(); $output->writeln( - " * Inline dependency {$requireName} as {$requireVersion}" + " - Inlining {$requireName} ({$requireVersion})" ); $composerData['require'][$requireName] = $requireVersion; } diff --git a/src/RecipeInstaller.php b/src/RecipeInstaller.php index b679ce7..b0fc018 100644 --- a/src/RecipeInstaller.php +++ b/src/RecipeInstaller.php @@ -29,17 +29,33 @@ class RecipeInstaller extends LibraryInstaller { protected function installProjectFiles($recipe, $sourceRoot, $destinationRoot, $filePatterns) { $fileIterator = $this->getFileIterator($sourceRoot, $filePatterns); + $any = false; foreach($fileIterator as $path => $info) { $relativePath = substr($path, strlen($sourceRoot)); $destination = $destinationRoot . $relativePath; - // Only copy non-existent files - if (file_exists($destination)) { - continue; + // Write header + if (!$any) { + $this->io->write("Installing project files for recipe {$recipe}:"); + $any = true; + } + + // Check if file exists + if (file_exists($destination)) { + if (file_get_contents($destination) === file_get_contents($path)) { + $this->io->write( + " - Skipping $relativePath (existing, but unchanged)" + ); + } else { + $this->io->write( + " - Skipping $relativePath (existing and modified in project)" + ); + } + } else { + $this->io->write(" - Installing $relativePath"); + $this->filesystem->ensureDirectoryExists(dirname($destination)); + copy($path, $destination); } - $this->io->write("Installing recipe $recipe file $relativePath"); - $this->filesystem->ensureDirectoryExists(dirname($destination)); - copy($path, $destination); } } diff --git a/src/RecipePlugin.php b/src/RecipePlugin.php index addc2cd..22df895 100644 --- a/src/RecipePlugin.php +++ b/src/RecipePlugin.php @@ -28,6 +28,7 @@ class RecipePlugin implements PluginInterface, EventSubscriberInterface, Capable public static function getSubscribedEvents() { return [ + 'post-package-update' => 'installPackage', 'post-package-install' => 'installPackage', ]; }