FIX Only write composer.json if there are changes (#21)

FIX Only write composer.json if there are changes
This commit is contained in:
Andrew Paxley 2022-05-10 09:40:14 +12:00 committed by GitHub
parent 8a77da94d1
commit 301daf2437
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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 <info>$relativePath</info>");
$this->filesystem->ensureDirectoryExists(dirname($destination ?? ''));
copy($sourcePath ?? '', $destination ?? '');
$this->hasWrittenFiles = true;
}
return $relativePath;
}