Skip to content

Commit

Permalink
FIX Only write composer.json if there are changes (#21)
Browse files Browse the repository at this point in the history
FIX Only write composer.json if there are changes
  • Loading branch information
andrewandante authored May 9, 2022
1 parent 8a77da9 commit 301daf2
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/RecipeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

class RecipeInstaller extends LibraryInstaller
{
/**
* @var bool
*/
private $hasWrittenFiles = false;

public function __construct(IOInterface $io, Composer $composer)
{
Expand Down Expand Up @@ -67,13 +71,15 @@ protected function installProjectFiles(
}

// 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;
}
}

Expand Down Expand Up @@ -115,6 +121,7 @@ protected function installProjectFile($sourceRoot, $destinationRoot, $sourcePath
$this->io->write(" - Copying <info>$relativePath</info>");
$this->filesystem->ensureDirectoryExists(dirname($destination ?? ''));
copy($sourcePath ?? '', $destination ?? '');
$this->hasWrittenFiles = true;
}
return $relativePath;
}
Expand Down

0 comments on commit 301daf2

Please sign in to comment.