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

Invalid version string "^2.1" #29

Closed
jakoch opened this issue May 12, 2016 · 14 comments
Closed

Invalid version string "^2.1" #29

jakoch opened this issue May 12, 2016 · 14 comments
Labels

Comments

@jakoch
Copy link
Owner

jakoch commented May 12, 2016

I'm opening a new issue for the following comment and for bug verification,
because i tend to loose track of comments to source code.

74d7516#commitcomment-17446718

Steps to reproduce the problem:

drAlberT : simply running composer require jakoch/phantomjs-installer will use "^2.1" and rises the error

  • composer require jakoch/phantomjs-installer
    • this uses ^2.1 and resolves to 2.1.1 for me..
    • Note: this doesn't install PhantomJS, because no script triggered!
"require": {
    "jakoch/phantomjs-installer": "^2.1"
},

Workaround:

  • please require the exact version manually
  • do not rely on "range"- or "star"-operator based versions (^2.1or 2.1.*, 2.*)
jakoch referenced this issue May 12, 2016
…v-master as <version>"

made PACKAGE_NAME a const
@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

composer.json

{
    "require": {
        "jakoch/phantomjs-installer": "^2.1"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}

Result:

composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (2.1.1)
    Loading from cache

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Downloading: 100%

The problem i see is that ^2.1 resolves to 2.1.1 instead of 2.1.1-p01.
It seems that 2.1.1-p01 does not satisfy constraint ^2.1 for Composer.

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

@drAlberT
Copy link

drAlberT commented May 12, 2016

@jakoch I'm doing some tests ..

These are my settings:

  • OS: Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64
  • PHP:
    • PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    • PHP 5.6.21 (cli) (built: May 3 2016 06:21:49) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    • PHP 7.0.6 (cli) (built: May 2 2016 23:12:04) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

I have the same result for every php version I tried

@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

I guess, i found the reason in the semver docu - http://semver.org/#spec-item-11

When major, minor, and patch are equal, a pre-release version has lower precedence than a normal version. Example: 1.0.0-alpha < 1.0.0.

The reason that the constraint ^2.1 resolves to 2.1.1 is that 2.1.1-p01 is lower than 2.1.1,
even if tagged/released later like here.

So much for two-in-one version trickery ...

@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

Thanks for the OS and PHP versions,
but i would say that this isn't related to a specific version of PHP or OS.

I will test the full range of commands, including updates from version to version.

CLI: composer require jakoch/phantomjs-installer:"dev-master" --ignore-platform-reqs
Result: dev-master 0390bea - which is ok

./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (dev-master 0390bea)
    Cloning 0390bea35cbf03b4050f71bfbc508f6f27294376

Writing lock file
Generating autoload files

CLI: composer require jakoch/phantomjs-installer:"^2.1" --ignore-platform-reqs
Result: update from dev-master to 2.1.1-p01 - which is ok

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Updating jakoch/phantomjs-installer (dev-master 0390bea => 2.1.1-p01)
    Checking out 00cab61b66c39b60886a2bbdd7674ecfb344f98f

Writing lock file
Generating autoload files

CLI: composer require jakoch/phantomjs-installer:"dev-master" --ignore-platform-reqs
Result: update from 2.1.1-p01 to dev-master- which is ok

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Updating jakoch/phantomjs-installer (2.1.1-p01 => dev-master 0390bea)
    Checking out 0390bea35cbf03b4050f71bfbc508f6f27294376

Writing lock file
Generating autoload files

Finally, in an empty folder:
CLI: composer require jakoch/phantomjs-installer:"^2.1" --ignore-platform-reqs

Result: ^2.1 resolves to 2.1.1-p01 - hmm, i expected 2.1.1 - but ok

./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (2.1.1-p01)
    Downloading: 100%

Writing lock file
Generating autoload files

Finally, without version constraint on the require:
CLI: composer require jakoch/phantomjs-installer --ignore-platform-reqs
Result: 2.1.1-p01 -- seems to work... ok

Using version ^2.1 for jakoch/phantomjs-installer
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (2.1.1-p01)
    Loading from cache

Writing lock file
Generating autoload files

All cases handled and no loose screws found, yet. :(
I really wonder where the Invalid version string "^2.1" comes from... can't reproduce.

Back to you @drAlberT : any ideas or additional steps i could try?

@drAlberT
Copy link

drAlberT commented May 12, 2016

I made a test with a new brand empty project. Same issue:

foobar/ $ cat composer.json
{
    "name": "dralbert/foobar",
    "minimum-stability": "stable",
    "require": {
        "jakoch/phantomjs-installer": "2.1.1"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}
foobar/ $ tree -L 2
.
├── [ 102]  bin/
│   └── [ 43M]  phantomjs*
├── [ 411]  composer.json
├── [2.1K]  composer.lock
└── [ 170]  vendor/
    ├── [ 183]  autoload.php
    ├── [ 340]  composer/
    └── [ 136]  jakoch/

4 directories, 4 files
foobar/ $ composer require jakoch/phantomjs-installer

screen shot 2016-05-12 at 17 14 26

@drAlberT
Copy link

@jakoch made a new test .. another server, another OS:

$ uname -a
Linux devel 3.2.0-4-686-pae #1 SMP Debian 3.2.73-2+deb7u2 i686 GNU/Linux
$ php -v
PHP 5.4.45-0+deb7u2 (cli) (built: Oct 17 2015 09:01:48)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
$ cat composer.json
{
    "name": "dralbert/foobar",
    "minimum-stability": "stable",
    "require": {
        "jakoch/phantomjs-installer": "2.1.1"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}
$ tree -L 2
.
├── bin
│   └── phantomjs
├── composer.json
├── composer.lock
└── vendor
    ├── autoload.php
    ├── composer
    └── jakoch

4 directories, 4 files
$ composer require jakoch/phantomjs-installer
Using version ^2.1 for jakoch/phantomjs-installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing jakoch/phantomjs-installer (2.1.1)
  - Installing jakoch/phantomjs-installer (2.1.1-p01)
    Downloading: 100%

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
Script PhantomInstaller\Installer::installPhantomJS handling the post-update-cmd event terminated with an exception

Installation failed, reverting ./composer.json to its original content.


  [UnexpectedValueException]
  Invalid version string "^2.1"


require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--] [<packages>]...

Same result ;(

@drAlberT
Copy link

maybe the -p01 is confusing something? .. would 2.1.1.1 be a better naming for versioning ?

@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

Ahh, now i see where you are coming from:

Updating dependencies (including require-dev)
  - Removing jakoch/phantomjs-installer (2.1.1)
  - Installing jakoch/phantomjs-installer (2.1.1-p01) 

This is an install of 2.1.1 and then a require on top of it. Ok, let's try that:

composer.json

{
    "name": "dralbert/foobar",
    "minimum-stability": "stable",
    "require": {
        "jakoch/phantomjs-installer": "2.1.1"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}

followed by composer install to pull 2.1.1 in

Result:

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (2.1.1)
    Loading from cache

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache

then followed by composer require jakoch/phantomjs-installer:

Result:

Using version ^2.1 for jakoch/phantomjs-installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache

The require command changes the constraint from 2.1.1 to ^2.1 in composer.json.
But i don't get the exception.... strange...

We are using the same commands, but get different results.
Do you see the same?

One more try: on top of 2.1.1
composer require jakoch/phantomjs-installer:"2.1.1-p01" --ignore-platform-reqs
Result:

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing jakoch/phantomjs-installer (2.1.1)
  - Installing jakoch/phantomjs-installer (2.1.1-p01)
    Loading from cache

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache

No clue...

maybe the -p01 is confusing something? .. would 2.1.1.1 be a better naming for versioning ?

Maybe. But before i try the next versioning pattern, i would actually delete the 2.1.1-p01 and do a forced git tag push to update the old 2.1.1.

@drAlberT
Copy link

drAlberT commented May 12, 2016

@jakoch Bingo! ..

https://github.com/jakoch/phantomjs-installer/blob/master/src/PhantomInstaller/Installer.php#L213

If you dump the version here you get "^2.1" and the regex will not match .. so the version string returned by the function is simply ^2.1 and it is wrong, of course

@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

Ok, got it.. i can only reproduce this with Composer 1.1.0 (stable channel).

composer self-update
You are already using composer version 1.1.0 (stable channel).
composer require jakoch/phantomjs-installer:"^2.1" --ignore-platform-reqs
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
Script PhantomInstaller\Installer::installPhantomJS handling the post-update-cmd event terminated with an exception

Installation failed, reverting ./composer.json to its original content.


  [UnexpectedValueException]
  Invalid version string "^2.1"

@jakoch jakoch removed the verify bug label May 12, 2016
@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

The origin of the exception are these two lines
https://github.com/jakoch/phantomjs-installer/blob/master/src/PhantomInstaller/Installer.php#L115-L116

$version = `^2.1`;
$normVersion = $versionParser->normalize($version);

I other words: ^2.1 can't be normalized...

I need to resolve the ^2.1 used as installer version to 2.1.1 for the PhantomJS version.
My idea for a solution is the following:

  • if ^ on version number, run a versionTransformer($version)
    • strip the ^
    • build version number from maj.min + patch level 0: maj.min.0 (start of range)
    • compare maj.min.0 to PhantomJS installer versions
    • and return the highest version of the range, e.g. 2.1.1
  • Result: ^2.1 -> 2.1.1

Patch incoming...

jakoch added a commit that referenced this issue May 12, 2016
…rom the root package.

this will match `2.1.1-p01` and return `2.1.1`, instead of getting a `^2.1` from the root.
issue #29
@jakoch
Copy link
Owner Author

jakoch commented May 12, 2016

I've tagged a new release: https://github.com/jakoch/phantomjs-installer/releases/tag/2.1.1-p02
Please give me some feedback.

And: Thank you for your time and help in tracking this problem down !


composer.json

{
    "name": "dralbert/foobar",
    "minimum-stability": "stable",
    "require": {
        "jakoch/phantomjs-installer": "2.1.1"
    },
    "config": {
        "bin-dir": "bin"
    },
    "scripts": {
        "post-install-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ],
        "post-update-cmd": [
            "PhantomInstaller\\Installer::installPhantomJS"
        ]
    }
}
composer install

Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing jakoch/phantomjs-installer (2.1.1)
    Loading from cache

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache
composer require jakoch/phantomjs-installer:"^2.1" --ignore-platform-reqs

./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing jakoch/phantomjs-installer (2.1.1)
  - Installing jakoch/phantomjs-installer (2.1.1-p02)
    Loading from cache

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache

This works on Composer 1.1.0 stable and 1.2-dev.

@drAlberT
Copy link

$ composer require jakoch/phantomjs-installer
Using version ^2.1 for jakoch/phantomjs-installer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Removing jakoch/phantomjs-installer (2.1.1-p01)
  - Installing jakoch/phantomjs-installer (2.1.1-p02)
    Downloading: 100%

Writing lock file
Generating autoload files
> PhantomInstaller\Installer::installPhantomJS
  - Installing phantomjs (2.1.1)
    Loading from cache

Sounds good 👍

Thank you for solving in such a fast way!

@jakoch
Copy link
Owner Author

jakoch commented May 13, 2016

No problem.

Sometimes these dependency problems are really hard to track down and reproduce.
This is a good example to stick to it and finding the reproduction case.
Thank you for supporting me. 👍

Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants