Skip to content

Enable support for inline recipes (local recipe inside the package itself) #572

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

Closed
wants to merge 3 commits into from
Closed
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
51 changes: 39 additions & 12 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -711,18 +711,40 @@ private function fetchRecipes(): array

$noRecipe = !isset($manifests[$name]) || (isset($manifests[$name]['not_installable']) && $manifests[$name]['not_installable']);
if ($noRecipe && 'symfony-bundle' === $package->getType()) {
$manifest = [];
$bundle = new SymfonyBundle($this->composer, $package, $job);
if (null === $devPackages) {
$devPackages = array_column($this->composer->getLocker()->getLockData()['packages-dev'], 'name');
}
$envs = \in_array($name, $devPackages) ? ['dev', 'test'] : ['all'];
foreach ($bundle->getClassNames() as $class) {
$manifest['manifest']['bundles'][$class] = $envs;
}
if ($manifest) {
$manifest['origin'] = sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion());
// Get the lock data from all packages, including dev.
$lockDataPackages = array_merge(
$this->composer->getLocker()->getLockData()['packages'],
$this->composer->getLocker()->getLockData()['packages-dev']
);

// Get lock data of the package.
$lockDataPackage = current(
array_filter(
$lockDataPackages,
static function ($lockData) use ($package) {
return $lockData['name'] === $package->getName();
}
)
);

if (isset($lockDataPackage['extra']['recipe']) && \is_array($lockDataPackage['extra']['recipe'])) {
$manifest['origin'] = sprintf('%s:%s@inline recipe', $name, $package->getPrettyVersion());
$manifest['recipe'] = $lockDataPackage['extra']['recipe'];
$recipes[$name] = new Recipe($package, $name, $job, $manifest);
} else {
$manifest = [];
$bundle = new SymfonyBundle($this->composer, $package, $job);
if (null === $devPackages) {
$devPackages = array_column($this->composer->getLocker()->getLockData()['packages-dev'], 'name');
}
$envs = \in_array($name, $devPackages) ? ['dev', 'test'] : ['all'];
foreach ($bundle->getClassNames() as $class) {
$manifest['manifest']['bundles'][$class] = $envs;
}
if ($manifest) {
$manifest['origin'] = sprintf('%s:%s@auto-generated recipe', $name, $package->getPrettyVersion());
$recipes[$name] = new Recipe($package, $name, $job, $manifest);
}
}
}
}
Expand Down Expand Up @@ -762,7 +784,12 @@ private function formatOrigin(string $origin): string
return $origin;
}

return sprintf('<info>%s</> (<comment>>=%s</>): From %s', $matches[1], $matches[2], 'auto-generated recipe' === $matches[3] ? '<comment>'.$matches[3].'</>' : $matches[3]);
$from = $matches[3];
if ('auto-generated recipe' === $matches[3] || 'inline recipe' === $matches[3]) {
$from = '<comment>'.$matches[3].'</>';
}

return sprintf('<info>%s</> (<comment>>=%s</>): From %s', $matches[1], $matches[2], $from);
}

private function shouldRecordOperation(PackageEvent $event): bool
Expand Down
4 changes: 4 additions & 0 deletions src/Recipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function getJob(): string

public function getManifest(): array
{
if (\array_key_exists('recipe', $this->data)) {
return array_merge($this->data['recipe'], isset($this->data['manifest']) ? $this->data['manifest'] : []);
}

if (!isset($this->data['manifest'])) {
throw new \LogicException(sprintf('Manifest is not available for recipe "%s".', $this->name));
}
Expand Down