From 676f7e2af7de1eb61703f8d07cd0ddad4a42faca Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 1 Jun 2022 17:52:22 +0200 Subject: [PATCH] Prevent recipes bound to packs from being uninstalled when unpacking --- src/Flex.php | 23 ++++++++++++++++++----- tests/FlexTest.php | 2 ++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Flex.php b/src/Flex.php index e1d345ab7..ba038c579 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -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) { @@ -754,6 +762,7 @@ public function fetchRecipes(array $operations, bool $reset): array $recipes = [ 'symfony/framework-bundle' => null, ]; + $packRecipes = []; $metaRecipes = []; foreach ($operations as $operation) { @@ -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; } } @@ -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) diff --git a/tests/FlexTest.php b/tests/FlexTest.php index 26ef496c1..ab8fe4af4 100644 --- a/tests/FlexTest.php +++ b/tests/FlexTest.php @@ -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); @@ -209,6 +210,7 @@ public function testFetchRecipesOrder() $this->assertSame([ 'symfony/flex', + 'symfony/webapp-pack', 'symfony/webapp-meta', 'symfony/framework-bundle', 'symfony/console',