setName($name) ->setDescription('Unpack Drupal recipes.') ->addArgument('recipes', InputArgument::IS_ARRAY, "A list of recipe package names separated by a space, e.g. drupal/recipe_one drupal/recipe_two. If not provided, all recipes listed in the require section of the root composer are unpacked.") ->setHelp( <<$name command unpacks dependencies from the specified recipe packages into the composer.json file. php composer.phar $name drupal/my-recipe [...] It is usually not necessary to call $name manually, because by default it is called automatically as needed, after a require command. EOT ); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output): int { $composer = $this->requireComposer(); $io = $this->getIO(); $local_repo = $composer->getRepositoryManager()->getLocalRepository(); $package_names = $input->getArgument('recipes') ?? []; // If no recipes are provided unpack all recipes that are required by the // root package. if (empty($package_names)) { foreach ($composer->getPackage()->getRequires() as $link) { $target = $link->getTarget(); // Skip platform requirements, since those don't resolve to a real // package. // @see https://getcomposer.org/doc/articles/composer-platform-dependencies.md if (PlatformRepository::isPlatformPackage($target)) { continue; } $package = $local_repo->findPackage($target, $link->getConstraint()); if ($package->getType() === Plugin::RECIPE_PACKAGE_TYPE) { $package_names[] = $package->getName(); } } if (empty($package_names)) { $io->write('No recipes to unpack.'); return 0; } } $manager = new UnpackManager($composer, $io); $unpack_collection = new UnpackCollection(); foreach ($package_names as $package_name) { if (!$manager->isRootDependency($package_name)) { $io->error(sprintf('%s not found in the root composer.json.', $package_name)); return 1; } $packages = $local_repo->findPackages($package_name); $package = reset($packages); if (!$package instanceof PackageInterface) { $io->error(sprintf('%s does not resolve to a package.', $package_name)); return 1; } if ($package->getType() !== Plugin::RECIPE_PACKAGE_TYPE) { $io->error(sprintf('%s is not a recipe.', $package->getPrettyName())); return 1; } if ($manager->unpackOptions->isIgnored($package)) { $io->error(sprintf('%s is in the extra.drupal-recipe-unpack.ignore list.', $package->getName())); return 1; } if (UnpackManager::isDevRequirement($package)) { $io->warning(sprintf('%s is present in the require-dev key. Unpacking will move the recipe\'s dependencies to the require key.', $package->getName())); if ($io->isInteractive() && !$io->askConfirmation('Do you want to continue [yes]?')) { return 0; } } $unpack_collection->add($package); } $manager->unpack($unpack_collection); return 0; } }