psalm
psalm copied to clipboard
`composer install` failing when `.git` folder is not available
Hi,
While packaging Psalm in Nix, I noticed that installing Psalm without the .git
folder is failing.
Here's a quick reproducer:
#!/usr/bin/env bash
# Exit on error
set -e
rm -rf 5.x.zip psalm-5.x
wget https://github.com/vimeo/psalm/archive/refs/heads/5.x.zip
unzip 5.x.zip
cd psalm-5.x
composer i --no-dev
The error is:
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires psalm/plugin-mockery ^1.1 -> satisfiable by psalm/plugin-mockery[1.1.0].
- psalm/plugin-mockery 1.1.0 requires vimeo/psalm dev-master || ^5.0@rc || ^5.0 -> satisfiable by vimeo/psalm[dev-master, 5.0.0-alpha1, ..., 5.x-dev, 6.x-dev (alias of dev-master)] from composer repo (https://repo.packagist.org) but vimeo/psalm is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
Problem 2
- psalm/plugin-phpunit[0.18.0, ..., 0.18.3] require vimeo/psalm dev-master || dev-4.x || ^4.5 || ^5@beta -> satisfiable by vimeo/psalm[dev-master, 4.5.0, ..., 4.x-dev, 5.0.0-alpha1, ..., 5.x-dev, 6.x-dev (alias of dev-master)] from composer repo (https://repo.packagist.org) but vimeo/psalm is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- psalm/plugin-phpunit 0.18.4 requires vimeo/psalm dev-master || dev-4.x || ^4.7.1 || ^5@beta || ^5.0 -> satisfiable by vimeo/psalm[dev-master, 4.7.1, ..., 4.x-dev, 5.0.0-alpha1, ..., 5.x-dev, 6.x-dev (alias of dev-master)] from composer repo (https://repo.packagist.org) but vimeo/psalm is the root package and cannot be modified. See https://getcomposer.org/dep-on-root for details and assistance.
- Root composer.json requires psalm/plugin-phpunit ^0.18 -> satisfiable by psalm/plugin-phpunit[0.18.0, ..., 0.18.4].
Running update with --no-dev does not mean require-dev is ignored, it just means the packages will not be installed. If dev requirements are blocking the update you have to resolve those problems.
I believe that installing Psalm should be easy and straightforward, what can we do to fix this?
edit: To make it work, just remove the following two lines from composer.json
, 'require-dev' section:
"psalm/plugin-mockery": "^1.1",
"psalm/plugin-phpunit": "^0.18",
The weird thing is that this issue is showing up, while --no-dev
is added. I don't get it.
Hey @drupol, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.
I think I have found the root of the issue.
Basically, the 2 plugins in require-dev
requires psalm ^5
. Since the .git
folder is not available and the Psalm version is not in composer.json
, Composer is not able to infer the proper Psalm version and set 1.0.0.0
by default and that's why it's failing to install.
To fix the issue, we can do the following:
COMPOSER_ROOT_VERSION=5.22.1 composer i --no-dev
And that works perfectly.
I guess we can now close the issue, let me know if you plan to do something to improve this.
Thanks.
This is basically how Composer works, and building Psalm from GitHub snapshots isn't exactly a supported installation method.
We use COMPOSER_ROOT_VERSION in CI ourselves: https://github.com/vimeo/psalm/blob/d3c1222152e000b6a81f37e0a1728b85c38c3659/.github/workflows/ci.yml#L45-L48
It could be added to documentation perhaps, as long as we make it clear it's not an officially recommended way to install Psalm.
Good idea to update the documentation, I've spent quite a huge amount of time to figure out why I wasn't able to install Psalm in Nix! (Nix builds software in total isolation, without the .git
folder)
I think we should write in the documentation that git
and the .git
folder must be available to build/install Psalm. I hope one day we'll find a way to get rid of that.
Actually that's not what I meant. I was thinking about adding two more doc pages:
- Alternative installation methods: deb, rpm, brew formulas, arch AUR, phive, etc.
- Packaging Psalm: instructions to build your own packages / recipes / etc.
Both would bear the notice that the information they present is contributed by the community and not maintained by our team, and that the 'official' installation ways are composer package, phar download and phar installed via composer. Then you can add NixOS instructions to the packaging page. Actually you can start the page yourself (as PR to master
branch, say contributing/packaging.md
) and I'll help with linking the page from other places and testing it in my local psalm.dev instance (it's a bit tricky to set up).
OK ! I will work on that.