Skip to content

Commit

Permalink
Merge pull request #4 from magento-borg/require-commerce-command
Browse files Browse the repository at this point in the history
PWA-2165: Move functionality to require-commerce and drop web setup w…
  • Loading branch information
pdohogne-magento authored Oct 18, 2021
2 parents 27b97b5 + 6cebd6f commit ee5d594
Show file tree
Hide file tree
Showing 38 changed files with 1,121 additions and 1,667 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Purpose of plugin

The `magento/composer-root-update-plugin` Composer plugin resolves changes that need to be made to the root project `composer.json` file before updating to a new Magento metapackage requirement.
The `magento/composer-root-update-plugin` Composer plugin resolves changes that need to be made to the root project `composer.json` file before updating to a new Magento metapackage requirement through the `composer require-commerce` command.

This is accomplished by comparing the root `composer.json` file for the Magento project corresponding to the Magento version and edition in the current installation with the Magento project `composer.json` file for the target Magento metapackage when the `composer require` command runs and applying any deltas found between the two files if they do not conflict with the existing `composer.json` file in the Magento root directory.
To accomplish this, it compares the default project `composer.json` file for the Magento Open Source or Adobe Commerce metapackage version in the current installation with the project `composer.json` file corresponding to the target metapackage. The command then applies any deltas found between the two files if they do not conflict with user customizations.

# Getting Started

Expand Down
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"type": "project",
"name": "magento/composer-root-update-plugin",
"description": "Git source for the Magento root update lookahead composer plugin",
"description": "Git source for the Magento Open Source/Adobe Commerce root update lookahead composer plugin",
"license": [
"OSL-3.0",
"AFL-3.0"
],
"require": {
"composer/composer": "<1.11 || >=2.0.0 <2.1",
"php": "~7.3.0||~7.4.0",
"composer/composer": "^1.0 || ^2.0",
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
"phpunit/phpunit": "~6.5.0"
"phpunit/phpunit": "~9.5.0"
},
"autoload": {
"psr-4": {
Expand Down
145 changes: 43 additions & 102 deletions docs/class_descriptions.md

Large diffs are not rendered by default.

111 changes: 19 additions & 92 deletions docs/process_flows.md

Large diffs are not rendered by default.

Binary file removed docs/resources/explicit_install_flow.png
Binary file not shown.
Binary file removed docs/resources/module_install_flow.png
Binary file not shown.
Binary file removed docs/resources/require_command_flow.png
Binary file not shown.
Binary file removed docs/resources/self_install_flow.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Composer\Semver\VersionParser;
use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Exception;
use Symfony\Component\Console\Input\InputInterface;

/**
Expand All @@ -37,14 +38,14 @@ abstract class ExtendableRequireCommand extends RequireCommand
protected $jsonFile;

/**
* @var bool $mageNewlyCreated
* @var bool $pluginNewlyCreated
*/
protected $mageNewlyCreated;
protected $pluginNewlyCreated;

/**
* @var bool|string $mageComposerBackup
* @var bool|string $pluginComposerBackup
*/
protected $mageComposerBackup;
protected $pluginComposerBackup;

/**
* @var string $preferredStability
Expand All @@ -64,8 +65,8 @@ public function __construct(string $name = null)
parent::__construct($name);
$this->fileName = null;
$this->jsonFile = null;
$this->mageNewlyCreated = null;
$this->mageComposerBackup = null;
$this->pluginNewlyCreated = null;
$this->pluginComposerBackup = null;
$this->preferredStability = null;
$this->phpVersion = null;
}
Expand All @@ -80,7 +81,7 @@ public function __construct(string $name = null)
* @param InputInterface $input
* @return int|array
*/
protected function parseComposerJsonFile($input)
protected function parseComposerJsonFile(InputInterface $input)
{
$file = Factory::getComposerFile();
$io = $this->getIO();
Expand Down Expand Up @@ -129,8 +130,8 @@ protected function parseComposerJsonFile($input)

$this->fileName = $file;
$this->jsonFile = $json;
$this->mageNewlyCreated = $newlyCreated;
$this->mageComposerBackup = $composerBackup;
$this->pluginNewlyCreated = $newlyCreated;
$this->pluginComposerBackup = $composerBackup;
$this->preferredStability = $preferredStability;
$this->phpVersion = $phpVersion;
return 0;
Expand All @@ -140,17 +141,17 @@ protected function parseComposerJsonFile($input)
* Interactively ask for the requirement arguments
*
* Copied second half of InitCommand::determineRequirements() without calling findBestVersionAndNameForPackage(),
* which would try to use existing requirements before the plugin can update new Magento values
* which would try to use existing requirements before the plugin can update new project values
*
* @see InitCommand::determineRequirements()
*
* @return array
* @throws \Exception
* @throws Exception
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function getRequirementsInteractive()
protected function getRequirementsInteractive(): array
{
$versionParser = new VersionParser();
$io = $this->getIO();
Expand Down Expand Up @@ -215,7 +216,7 @@ protected function getRequirementsInteractive()
return $pkgMatches['name'];
}

throw new \Exception('Not a valid selection');
throw new Exception('Not a valid selection');
};

$package = $io->askAndValidate(
Expand Down Expand Up @@ -266,19 +267,19 @@ protected function getRequirementsInteractive()
* @param string $message
* @return void
*/
protected function revertMageComposerFile($message)
protected function revertRootComposerFile(string $message)
{
$file = $this->fileName;
$io = $this->getIO();
if ($this->mageNewlyCreated) {
if ($this->pluginNewlyCreated) {
if (file_exists($this->jsonFile->getPath())) {
$io->writeError("\n<error>$message, deleting $file.</error>");
unlink($this->jsonFile->getPath());
}
} else {
$io->writeError("\n<error>$message, " .
"reverting $file to its original content from before the Magento root update.</error>");
file_put_contents($this->jsonFile->getPath(), $this->mageComposerBackup);
"reverting $file to its original content from before the magento/project root update.</error>");
file_put_contents($this->jsonFile->getPath(), $this->pluginComposerBackup);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
namespace Magento\ComposerRootUpdatePlugin\Plugin;

use Composer\Plugin\Capability\CommandProvider as CommandProviderCapability;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\MageRootRequireCommand;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\OverrideRequireCommand;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\RequireCommerceCommand;
use Magento\ComposerRootUpdatePlugin\Plugin\Commands\UpdatePluginNamespaceCommands;

/**
Expand All @@ -20,6 +21,9 @@ class CommandProvider implements CommandProviderCapability
*/
public function getCommands()
{
return [new MageRootRequireCommand(), new UpdatePluginNamespaceCommands()];
return [
new OverrideRequireCommand(),
new RequireCommerceCommand()
];
}
}
Loading

0 comments on commit ee5d594

Please sign in to comment.