Skip to content

Commit

Permalink
Prevent recipes bound to packs from being uninstalled when unpacking
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 1, 2022
1 parent 2ae0997 commit 676f7e2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,14 @@ public function configureInstaller()
foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Installer) {
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));

$updateAllowList = \Closure::bind(function () {
return $this->updateWhitelist ?? $this->updateAllowList;
}, $this->installer, $this->installer)();

if (['php' => 0] === $updateAllowList) {
$this->dryRun = true; // prevent recipes from being uninstalled when removing a pack
}
}

if (isset($trace['object']) && $trace['object'] instanceof GlobalCommand) {
Expand Down Expand Up @@ -754,6 +762,7 @@ public function fetchRecipes(array $operations, bool $reset): array
$recipes = [
'symfony/framework-bundle' => null,
];
$packRecipes = [];
$metaRecipes = [];

foreach ($operations as $operation) {
Expand Down Expand Up @@ -803,12 +812,16 @@ public function fetchRecipes(array $operations, bool $reset): array
}

if (isset($manifests[$name])) {
if ('metapackage' === $package->getType()) {
$metaRecipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
$recipe = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);

if ('symfony-pack' === $package->getType()) {
$packRecipes[$name] = $recipe;
} elseif ('metapackage' === $package->getType()) {
$metaRecipes[$name] = $recipe;
} elseif ('symfony/flex' === $name) {
$flexRecipe = [$name => new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? [])];
$flexRecipe = [$name => $recipe];
} else {
$recipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
$recipes[$name] = $recipe;
}
}

Expand All @@ -834,7 +847,7 @@ public function fetchRecipes(array $operations, bool $reset): array
}
}

return array_merge($flexRecipe, $metaRecipes, array_filter($recipes));
return array_merge($flexRecipe, $packRecipes, $metaRecipes, array_filter($recipes));
}

public function truncatePackages(PrePoolCreateEvent $event)
Expand Down
2 changes: 2 additions & 0 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function testFetchRecipesOrder()
['name' => 'symfony/flex', 'type' => 'composer-plugin'],
['name' => 'symfony/framework-bundle', 'type' => 'library'],
['name' => 'symfony/webapp-meta', 'type' => 'metapackage'],
['name' => 'symfony/webapp-pack', 'type' => 'symfony-pack'],
];

$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
Expand All @@ -209,6 +210,7 @@ public function testFetchRecipesOrder()

$this->assertSame([
'symfony/flex',
'symfony/webapp-pack',
'symfony/webapp-meta',
'symfony/framework-bundle',
'symfony/console',
Expand Down

0 comments on commit 676f7e2

Please sign in to comment.