From 5f46ff2ad6ccb14f73f79f2828bbea8dd30ed9a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Mon, 24 Dec 2018 13:23:53 +0100 Subject: [PATCH] Fix: Reset composer and update using --working-dir option when necessary --- CHANGELOG.md | 4 ++++ src/Command/NormalizeCommand.php | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54a9d391..9c26471a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,10 @@ For a full diff see [`0.9.0...1.0.0`](https://github.com/localheinz/composer-nor * Added this changelog ([#94](https://github.com/localheinz/composer-normalize/pull/94)), by [@localheinz](https://github.com/localheinz) +#### Fixed + +* Force reading `composer.json` and `composer.lock` after normalization to ensure `composer.lock` is updated when not fresh after normalization ([#139](https://github.com/localheinz/composer-normalize/pull/139)), by [@localheinz](https://github.com/localheinz) + #### Removed * Removed normalizers after extracting package [`localheinz/composer-json-normalizer`](https://github.com/localheinz/composer-json-normalizer) ([#106](https://github.com/localheinz/composer-normalize/pull/106)), by [@localheinz](https://github.com/localheinz) diff --git a/src/Command/NormalizeCommand.php b/src/Command/NormalizeCommand.php index 0eb55aa6..69ea6e7e 100644 --- a/src/Command/NormalizeCommand.php +++ b/src/Command/NormalizeCommand.php @@ -238,6 +238,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O if (false === $noUpdateLock && true === $locker->isLocked()) { $io->write('Updating lock file.'); + $this->resetComposer(); + + $file = $input->getArgument('file'); + + if (\is_string($file)) { + return $this->updateLockerInWorkingDirectory( + $output, + \dirname($file) + ); + } + return $this->updateLocker($output); } @@ -380,4 +391,30 @@ private function updateLocker(Console\Output\OutputInterface $output): int $output ); } + + /** + * @see https://getcomposer.org/doc/03-cli.md#update + * + * @param Console\Output\OutputInterface $output + * @param string $workingDirectory + * + * @throws \Exception + * + * @return int + */ + private function updateLockerInWorkingDirectory(Console\Output\OutputInterface $output, string $workingDirectory): int + { + return $this->getApplication()->run( + new Console\Input\ArrayInput([ + 'command' => 'update', + '--lock' => true, + '--no-autoloader' => true, + '--no-plugins' => true, + '--no-scripts' => true, + '--no-suggest' => true, + '--working-dir' => $workingDirectory, + ]), + $output + ); + } }