Skip to content

Commit 676f7e2

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

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-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 = [$name => $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)

tests/FlexTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function testFetchRecipesOrder()
187187
['name' => 'symfony/flex', 'type' => 'composer-plugin'],
188188
['name' => 'symfony/framework-bundle', 'type' => 'library'],
189189
['name' => 'symfony/webapp-meta', 'type' => 'metapackage'],
190+
['name' => 'symfony/webapp-pack', 'type' => 'symfony-pack'],
190191
];
191192

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

210211
$this->assertSame([
211212
'symfony/flex',
213+
'symfony/webapp-pack',
212214
'symfony/webapp-meta',
213215
'symfony/framework-bundle',
214216
'symfony/console',

0 commit comments

Comments
 (0)