Skip to content

Commit dc38805

Browse files
Prevent recipes bound to packs from being uninstalled when unpacking
1 parent 2ae0997 commit dc38805

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Flex.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,14 @@ public function configureInstaller()
306306
foreach ($backtrace as $trace) {
307307
if (isset($trace['object']) && $trace['object'] instanceof Installer) {
308308
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));
309+
310+
$updateAllowList = \Closure::bind(function () {
311+
return $this->updateWhitelist ?? $this->updateAllowList;
312+
}, $this->installer, $this->installer)();
313+
314+
if (['php' => 0] === $updateAllowList) {
315+
$this->dryRun = true; // prevent recipes from being uninstalled when removing a pack
316+
}
309317
}
310318

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

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

805814
if (isset($manifests[$name])) {
806-
if ('metapackage' === $package->getType()) {
807-
$metaRecipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
815+
$recipe = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
816+
817+
if ('symfony-pack' === $package->getType()) {
818+
$packRecipes[$name] = $recipe;
819+
} elseif ('metapackage' === $package->getType()) {
820+
$metaRecipes[$name] = $recipe;
808821
} elseif ('symfony/flex' === $name) {
809-
$flexRecipe = [$name => new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? [])];
822+
$flexRecipe = [$recipe];
810823
} else {
811-
$recipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
824+
$recipes[$name] = $recipe;
812825
}
813826
}
814827

@@ -834,7 +847,7 @@ public function fetchRecipes(array $operations, bool $reset): array
834847
}
835848
}
836849

837-
return array_merge($flexRecipe, $metaRecipes, array_filter($recipes));
850+
return array_merge($flexRecipe, $packRecipes, $metaRecipes, array_filter($recipes));
838851
}
839852

840853
public function truncatePackages(PrePoolCreateEvent $event)

0 commit comments

Comments
 (0)