Skip to content

Commit

Permalink
trying to fix getVersion() to fetch the version alias, when using "de…
Browse files Browse the repository at this point in the history
…v-master as <version>"

made PACKAGE_NAME a const
  • Loading branch information
jakoch committed Jan 26, 2016
1 parent 1d1abcf commit 74d7516
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/PhantomInstaller/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class Installer

const PHANTOMJS_CHMODE = 0770; // octal !

const PACKAGE_NAME = 'jakoch/phantomjs-installer';

/**
* installPhantomJS is the main function of the install script.
*
Expand Down Expand Up @@ -93,7 +95,7 @@ public static function download($io, $downloadManager, $targetDir, $version)
} catch (\Exception $e) {
if ($e instanceof \Composer\Downloader\TransportException && $e->getStatusCode() === 404) {
$version = self::getLowerVersion($version);
$io->write(PHP_EOL . '<warning>Let\'s retry the download with a lower version number: "'. $version .'".</warning>');
$io->write('<warning>Retrying the download with a lower version number: "'. $version .'".</warning>');
}
}
}
Expand Down Expand Up @@ -173,17 +175,28 @@ public static function getLowerVersion($old_version)
*/
public static function getVersion($composer)
{
// try getting the version from the local repository
$packages = $composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages();

foreach($packages as $package) {
if($package->getName() === 'jakoch/phantomjs-installer') {
if($package->getName() === self::PACKAGE_NAME) {
$version = $package->getPrettyVersion();
break;
}
}

// let's take a look at the aliases
if($package->getVersion() === '9999999-dev') { // this indicates the version alias???
$aliases = $composer->getLocker()->getAliases();
foreach($aliases as $idx => $alias) {
if($alias['package'] === self::PACKAGE_NAME) {
return $alias['alias'];
}
}
}

// version was not found in the local repository, let's take a look at the root package
if($version == null) {
$version = self::getRequiredVersion($composer->getPackage(), 'jakoch/phantomjs-installer');
// let's take a look at the root package
if(!empty($version)) {
$version = self::getRequiredVersion($composer->getPackage());
}

// fallback to the hardcoded latest version, if "dev-master" was set
Expand Down Expand Up @@ -212,14 +225,14 @@ public static function getVersion($composer)
* @throws \RuntimeException
* @return mixed
*/
public static function getRequiredVersion(RootPackageInterface $package, $packageName = 'jakoch/phantomjs-installer')
public static function getRequiredVersion(RootPackageInterface $package)
{
foreach (array($package->getRequires(), $package->getDevRequires()) as $requiredPackages) {
if (isset($requiredPackages[$packageName])) {
return $requiredPackages[$packageName]->getPrettyConstraint();
if (isset($requiredPackages[self::PACKAGE_NAME])) {
return $requiredPackages[self::PACKAGE_NAME]->getPrettyConstraint();
}
}
throw new \RuntimeException('Can not determine required version of ' . $packageName);
throw new \RuntimeException('Can not determine required version of ' . self::PACKAGE_NAME);
}

/**
Expand Down

6 comments on commit 74d7516

@drAlberT
Copy link

Choose a reason for hiding this comment

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

I think this commit is breaking something.

screen shot 2016-05-12 at 10 53 41

@jakoch
Copy link
Owner Author

@jakoch jakoch commented on 74d7516 May 12, 2016

Choose a reason for hiding this comment

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

Thank you for reporting the issue.

Invalid version string "^2.1" . Hmm. My first guess is, that the problem might be the range operator ^.

I have to reproduce the problem first.
Which version of the installer do you require in composer.json?
This one?

"require": {
        "jakoch/phantomjs-installer": "^2.1"
    },

@drAlberT
Copy link

@drAlberT drAlberT commented on 74d7516 May 12, 2016

Choose a reason for hiding this comment

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

@jakoch Yes .. simply running composer require jakoch/phantomjs-installer will use "^2.1" and rises the error

Version requirement "^2.1" will select the last stable version "2.1.1-p01" .. manually requiring this version gives no error

So .. yes the problem seems to be the "^2.1" string .. have tried and "2.*" gives error too

@jakoch
Copy link
Owner Author

@jakoch jakoch commented on 74d7516 May 12, 2016

Choose a reason for hiding this comment

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

Thank you for the quick response and your feedback on this issue.
It's now a verified bug and ticket #29

Version requirement "^2.1" will select the last stable version "2.1.1-p01"

Running composer require jakoch/phantomjs-installer uses ^2.1 and resolves to 2.1.1 for me..

manually requiring this version gives no error

Ok - this is also my suggested workaround then 🌻

@drAlberT
Copy link

@drAlberT drAlberT commented on 74d7516 May 12, 2016

Choose a reason for hiding this comment

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

Running composer require jakoch/phantomjs-installer uses ^2.1 and resolves to 2.1.1 for me..

Can this be due to some composer settings related to minimum stability I missed ?

@jakoch
Copy link
Owner Author

@jakoch jakoch commented on 74d7516 May 12, 2016

Choose a reason for hiding this comment

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

  • No, setting "minimum-stability": "dev" wouldn't change it.
  • I have a hard time reproducing the "Invalid version string "^2.1" thing. Running the CLI command standalone doesn't give me that error.
  • For now the problem is that, ^2.1 resolves to 2.1.1 and not 2.1.1-p01
    • maybe its the -p01 part that Composer doesn't like. I need to look their version syntax up.

I currently checking the version with https://semver.mwl.be/#?package=jakoch%2Fphantomjs-installer&version=%5E2.1&minimum-stability=stable

Please sign in to comment.