Filter dev-dependencies from "dump-autoload --no-dev" , fixes #4343
parent
b540ce264c
commit
b0be87177d
|
@ -388,6 +388,7 @@ EOF;
|
||||||
public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
|
public function parseAutoloads(array $packageMap, PackageInterface $mainPackage)
|
||||||
{
|
{
|
||||||
$mainPackageMap = array_shift($packageMap);
|
$mainPackageMap = array_shift($packageMap);
|
||||||
|
$packageMap = $this->filterPackageMap($packageMap, $mainPackage);
|
||||||
$sortedPackageMap = $this->sortPackageMap($packageMap);
|
$sortedPackageMap = $this->sortPackageMap($packageMap);
|
||||||
$sortedPackageMap[] = $mainPackageMap;
|
$sortedPackageMap[] = $mainPackageMap;
|
||||||
array_unshift($packageMap, $mainPackageMap);
|
array_unshift($packageMap, $mainPackageMap);
|
||||||
|
@ -899,6 +900,48 @@ INITIALIZER;
|
||||||
return md5($package->getName() . ':' . $path);
|
return md5($package->getName() . ':' . $path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters out dev-dependencies when not in dev-mode
|
||||||
|
*
|
||||||
|
* @param array $packageMap
|
||||||
|
* @param PackageInterface $mainPackage
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function filterPackageMap(array $packageMap, PackageInterface $mainPackage) {
|
||||||
|
if ($this->devMode === true) {
|
||||||
|
return $packageMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
$packages = array();
|
||||||
|
$include = array();
|
||||||
|
|
||||||
|
foreach ($packageMap as $item) {
|
||||||
|
$package = $item[0];
|
||||||
|
$name = $package->getName();
|
||||||
|
$packages[$name] = $package;
|
||||||
|
}
|
||||||
|
|
||||||
|
$add = function (PackageInterface $package) use (&$add, $mainPackage, $packages, &$include) {
|
||||||
|
foreach ($package->getRequires() as $link) {
|
||||||
|
$target = $link->getTarget();
|
||||||
|
$include[$target] = true;
|
||||||
|
if (isset($packages[$target])) {
|
||||||
|
$add($packages[$target]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
$add($mainPackage);
|
||||||
|
|
||||||
|
return array_filter(
|
||||||
|
$packageMap,
|
||||||
|
function ($item) use ($include) {
|
||||||
|
$package = $item[0];
|
||||||
|
$name = $package->getName();
|
||||||
|
return isset($include[$name]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sorts packages by dependency weight
|
* Sorts packages by dependency weight
|
||||||
*
|
*
|
||||||
|
|
|
@ -360,6 +360,10 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
public function testVendorsAutoloading()
|
public function testVendorsAutoloading()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -406,6 +410,10 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
public function testVendorsClassMapAutoloading()
|
public function testVendorsClassMapAutoloading()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -441,6 +449,10 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
public function testVendorsClassMapAutoloadingWithTargetDir()
|
public function testVendorsClassMapAutoloadingWithTargetDir()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -476,6 +488,11 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
public function testClassMapAutoloadingEmptyDirAndExactFile()
|
public function testClassMapAutoloadingEmptyDirAndExactFile()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b'),
|
||||||
|
new Link('a', 'c/c')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -515,6 +532,11 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
public function testClassMapAutoloadingAuthoritativeAndApcu()
|
public function testClassMapAutoloadingAuthoritativeAndApcu()
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b'),
|
||||||
|
new Link('a', 'c/c')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -559,6 +581,11 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array('files' => array('root.php')));
|
$package->setAutoload(array('files' => array('root.php')));
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b'),
|
||||||
|
new Link('a', 'c/c')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -604,6 +631,14 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
|
|
||||||
$notAutoloadPackage = new Package('a', '1.0', '1.0');
|
$notAutoloadPackage = new Package('a', '1.0', '1.0');
|
||||||
|
|
||||||
|
$requires = array(
|
||||||
|
new Link('a', 'a/a'),
|
||||||
|
new Link('a', 'b/b'),
|
||||||
|
new Link('a', 'c/c')
|
||||||
|
);
|
||||||
|
$autoloadPackage->setRequires($requires);
|
||||||
|
$notAutoloadPackage->setRequires($requires);
|
||||||
|
|
||||||
$autoloadPackages = array();
|
$autoloadPackages = array();
|
||||||
$autoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
|
$autoloadPackages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
$autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
|
$autoloadPackages[] = $b = new Package('b/b', '1.0', '1.0');
|
||||||
|
@ -667,9 +702,12 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
{
|
{
|
||||||
$package = new Package('a', '1.0', '1.0');
|
$package = new Package('a', '1.0', '1.0');
|
||||||
$package->setAutoload(array('files' => array('root2.php')));
|
$package->setAutoload(array('files' => array('root2.php')));
|
||||||
$package->setRequires(array(new Link('a', 'z/foo')));
|
$package->setRequires(array(
|
||||||
$package->setRequires(array(new Link('a', 'd/d')));
|
new Link('a', 'z/foo'),
|
||||||
$package->setRequires(array(new Link('a', 'e/e')));
|
new Link('a', 'b/bar'),
|
||||||
|
new Link('a', 'd/d'),
|
||||||
|
new Link('a', 'e/e')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $z = new Package('z/foo', '1.0', '1.0');
|
$packages[] = $z = new Package('z/foo', '1.0', '1.0');
|
||||||
|
@ -736,7 +774,10 @@ class AutoloadGeneratorTest extends TestCase
|
||||||
'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
|
'psr-0' => array('A\\B' => $this->workingDir.'/lib'),
|
||||||
'classmap' => array($this->workingDir.'/src'),
|
'classmap' => array($this->workingDir.'/src'),
|
||||||
));
|
));
|
||||||
$mainPackage->setRequires(array(new Link('z', 'a/a')));
|
$mainPackage->setRequires(array(
|
||||||
|
new Link('z', 'a/a'),
|
||||||
|
new Link('z', 'b/b')
|
||||||
|
));
|
||||||
|
|
||||||
$packages = array();
|
$packages = array();
|
||||||
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
$packages[] = $a = new Package('a/a', '1.0', '1.0');
|
||||||
|
@ -993,6 +1034,9 @@ EOF;
|
||||||
'classmap' => array('classmap'),
|
'classmap' => array('classmap'),
|
||||||
'files' => array('test.php'),
|
'files' => array('test.php'),
|
||||||
));
|
));
|
||||||
|
$package->setRequires(array(
|
||||||
|
new Link('a', 'b/b')
|
||||||
|
));
|
||||||
|
|
||||||
$vendorPackage = new Package('b/b', '1.0', '1.0');
|
$vendorPackage = new Package('b/b', '1.0', '1.0');
|
||||||
$vendorPackage->setAutoload(array(
|
$vendorPackage->setAutoload(array(
|
||||||
|
|
Loading…
Reference in New Issue