From 301daf2437c361fa983eae7e286b850ca06736ea Mon Sep 17 00:00:00 2001 From: Andrew Paxley Date: Tue, 10 May 2022 09:40:14 +1200 Subject: [PATCH] FIX Only write composer.json if there are changes (#21) FIX Only write composer.json if there are changes --- src/RecipeInstaller.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/RecipeInstaller.php b/src/RecipeInstaller.php index 5889094..10c918c 100644 --- a/src/RecipeInstaller.php +++ b/src/RecipeInstaller.php @@ -16,6 +16,10 @@ use RegexIterator; class RecipeInstaller extends LibraryInstaller { + /** + * @var bool + */ + private $hasWrittenFiles = false; public function __construct(IOInterface $io, Composer $composer) { @@ -67,13 +71,15 @@ class RecipeInstaller extends LibraryInstaller } // If any files are written, modify composer.json with newly installed files - if ($installedFiles) { + if ($this->hasWrittenFiles) { sort($installedFiles); if (!isset($composerData['extra'])) { $composerData['extra'] = []; } $composerData['extra'][$registrationKey] = $installedFiles; $composerFile->write($composerData); + // Reset the variable so that we can try this trick again later + $this->hasWrittenFiles = false; } } @@ -115,6 +121,7 @@ class RecipeInstaller extends LibraryInstaller $this->io->write(" - Copying $relativePath"); $this->filesystem->ensureDirectoryExists(dirname($destination ?? '')); copy($sourcePath ?? '', $destination ?? ''); + $this->hasWrittenFiles = true; } return $relativePath; }