From 51ba915751a8bc76854478c4fb198150bf183d1f Mon Sep 17 00:00:00 2001 From: Andrew Paxley Date: Mon, 2 May 2022 17:14:41 +1200 Subject: [PATCH] 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; }