From dc023662ecf8caf8d4e6c71204a4ff5524f3e264 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Thu, 21 Sep 2017 00:09:10 +0300 Subject: [PATCH 1/3] Updated NpmRepository to skip broken versions --- Repository/NpmRepository.php | 16 ++++++-- Tests/Repository/NpmRepositoryTest.php | 56 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 4 deletions(-) diff --git a/Repository/NpmRepository.php b/Repository/NpmRepository.php index 5ce660d6..cad04ece 100644 --- a/Repository/NpmRepository.php +++ b/Repository/NpmRepository.php @@ -147,10 +147,18 @@ protected function createArrayRepositoryConfig(array $packageConfigs) $loader = new ArrayLoader(); foreach ($packageConfigs as $version => $config) { - $config['version'] = $version; - $config = $this->assetType->getPackageConverter()->convert($config); - $config = $this->assetRepositoryManager->solveResolutions($config); - $packages[] = $loader->load($config); + try { + $config['version'] = $version; + $config = $this->assetType->getPackageConverter()->convert($config); + $config = $this->assetRepositoryManager->solveResolutions($config); + $packages[] = $loader->load($config); + } catch (\UnexpectedValueException $exception) { + // Most probably version constraint is broken. + // Skip this version and hope that another one will be OK + continue; + } catch (\Exception $exception) { + throw $exception; + } } return $packages; diff --git a/Tests/Repository/NpmRepositoryTest.php b/Tests/Repository/NpmRepositoryTest.php index 4d25b102..521982c2 100644 --- a/Tests/Repository/NpmRepositoryTest.php +++ b/Tests/Repository/NpmRepositoryTest.php @@ -107,6 +107,62 @@ public function testWatProvidesWithoutRepositoryUrl() $this->assertCount(1, $this->rm->getRepositories()); } + public function testWhatProvidesWithBrokenVersionConstraint() + { + $name = $this->getType().'-asset/foobar'; + $rfs = $this->replaceRegistryRfsByMock(); + $rfs->expects($this->any()) + ->method('getContents') + ->will($this->returnValue(json_encode(array( + 'repository' => array( + 'type' => 'vcs', + ), + 'versions' => array( + '1.0.0' => array( + 'name' => 'foobar', + 'version' => '0.0.1', + 'dependencies' => array(), + 'dist' => array( + 'shasum' => '1d408b3fdb76923b9543d96fb4c9dfd535d9cb5d', + 'tarball' => 'http://registry.tld/foobar/-/foobar-1.0.0.tgz', + ), + ), + '1.0.1' => array( + 'name' => 'foobar', + 'version' => '0.0.1', + 'dependencies' => array( + // This constraint is invalid. Whole version package version should be skipped. + 'library1' => '^1.2,,<2.0' + ), + 'dist' => array( + 'shasum' => '1d408b3fdb76923b9543d96fb4c9acd535d9cb7a', + 'tarball' => 'http://registry.tld/foobar/-/foobar-1.0.1.tgz', + ), + ), + '1.0.2' => array( + 'name' => 'foobar', + 'version' => '0.0.1', + 'dependencies' => array( + 'library1' => '^1.2,<2.0' + ), + 'dist' => array( + 'shasum' => '1d408b3fdb76923b9543d96fb4c9acd535d9cb7a', + 'tarball' => 'http://registry.tld/foobar/-/foobar-1.0.1.tgz', + ), + ), + ), + 'time' => array( + '1.0.0' => '2016-09-20T13:48:47.730Z', + ), + )))); + + $this->assertCount(0, $this->rm->getRepositories()); + $this->assertCount(0, $this->registry->whatProvides($this->pool, $name)); + $this->assertCount(0, $this->registry->whatProvides($this->pool, $name)); + $this->assertCount(1, $this->rm->getRepositories()); + $this->assertCount(2, $this->rm->getRepositories()[0]->getPackages()); + } + /** * @expectedException \Fxp\Composer\AssetPlugin\Exception\InvalidCreateRepositoryException * @expectedExceptionMessage "repository.url" parameter of "foobar" From 5e99eff6e3799c229fa60eac69d49e7cbb8a0e81 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Thu, 21 Sep 2017 10:25:56 +0300 Subject: [PATCH 2/3] Added error message for skipped package version --- Repository/NpmRepository.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Repository/NpmRepository.php b/Repository/NpmRepository.php index cad04ece..3019e639 100644 --- a/Repository/NpmRepository.php +++ b/Repository/NpmRepository.php @@ -12,6 +12,7 @@ namespace Fxp\Composer\AssetPlugin\Repository; use Composer\DependencyResolver\Pool; +use Composer\IO\IOInterface; use Composer\Package\CompletePackageInterface; use Composer\Package\Loader\ArrayLoader; use Composer\Repository\ArrayRepository; @@ -155,6 +156,7 @@ protected function createArrayRepositoryConfig(array $packageConfigs) } catch (\UnexpectedValueException $exception) { // Most probably version constraint is broken. // Skip this version and hope that another one will be OK + $this->io->write("Skipped {$config['name']} version {$version}: {$exception->getMessage()}", IOInterface::VERBOSE); continue; } catch (\Exception $exception) { throw $exception; From cc13b3984baae99f357fa2c90cdf8638f9dbdb2f Mon Sep 17 00:00:00 2001 From: Dmitry Naumenko Date: Sat, 23 Sep 2017 09:46:18 +0300 Subject: [PATCH 3/3] Removed redundant catch block --- Repository/NpmRepository.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Repository/NpmRepository.php b/Repository/NpmRepository.php index 3019e639..540eecea 100644 --- a/Repository/NpmRepository.php +++ b/Repository/NpmRepository.php @@ -158,8 +158,6 @@ protected function createArrayRepositoryConfig(array $packageConfigs) // Skip this version and hope that another one will be OK $this->io->write("Skipped {$config['name']} version {$version}: {$exception->getMessage()}", IOInterface::VERBOSE); continue; - } catch (\Exception $exception) { - throw $exception; } }