Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve directories for copy from recipe in update case #950

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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