Jump to content

composer: dependences and dependents


block34
 Share

Recommended Posts

$ cat .composer/config.json
{
    "repositories": {
        "a": {
            "type": "path",
            "url": "repo/a"
        },
        "b": {
            "type": "path",
            "url": "repo/b"
        },
        "c": {
            "type": "path",
            "url": "repo/c"
        }
    }
}
$ cat repo/a/composer.json
{
    "name": "my/a",
    "require": {
        "my/b": "dev-master"
    }
}
$ cat repo/b/composer.json
{
    "name": "my/b",
    "require": {
        "my/c": "dev-master"
    }
}
$ cat repo/c/composer.json
{
    "name": "my/c"
}


How do you see

my/a requires my/b
my/b requires my/c

But I wanted to know if there is a way to view *quickly* the whole structure of dependences.
Above all, I would like to know the *dependents*.

I tried like this
 

$ COMPOSER_HOME=.composer composer show -a my/b
No composer.json found in the current directory, showing available packages from a, b, c, packagist.org
name     : my/b
descrip. :
keywords :
versions : dev-master
type     : library
homepage :
source   : []
dist     : [path] repo/b 6de0f9e677dcab7051f94dbbf05893d0165bb826
names    : my/b

requires
my/c dev-master


In summary
 

$ COMPOSER_HOME=.composer composer show -a my/b \
  | grep my/
No composer.json found in the current directory, showing available packages from a, b, c, packagist.org
name     : my/b
names    : my/b
my/c dev-master


It tell me that

my/b requires my/c

but it doesn't tell me that

my/b is required from my/a (this is the thing that interests me most).

For example, if I have to remove a package (obsolete package), how can I verify that it does not have dependents?

Link to comment
Share on other sites

$ COMPOSER_HOME=.composer composer show -t 
Composer could not find a composer.json file
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
compose

 

Link to comment
Share on other sites

Why should require my/a package?

I don't want to request/download/install anything.

Let's pretend I don't know anything.
Let's pretend I only know that the my/b package exists (I don't want to request/download/install).
Let's pretend I just want to know which packages use the my/b package.

Can it be?

Link to comment
Share on other sites

You need to download dependencies to analyze them, since what dependencies you get can depend on the environment you're project is installed into.  So you need to start with a project that requires packages that you want.  Trying to analyze dependencies without a project doesn't really make sense.

If for some reason you don't want to make a project but want to know what packages my/b depends on, you can download my/b and run composer show -t within it's directory.  Every package is a composer project with it's own composer.json that defines it's details.

There's no way at all to get a list of which packages are dependent on my/b since doing so would require scanning every project ever created by every person on the planet.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.