Skip to content

Commit

Permalink
Fix: Reset composer and update using --working-dir option when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 24, 2018
1 parent 543bb46 commit 5f46ff2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 additions & 0 deletions src/Command/NormalizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,17 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
if (false === $noUpdateLock && true === $locker->isLocked()) {
$io->write('<info>Updating lock file.</info>');

$this->resetComposer();

$file = $input->getArgument('file');

if (\is_string($file)) {
return $this->updateLockerInWorkingDirectory(
$output,
\dirname($file)
);
}

return $this->updateLocker($output);
}

Expand Down Expand Up @@ -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
);
}
}

0 comments on commit 5f46ff2

Please sign in to comment.