Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated NpmRepository to skip broken versions #308

Merged
merged 3 commits into from
Sep 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Repository/NpmRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a warning or notice, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done

continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • continue is not necessary
  • remove comments because the output message is explicit

And it will be good for me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comments because the output message is explicit

the message says much less than the comment. should probably improve the message to say, why the version was skipped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$exception->getMessage() will include the exact reason, e.g. "Could not parse version constraint >=1.1.0,,<2.0: Invalid version string "1.1.0,,<2.0"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for keeping the comment then, it does not hurt and provides more context.

} catch (\Exception $exception) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catch is unnecessary.

throw $exception;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why catch it if you don't do anything with it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SilverFire See my previous review, because it is past in outdated status with your new update, but it's not the case: this catch is unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think this can be removed, you're just catching and throwing the exception again :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opps. It used id for debug to place breakpoint on throw $exception, then I just forgot to remove it. Thank you for pointing out, friends :)

}
}

return $packages;
Expand Down
56 changes: 56 additions & 0 deletions Tests/Repository/NpmRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down