Skip to content

Commit

Permalink
Resolve directories for copy from recipe in update case
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Sep 26, 2022
1 parent ab0453b commit 7392a69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/Configurator/CopyFromRecipeConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,35 @@ public function unconfigure(Recipe $recipe, $config, Lock $lock)
public function update(RecipeUpdate $recipeUpdate, array $originalConfig, array $newConfig): void
{
foreach ($recipeUpdate->getOriginalRecipe()->getFiles() as $filename => $data) {
$filename = $this->resolveTargetFolder($filename, $originalConfig);
$recipeUpdate->setOriginalFile($filename, $data['contents']);
}

$files = [];
foreach ($recipeUpdate->getNewRecipe()->getFiles() as $filename => $data) {
$filename = $this->resolveTargetFolder($filename, $newConfig);
$recipeUpdate->setNewFile($filename, $data['contents']);

$files[] = $this->getLocalFilePath($recipeUpdate->getRootDir(), $filename);
}

$recipeUpdate->getLock()->add($recipeUpdate->getPackageName(), ['files' => $files]);
}

/**
* @param array<string, string> $config
*/
private function resolveTargetFolder(string $path, array $config): string
{
foreach ($config as $key => $target) {
if (0 === strpos($path, $key)) {
return $this->options->expandTargetDir($target).substr($path, \strlen($key));
}
}

return $path;
}

private function getRemovableFilesFromRecipeAndLock(Recipe $recipe, Lock $lock): array
{
$lockedFiles = array_unique(
Expand Down
2 changes: 1 addition & 1 deletion tests/Command/UpdateRecipesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private function createCommandUpdateRecipes(): CommandTester
$rfs = Factory::createRemoteFilesystem($this->io, $composer->getConfig());
$rfs = new ParallelDownloader($this->io, $composer->getConfig(), $rfs->getOptions(), $rfs->isTlsDisabled());
}
$options = new Options(['root-dir' => FLEX_TEST_DIR]);
$options = new Options(['root-dir' => FLEX_TEST_DIR, 'bin-dir' => 'bin/']);
$command = new UpdateRecipesCommand(
$flex,
new Downloader($composer, $this->io, $rfs),
Expand Down

0 comments on commit 7392a69

Please sign in to comment.