From 4da2061af0fb9e8da24215ed174896d5d8f4eb04 Mon Sep 17 00:00:00 2001 From: Marco Cesarato Date: Thu, 15 Apr 2021 10:06:47 +0200 Subject: [PATCH] fix(bump): add lock files to commit Ref: #11 --- src/Bump/ComposerJson.php | 4 ++++ src/Bump/PackageJson.php | 4 ++++ src/Changelog.php | 2 ++ src/Type/Bump.php | 31 +++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/src/Bump/ComposerJson.php b/src/Bump/ComposerJson.php index 3159d8a..8757d75 100644 --- a/src/Bump/ComposerJson.php +++ b/src/Bump/ComposerJson.php @@ -11,6 +11,10 @@ class ComposerJson extends Bump * {@inheritdoc} */ protected $fileName = 'composer.json'; + /** + * {@inheritdoc} + */ + protected $lockFiles = ['composer.lock']; /** * {@inheritdoc} */ diff --git a/src/Bump/PackageJson.php b/src/Bump/PackageJson.php index 7dec1da..0e53663 100644 --- a/src/Bump/PackageJson.php +++ b/src/Bump/PackageJson.php @@ -10,6 +10,10 @@ class PackageJson extends Bump * {@inheritdoc} */ protected $fileName = 'package.json'; + /** + * {@inheritdoc} + */ + protected $lockFiles = ['package.lock', 'yarn.lock', 'pnpm-lock.yaml']; /** * {@inheritdoc} */ diff --git a/src/Changelog.php b/src/Changelog.php index d19d1b2..d273739 100644 --- a/src/Changelog.php +++ b/src/Changelog.php @@ -385,11 +385,13 @@ public function generate(InputInterface $input, SymfonyStyle $output): int $bumper->setVersion($newVersion); $bumper->save(); $filesToCommit[] = $bumper->getFilePath(); + $filesToCommit = array_merge($filesToCommit, $bumper->getExistingLockFiles()); } } catch (Exception $e) { $output->error('An error occurred bumping package version: ' . $e->getMessage()); } } + $filesToCommit = array_unique($filesToCommit); } // Print summary diff --git a/src/Type/Bump.php b/src/Type/Bump.php index f98150c..f9e6d28 100644 --- a/src/Type/Bump.php +++ b/src/Type/Bump.php @@ -12,6 +12,12 @@ abstract class Bump * @var string */ protected $fileName; + /** + * Package lock files. + * + * @var array + */ + protected $lockFiles; /** * Package file type. * @@ -108,6 +114,31 @@ public function getFileName(): string return $this->fileName; } + /** + * Get all existing lock files. + */ + public function getExistingLockFiles(): array + { + $paths = []; + foreach ($this->lockFiles as $lockFile) { + $path = $this->getPath() . DIRECTORY_SEPARATOR . $lockFile; + $path = preg_replace('/' . preg_quote(DIRECTORY_SEPARATOR, '/') . '+/', DIRECTORY_SEPARATOR, $path); + if (is_file($path)) { + $paths[] = $path; + } + } + + return $paths; + } + + /** + * Get lock file name. + */ + public function getLockFiles(): array + { + return $this->lockFiles; + } + /** * Package file exists. */