Skip to content

Commit 4adc8a9

Browse files
authored
Merge pull request #3 from magento-trigger/MC-39996
MC-39996: Add composer2 support
2 parents 9fc7b89 + 50318ac commit 4adc8a9

File tree

4 files changed

+89
-74
lines changed

4 files changed

+89
-74
lines changed

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"repositories": [
1010
{
1111
"type": "vcs",
12-
"url": "[email protected]:Flyingmana/phpcs.git"
12+
"url": "[email protected]:firegento/phpcs.git"
1313
}
1414
],
1515
"authors":[
@@ -39,16 +39,16 @@
3939
}
4040
],
4141
"require":{
42-
"composer-plugin-api": "^1.0"
42+
"composer-plugin-api": "^1.1 || ^2.0",
43+
"composer/composer": "^1.9 || ^2.0"
4344
},
4445
"require-dev":{
4546
"phpunit/phpunit":"*",
4647
"phpunit/phpunit-mock-objects": "dev-master",
4748
"squizlabs/php_codesniffer": "1.4.7",
48-
"firegento/phpcs": "dev-patch-1",
49-
"composer/composer":"*@dev",
50-
"symfony/process":"*",
51-
"mikey179/vfsStream":"*"
49+
"firegento/phpcs": "~1.1.0",
50+
"symfony/process": "*",
51+
"mikey179/vfsstream": "*"
5252
},
5353
"replace": {
5454
"magento-hackathon/magento-composer-installer": "*"
@@ -64,7 +64,6 @@
6464
"/tests/FullStackTest/"
6565
]
6666
},
67-
"test_version":"999.0.0",
6867
"extra":{
6968
"composer-command-registry": [ "MagentoHackathon\\Composer\\Magento\\Command\\DeployCommand" ],
7069
"class":"MagentoHackathon\\Composer\\Magento\\Plugin"

src/MagentoHackathon/Composer/Magento/Command/DeployCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @author Tiago Ribeiro <[email protected]>
1919
* @author Rui Marinho <[email protected]>
2020
*/
21-
class DeployCommand extends \Composer\Command\Command
21+
class DeployCommand extends \Composer\Command\BaseCommand
2222
{
2323
protected function configure()
2424
{

src/MagentoHackathon/Composer/Magento/Installer.php

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Composer\Installer\InstallerInterface;
1616
use Composer\Package\PackageInterface;
1717
use MagentoHackathon\Composer\Magento\Deploy\Manager\Entry;
18+
use React\Promise\PromiseInterface;
1819

1920
/**
2021
* Composer Magento Installer
@@ -99,7 +100,7 @@ class Installer extends LibraryInstaller implements InstallerInterface
99100
* @var bool
100101
*/
101102
protected $appendGitIgnore = false;
102-
103+
103104
/**
104105
* @var array Path mapping prefixes that need to be translated (i.e. to
105106
* use a public directory as the web server root).
@@ -201,7 +202,7 @@ public function setDeployManager( DeployManager $deployManager)
201202
$this->deployManager = $deployManager;
202203
}
203204

204-
205+
205206
public function setConfig( ProjectConfig $config )
206207
{
207208
$this->config = $config;
@@ -329,7 +330,7 @@ public function getDeployStrategy(PackageInterface $package, $strategy = null)
329330
}
330331
if( isset($extra['magento-deploy-ignore'][$package->getName()]) ){
331332
$moduleSpecificDeployIgnores = array_merge(
332-
$moduleSpecificDeployIgnores,
333+
$moduleSpecificDeployIgnores,
333334
$extra['magento-deploy-ignore'][$package->getName()]
334335
);
335336
}
@@ -394,35 +395,39 @@ public function getTargetDir()
394395
}
395396

396397
/**
397-
* Installs specific package
398-
*
399-
* @param InstalledRepositoryInterface $repo repository in which to check
400-
* @param PackageInterface $package package instance
398+
* @inheritdoc
401399
*/
402400
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
403401
{
404-
405402
if ($package->getType() === 'magento-core' && !$this->preInstallMagentoCore()) {
406403
return;
407404
}
408405

409-
parent::install($repo, $package);
406+
$afterInstall = function () use ($package) {
407+
// skip marshal and apply default behavior if extra->map does not exist
408+
if ($this->hasExtraMap($package)) {
409+
$strategy = $this->getDeployStrategy($package);
410+
$strategy->setMappings($this->getParser($package)->getMappings());
411+
$deployManagerEntry = new Entry();
412+
$deployManagerEntry->setPackageName($package->getName());
413+
$deployManagerEntry->setDeployStrategy($strategy);
414+
$this->deployManager->addPackage($deployManagerEntry);
410415

411-
// skip marshal and apply default behavior if extra->map does not exist
412-
if (!$this->hasExtraMap($package)) {
413-
return;
414-
}
416+
if ($this->appendGitIgnore) {
417+
$this->appendGitIgnore($package, $this->getGitIgnoreFileLocation());
418+
}
419+
}
420+
};
415421

416-
$strategy = $this->getDeployStrategy($package);
417-
$strategy->setMappings($this->getParser($package)->getMappings());
418-
$deployManagerEntry = new Entry();
419-
$deployManagerEntry->setPackageName($package->getName());
420-
$deployManagerEntry->setDeployStrategy($strategy);
421-
$this->deployManager->addPackage($deployManagerEntry);
422+
$promise = parent::install($repo, $package);
422423

423-
if ($this->appendGitIgnore) {
424-
$this->appendGitIgnore($package, $this->getGitIgnoreFileLocation());
424+
// Composer v2 might return a promise here
425+
if ($promise instanceof PromiseInterface) {
426+
return $promise->then($afterInstall);
425427
}
428+
429+
// If not, execute the code right away as parent::install executed synchronously (composer v1, or v2 without async)
430+
$afterInstall();
426431
}
427432

428433
/**
@@ -464,7 +469,7 @@ public function appendGitIgnore(PackageInterface $package, $ignoreFile)
464469
if( in_array($ignore, $ignoredMappings) ){
465470
continue;
466471
}
467-
472+
468473
$additions[] = $ignore;
469474
}
470475
}
@@ -474,7 +479,7 @@ public function appendGitIgnore(PackageInterface $package, $ignoreFile)
474479
$contents = array_merge($contents, $additions);
475480
file_put_contents($ignoreFile, implode("\n", $contents));
476481
}
477-
482+
478483
if ($package->getType() === 'magento-core') {
479484
$this->prepareMagentoCore();
480485
}
@@ -590,17 +595,10 @@ protected function redeployProject() {
590595
}
591596

592597
/**
593-
* Updates specific package
594-
*
595-
* @param InstalledRepositoryInterface $repo repository in which to check
596-
* @param PackageInterface $initial already installed package version
597-
* @param PackageInterface $target updated version
598-
*
599-
* @throws InvalidArgumentException if $from package is not installed
598+
* @inheritdoc
600599
*/
601600
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
602601
{
603-
604602
if ($target->getType() === 'magento-core' && !$this->preUpdateMagentoCore()) {
605603
return;
606604
}
@@ -618,25 +616,35 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
618616
}
619617
}
620618

621-
parent::update($repo, $initial, $target);
619+
$afterUpdate = function () use ($target) {
620+
// marshal files for new package version if extra->map exist
621+
if ($this->hasExtraMap($target)) {
622+
$targetStrategy = $this->getDeployStrategy($target);
623+
$targetStrategy->setMappings($this->getParser($target)->getMappings());
624+
$deployManagerEntry = new Entry();
625+
$deployManagerEntry->setPackageName($target->getName());
626+
$deployManagerEntry->setDeployStrategy($targetStrategy);
627+
$this->deployManager->addPackage($deployManagerEntry);
628+
}
622629

623-
// marshal files for new package version if extra->map exist
624-
if ($this->hasExtraMap($target)) {
625-
$targetStrategy = $this->getDeployStrategy($target);
626-
$targetStrategy->setMappings($this->getParser($target)->getMappings());
627-
$deployManagerEntry = new Entry();
628-
$deployManagerEntry->setPackageName($target->getName());
629-
$deployManagerEntry->setDeployStrategy($targetStrategy);
630-
$this->deployManager->addPackage($deployManagerEntry);
631-
}
630+
if($this->appendGitIgnore) {
631+
$this->appendGitIgnore($target, $this->getGitIgnoreFileLocation());
632+
}
632633

633-
if($this->appendGitIgnore) {
634-
$this->appendGitIgnore($target, $this->getGitIgnoreFileLocation());
635-
}
634+
if ($target->getType() === 'magento-core') {
635+
$this->postUpdateMagentoCore();
636+
}
637+
};
638+
639+
$promise = parent::update($repo, $initial, $target);
636640

637-
if ($target->getType() === 'magento-core') {
638-
$this->postUpdateMagentoCore();
641+
// Composer v2 might return a promise here
642+
if ($promise instanceof PromiseInterface) {
643+
return $promise->then($afterUpdate);
639644
}
645+
646+
// If not, execute the code right away as parent::update executed synchronously (composer v1, or v2 without async)
647+
$afterUpdate();
640648
}
641649

642650

@@ -707,30 +715,24 @@ public function clearMagentoCache() {
707715
}
708716

709717
/**
710-
* Uninstalls specific package.
711-
*
712-
* @param InstalledRepositoryInterface $repo repository in which to check
713-
* @param PackageInterface $package package instance
718+
* @inheritdoc
714719
*/
715720
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
716721
{
717722
// skip marshal and apply default behavior if extra->map does not exist
718-
if (!$this->hasExtraMap($package)) {
719-
parent::uninstall($repo, $package);
720-
return;
721-
}
722-
723-
$strategy = $this->getDeployStrategy($package);
724-
$strategy->setMappings($this->getParser($package)->getMappings());
725-
try {
726-
$strategy->clean();
727-
} catch (\ErrorException $e) {
728-
if ($this->io->isDebug()) {
729-
$this->io->write($e->getMessage());
723+
if ($this->hasExtraMap($package)) {
724+
$strategy = $this->getDeployStrategy($package);
725+
$strategy->setMappings($this->getParser($package)->getMappings());
726+
try {
727+
$strategy->clean();
728+
} catch (\ErrorException $e) {
729+
if ($this->io->isDebug()) {
730+
$this->io->write($e->getMessage());
731+
}
730732
}
731733
}
732734

733-
parent::uninstall($repo, $package);
735+
return parent::uninstall($repo, $package);
734736
}
735737

736738
/**
@@ -792,7 +794,7 @@ public function getInstallPath(PackageInterface $package)
792794

793795
return $installPath;
794796
}
795-
797+
796798
public function transformArrayKeysToLowerCase($array)
797799
{
798800
$arrayNew = array();
@@ -806,7 +808,7 @@ public function transformArrayKeysToLowerCase($array)
806808
* this function is for annoying people with messages.
807809
*
808810
* First usage: get people to vote about the future release of composer so later I can say "you wanted it this way"
809-
*
811+
*
810812
* @param IOInterface $io
811813
*/
812814
public function annoy(IOInterface $io)
@@ -819,7 +821,7 @@ public function annoy(IOInterface $io)
819821
$io->write('<comment> time for voting about the future of the #magento #composer installer. </comment>', true);
820822
$io->write('<comment> https://github.com/magento-hackathon/magento-composer-installer/blob/discussion-master/Milestone/2/index.md </comment>', true);
821823
$io->write('<error> For the case you don\'t vote, I will ignore your problems till iam finished with the resulting release. </error>', true);
822-
*
824+
*
823825
**/
824826
}
825827

src/MagentoHackathon/Composer/Magento/Plugin.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,18 @@ private function requestRegeneration()
335335
touch($filename);
336336
}
337337
}
338+
339+
/**
340+
* @inheritdoc
341+
*/
342+
public function deactivate(Composer $composer, IOInterface $io)
343+
{
344+
}
345+
346+
/**
347+
* @inheritdoc
348+
*/
349+
public function uninstall(Composer $composer, IOInterface $io)
350+
{
351+
}
338352
}

0 commit comments

Comments
 (0)