Skip to content

Commit e7f3f34

Browse files
committed
bug #852 Flex recipe should always be installed first (HypeMC)
This PR was merged into the 1.x branch. Discussion ---------- Flex recipe should always be installed first I've noticed that when running `composer symfony:recipes:install --reset --force` the `symfony/webapp-meta` section is removed from the `.env` file: ``` symfony new --webapp sfwebapp cd sfwebapp/ composer symfony:recipes:install --reset --force ``` results in: ```diff -###> symfony/webapp-meta ### -MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=0 -###< symfony/webapp-meta ### ``` This is because the [meta recipes have precedence](https://github.com/symfony/flex/blob/e9a1e596e18b5b2f337dcb5f942d598eaf9a5502/src/Flex.php#L778) over other recipes, so the `symfony/webapp-meta` recipe is installed first, but since the `symfony/flex` recipe that is installed later has a [default `.env` file](https://github.com/symfony/recipes/blob/c985160644792e891d5a6c6d5d4d1088bedbab6e/symfony/flex/1.0/.env), it overwrites everything. This PR fixes the problem by making sure the `symfony/flex` recipe is always installed first, as was the case [previously](https://github.com/symfony/flex/pull/439/files#diff-0de31db49040778c07ce10b8959584b33d2ee5c880e4f8a7c19e4055f95ccbe9R583). Commits ------- 1376339 Flex recipe should always be installed first
2 parents e9a1e59 + 1376339 commit e7f3f34

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/Flex.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,10 @@ public function fetchRecipes(array $operations, bool $reset): array
702702
$data = $this->downloader->getRecipes($operations);
703703
$manifests = $data['manifests'] ?? [];
704704
$locks = $data['locks'] ?? [];
705-
// symfony/flex and symfony/framework-bundle recipes should always be applied first
705+
// symfony/flex recipes should always be applied first
706+
$flexRecipe = [];
707+
// symfony/framework-bundle recipe should always be applied first after the metapackages
706708
$recipes = [
707-
'symfony/flex' => null,
708709
'symfony/framework-bundle' => null,
709710
];
710711
$metaRecipes = [];
@@ -748,6 +749,8 @@ public function fetchRecipes(array $operations, bool $reset): array
748749
if (isset($manifests[$name])) {
749750
if ('metapackage' === $package->getType()) {
750751
$metaRecipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
752+
} elseif ('symfony/flex' === $name) {
753+
$flexRecipe = [$name => new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? [])];
751754
} else {
752755
$recipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
753756
}
@@ -775,7 +778,7 @@ public function fetchRecipes(array $operations, bool $reset): array
775778
}
776779
}
777780

778-
return array_merge($metaRecipes, array_filter($recipes));
781+
return array_merge($flexRecipe, $metaRecipes, array_filter($recipes));
779782
}
780783

781784
public function truncatePackages(PrePoolCreateEvent $event)

tests/FlexTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,41 @@ public function getPackagesForAutoDiscovery(): array
178178
return $return;
179179
}
180180

181+
public function testFetchRecipesOrder()
182+
{
183+
$packages = [
184+
['name' => 'symfony/console', 'type' => 'library'],
185+
['name' => 'symfony/flex', 'type' => 'composer-plugin'],
186+
['name' => 'symfony/framework-bundle', 'type' => 'library'],
187+
['name' => 'symfony/webapp-meta', 'type' => 'metapackage'],
188+
];
189+
190+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
191+
$rootPackage = $this->mockRootPackage(['symfony' => ['allow-contrib' => true]]);
192+
193+
$flex = $this->mockFlex($io, $rootPackage, null, [
194+
'manifests' => array_reduce($packages, static function (array $manifests, array $packageInfo) {
195+
$manifests[$packageInfo['name']] = ['manifest' => []];
196+
197+
return $manifests;
198+
}, []),
199+
]);
200+
201+
$recipes = $flex->fetchRecipes(array_map(static function (array $packageInfo) {
202+
$package = new Package($packageInfo['name'], '1.0.0', '1.0.0');
203+
$package->setType($packageInfo['type']);
204+
205+
return new InstallOperation($package);
206+
}, $packages), true);
207+
208+
$this->assertSame([
209+
'symfony/flex',
210+
'symfony/webapp-meta',
211+
'symfony/framework-bundle',
212+
'symfony/console',
213+
], array_keys($recipes));
214+
}
215+
181216
public static function getTestPackages(): array
182217
{
183218
return [

0 commit comments

Comments
 (0)