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

composer show --direct with a specific package should exit with an error #11728

Closed
soullivaneuh opened this issue Nov 24, 2023 · 2 comments
Closed
Labels
Milestone

Comments

@soullivaneuh
Copy link
Contributor

With the given composer.json:

{
    "type": "project",
    "require": {
        "slevomat/coding-standard": "^8.14"
    },
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    }
}

The compose show command displays the following:

dealerdirect/phpcodesniffer-composer-installer v1.0.0 PHP_CodeSniffer Standards Composer Installer Plugin
phpstan/phpdoc-parser                          1.24.3 PHPDoc parser with support for nullable, intersection and generic types
slevomat/coding-standard                       8.14.1 Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with a...
squizlabs/php_codesniffer                      3.7.2  PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding stand...

With the --direct option:

slevomat/coding-standard 8.14.1 Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

If we specify a not installed package to the composer show command, like composer show not/existent, we got the following error:

In ShowCommand.php line 300:
                                                                                                
  Package "not/existent" not found, try using --available (-a) to show all available packages.  

And the command exit with an error code.

I would like to combine this behavior in combination with the --direct option to ensure a package is installed and required by the root package itself.

However, if I try with composer show --direct squizlabs/php_codesniffer, which is installed but not explicitly required, the commands successfully display the package information instead of exiting with an error code.

I would like an option to ensure a package is directly required by the root package and make the command throwing an error otherwise, like the sample above.

What do you think about this idea?

Regards

@fredden
Copy link
Contributor

fredden commented Dec 21, 2023

@soullivaneuh you may be interested in https://github.com/maglnet/ComposerRequireChecker. It's a tool that helps ensure that dependencies are declared properly. I can't quite tell from the description you have provided if this meets your needs or not. Why are you trying to work out if a particular package is listed as a direct dependency for a project?

@Seldaek Seldaek added this to the 2.7 milestone Dec 22, 2023
@Seldaek
Copy link
Member

Seldaek commented Dec 22, 2023

Sounds reasonable to me to fix this behavior. It was just not considered I believe because if the package is there we just show it, and direct is only used for listing right now, but it wouldn't hurt to check for directness when requesting a single package IMO. If you like to PR it..

@Seldaek Seldaek modified the milestones: 2.7, Nice To Have Dec 22, 2023
@Seldaek Seldaek modified the milestones: Nice To Have, 2.7 Jan 11, 2024
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

4 participants
@Seldaek @fredden @soullivaneuh and others