Skip to content

Prevent recipes bound to packs from being uninstalled when unpacking #923

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

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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