Browse Source

Improve sorting of plugin packages, fixes #3109, refs #2972

Jordi Boggiano 10 years ago
parent
commit
62b5062146

+ 13 - 3
src/Composer/Installer.php

@@ -597,9 +597,19 @@ class Installer
                 continue;
             }
 
-            if ($package->getRequires() === array() && ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer')) {
-                $installerOps[] = $op;
-                unset($operations[$idx]);
+            if ($package->getType() === 'composer-plugin' || $package->getType() === 'composer-installer') {
+                // ignore requirements to platform or composer-plugin-api
+                $requires = array_keys($package->getRequires());
+                foreach ($requires as $index => $req) {
+                    if ($req === 'composer-plugin-api' || preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $req)) {
+                        unset($requires[$index]);
+                    }
+                }
+                // if there are no other requirements, move the plugin to the top of the op list
+                if (!count($requires)) {
+                    $installerOps[] = $op;
+                    unset($operations[$idx]);
+                }
             }
         }
 

+ 7 - 4
tests/Composer/Test/Fixtures/installer/plugins-are-installed-first.test

@@ -1,5 +1,5 @@
 --TEST--
-Composer installers are installed first if they have no requirements
+Composer installers are installed first if they have no meaningful requirements
 --COMPOSER--
 {
     "repositories": [
@@ -9,20 +9,23 @@ Composer installers are installed first if they have no requirements
                 { "name": "pkg", "version": "1.0.0" },
                 { "name": "pkg2", "version": "1.0.0" },
                 { "name": "inst", "version": "1.0.0", "type": "composer-plugin" },
-                { "name": "inst2", "version": "1.0.0", "type": "composer-plugin", "require": { "pkg2": "*" } }
+                { "name": "inst-with-req", "version": "1.0.0", "type": "composer-plugin", "require": { "php": ">=5", "ext-json": "*", "composer-plugin-api": "*" } },
+                { "name": "inst-with-req2", "version": "1.0.0", "type": "composer-plugin", "require": { "pkg2": "*" } }
             ]
         }
     ],
     "require": {
         "pkg": "1.0.0",
         "inst": "1.0.0",
-        "inst2": "1.0.0"
+        "inst-with-req2": "1.0.0",
+        "inst-with-req": "1.0.0"
     }
 }
 --RUN--
 install
 --EXPECT--
 Installing inst (1.0.0)
+Installing inst-with-req (1.0.0)
 Installing pkg (1.0.0)
 Installing pkg2 (1.0.0)
-Installing inst2 (1.0.0)
+Installing inst-with-req2 (1.0.0)