mirror of
https://github.com/composer/composer
synced 2025-05-11 09:32:55 +00:00
[#2492] Automatically using the latest version when requiring a package
This applies to the init and require commands. Previously: If you ommitted the version of a library, it prompted you to enter a version. New Behavior: If you omit the version, it automatically selects the latest version that is consistent with your minimum-stability flag. Is Jordi mentions, this is consistent with how npm works.
This commit is contained in:
parent
947db97e33
commit
58535a62fa
2 changed files with 59 additions and 22 deletions
|
@ -266,23 +266,14 @@ EOT
|
|||
$pool->addRepository($sourceRepo);
|
||||
|
||||
$constraint = $packageVersion ? $parser->parseConstraints($packageVersion) : null;
|
||||
$candidates = $pool->whatProvides($name, $constraint);
|
||||
foreach ($candidates as $key => $candidate) {
|
||||
if ($candidate->getName() !== $name) {
|
||||
unset($candidates[$key]);
|
||||
}
|
||||
}
|
||||
$candidates = $pool->whatProvides($name, $constraint, true);
|
||||
|
||||
if (!$candidates) {
|
||||
throw new \InvalidArgumentException("Could not find package $name" . ($packageVersion ? " with version $packageVersion." : " with stability $stability."));
|
||||
}
|
||||
|
||||
if (null === $directory) {
|
||||
$parts = explode("/", $name, 2);
|
||||
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
|
||||
}
|
||||
|
||||
// select highest version if we have many
|
||||
// logic is repeated in InitCommand
|
||||
$package = reset($candidates);
|
||||
foreach ($candidates as $candidate) {
|
||||
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
|
||||
|
@ -291,6 +282,11 @@ EOT
|
|||
}
|
||||
unset($candidates);
|
||||
|
||||
if (null === $directory) {
|
||||
$parts = explode("/", $name, 2);
|
||||
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
|
||||
}
|
||||
|
||||
$io->write('<info>Installing ' . $package->getName() . ' (' . VersionParser::formatVersion($package, false) . ')</info>');
|
||||
|
||||
if ($disablePlugins) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue