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

When running composer require on the project, it dies #38

Closed
mglaman opened this issue Apr 12, 2019 · 11 comments · Fixed by #50
Closed

When running composer require on the project, it dies #38

mglaman opened this issue Apr 12, 2019 · 11 comments · Fixed by #50

Comments

@mglaman
Copy link
Owner

mglaman commented Apr 12, 2019

When running composer require mglaman/drupal-check --dev on a Drupal project, it will crash. This is due to Drupal's minimum-stability:dev setting. This caused symfony/console to come in as 4.2.x and conflict city fired off.

@davidferlay
Copy link

davidferlay commented Apr 15, 2019

Looks like issue is also appearing when executing composer require mglaman/drupal-check on a Drupal project

Any idea how it should be fixed ?

/var/www/html $ composer require mglaman/drupal-check
    1/1:	https://packages.drupal.org/8/drupal/provider-2019-2$3c57e0a47ec99e2008195bebd253ef7d86e308abc87fec703ca6bfffabad95f5.json
    Finished: success: 1, skipped: 0, failure: 0, total: 1
    1/3:	http:https://repo.packagist.org/p/provider-latest$51a0e626e31f644baab8ad729abc25d825cd7ebdf13f8d7172e30912eaa0b9cc.json
    2/3:	http:https://repo.packagist.org/p/provider-2019-01$ff6388330b45685db1f753be53f503f8c074ebfd77dd19d9b183f619b93cfd16.json
    3/3:	http:https://repo.packagist.org/p/provider-2017$98ef485051ef3bccffcbd37e8c126e80c50d235b45b9773fbeb5719852628d08.json
    Finished: success: 3, skipped: 0, failure: 0, total: 3
Using version ^1.0 for mglaman/drupal-check
./composer.json has been updated
Gathering patches for root package.
> SkilldDrupal\composer\ScriptHandler::checkComposerVersion
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install mglaman/drupal-check 1.0.7
    - Conclusion: don't install mglaman/drupal-check 1.0.6
    - Conclusion: don't install mglaman/drupal-check 1.0.5
    - Conclusion: don't install mglaman/drupal-check 1.0.4
    - Conclusion: don't install mglaman/drupal-check 1.0.3
    - Conclusion: don't install mglaman/drupal-check 1.0.2
    - Conclusion: don't install mglaman/drupal-check 1.0.1
    - Installation request for mglaman/drupal-check ^1.0 -> satisfiable by mglaman/drupal-check[1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.0.5, 1.0.6, 1.0.7].
    - Conclusion: remove symfony/console v3.4.24
    - mglaman/drupal-check 1.0.0 requires symfony/console ^4.2 -> satisfiable by symfony/console[4.2.x-dev, v4.2.0, v4.2.0-BETA1, v4.2.0-BETA2, v4.2.0-RC1, v4.2.1, v4.2.2, v4.2.3, v4.2.4, v4.2.5, 4.3.x-dev].
    - Can only install one of: symfony/console[v3.4.24, 4.2.x-dev].
    - Can only install one of: symfony/console[v4.2.0, v3.4.24].
    - Can only install one of: symfony/console[v4.2.0-BETA1, v3.4.24].
    - Can only install one of: symfony/console[v4.2.0-BETA2, v3.4.24].
    - Can only install one of: symfony/console[v4.2.0-RC1, v3.4.24].
    - Can only install one of: symfony/console[v4.2.1, v3.4.24].
    - Can only install one of: symfony/console[v4.2.2, v3.4.24].
    - Can only install one of: symfony/console[v4.2.3, v3.4.24].
    - Can only install one of: symfony/console[v4.2.4, v3.4.24].
    - Can only install one of: symfony/console[v4.2.5, v3.4.24].
    - Can only install one of: symfony/console[4.3.x-dev, v3.4.24].
    - Installation request for symfony/console (installed at v3.4.24) -> satisfiable by symfony/console[v3.4.24].


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

@cloudstrife602
Copy link

cloudstrife602 commented Apr 18, 2019

Drupal doesn't yet support symfony/console >3. Our drupal site composer.json file includes a line limiting symfony/console to versions something like ~3.6 but since all versions of mglaman/drupal-check require symfony/console: ^4.2 we get dependency conflicts. Drupal says we can't install 4, drupal-check says we have to have at least 4.2. They can't be resolved so the installation is rejected and the composer.json file reverts to what it was before the command execution. The solution would be to install drupal-check globally via composer global require mglaman/drupal-check and adding your global composer to your PATH.

Since global composer can still fall prey to dependency conflicts, drush/drush for example requires symfony/console: ^3.4. I recommend using cgr which sandboxes each globally required package with its own dependencies so there shouldn't be conflicts. See https://packagist.org/packages/consolidation/cgr for information.

@mglaman
Copy link
Owner Author

mglaman commented Apr 18, 2019

Please try using the Phar. And this project was never meant to be added alongside Drupal projects. Directly add mglaman/phpstan-drupal

Edit. I forgot we were going to try and fix this.

@davidferlay
Copy link

davidferlay commented Apr 19, 2019

Drupal doesn't yet support symfony/console >3. (...)
Since all versions of mglaman/drupal-check require symfony/console: ^4.2 we get dependency conflicts.

Current readme states :
PHP >=7.1

However, composer.json defines more requirements :

    "require": {
        "php": "~7.1",
        "composer/xdebug-handler": "^1.3",
        "jean85/pretty-package-versions": "^1.2",
        "mglaman/phpstan-drupal-deprecations": "^0.11.1",
        "mglaman/phpstan-junit": "^0.11.1",
        "symfony/console": "^4.2",
        "webflo/drupal-finder": "^1.1"

Wouldn't it make sense to update readme to make dependencies more exaustive ? I can make a PR for it)

@mglaman
Copy link
Owner Author

mglaman commented Apr 19, 2019

If we make the dependencies more explicit we can work around the problem. @davidferlay feel free to give it a PR and see what happens! TravisCI workflow should be updated to test running the project against composer require on a Drupal site.

I do that for phpstan-drupal: https://github.com/mglaman/phpstan-drupal/blob/master/.travis.yml#L19

@davidferlay
Copy link

davidferlay commented Apr 19, 2019

Roger that @mglaman

During further playing and when trying the cgr solution proposed by @cloudstrife602 (but outside of a Drupal project), I encountered another issue related to Composer :

Action

docker run -i -t skilldlabs/php:72 /bin/sh
/srv # composer global require consolidation/cgr
/srv # PATH="$(composer config -g home)/vendor/bin:$PATH"
/srv # cgr mglaman/drupal-check
/srv # ~/.composer/vendor/bin/drupal-check 

Or

docker run -i -t skilldlabs/php:72 /bin/sh
/srv # composer global require mglaman/drupal-check
/srv # ~/.composer/vendor/bin/drupal-check

fyi docker image used here includes php and composer

Observed result

Binary is not executed and return error message :

Composer autoload file not found.
You need to run 'composer install'.

Expected result

/srv # ~/.composer/vendor/bin/drupal-check should execute binary successfully, just like it is working when running another package (already installed in image) :

/srv # ~/.composer/vendor/bin/phpstan 
PHPStan - PHP Static Analysis Tool 0.11.5
(...)

Did I get something wrong ?
Any clue what is hapenning ?

@mglaman
Copy link
Owner Author

mglaman commented Apr 19, 2019

Because it had no idea how to load its autoloader

$composerAutoloadFile = __DIR__ . '/vendor/autoload.php';
if (file_exists($composerAutoloadFile)) {
    require $composerAutoloadFile;
} else {
    echo "Composer autoload file not found.\n";
    echo "You need to run 'composer install'.\n";
    exit(1);
}

This doesn't support the global install very well if you do not run the phar. So it needs to be updated to support loading the autoloader in global.

See https://github.com/mglaman/drupalorg-cli

if (file_exists(CLI_ROOT . '/vendor/autoload.php')) {
    require CLI_ROOT . '/vendor/autoload.php';
} elseif (file_exists(CLI_ROOT . '/../../autoload.php')) {
    // This would be the autoloader's location if the package is installed
    // globally.
    require CLI_ROOT . '/../../autoload.php';
} else {
    echo "Composer autoload file not found.\n";
    echo "You need to run 'composer install'.\n";
    exit(1);
}

@Sergey-Orlov
Copy link
Contributor

Sergey-Orlov commented Apr 25, 2019

Problem is not only in autoader here.

After fixing autoloader path #47, got next issue:
There is relative path in neon files, like https://github.com/mglaman/drupal-check/blob/master/phpstan/deprecation_testing.neon#L10
- ../vendor/mglaman/phpstan-drupal/extension.neon

So it cause error

  File '/root/.composer/vendor/mglaman/drupal-check/src/Command/../../phpstan/../vendor/mglaman/phpstan-drupal/extension.neon' is missing or is not readable.

@mglaman
Copy link
Owner Author

mglaman commented Apr 27, 2019

@Sergey-Orlov thanks. The PR #50 is now verifying your fix for the autoloader and confirming the .neon loading problems. I need to see if they could be more dynamically generated... or something.

@mglaman
Copy link
Owner Author

mglaman commented Apr 27, 2019

I just learned that Nette/DI supports .neon AND .php! Testing with dynamic .php files for returning vendor rules.

@mglaman
Copy link
Owner Author

mglaman commented Apr 27, 2019

I'm tagging a new release. This should fix global installs

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

Successfully merging a pull request may close this issue.

4 participants