Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer ignoring zip dependecies' composer.json file

I'm using Composer for a project that needs to handle some dependencies but I got a really weird issue. Composer is ignoring the composer.json file contained in child packages.

My project needs to retrieve some custom zip packages, in these packages a composer.json file defines other requirements. The repositories of these requirements are declared in the root composer.json file since Composer cant recursively fetch repositories.

The thing is that after my zip package is downloaded, unpacked and placed in the vendor dir, composer totally ignores its composer.json where other requirements are defined...

The zip archive is something like this:

  • /dir1
  • /dir2
  • file1
  • file2
  • composer.json

To give you an idea this is how my root composer.json looks like:

{
    "name": "myproject/project",
    "type": "library",
    "repositories": [    
        {
        "packagist" : false 
        },
        {
             "type": "package", 
             "package": {
                 "name" : "giulianobundles/mybundle",
                 "version" : "1",
             "dist": {
                "url": "http://url/to/zip/file",
                     "type": "zip"
                 }
             }
        },
        {
            "type": "package", 
            "package": {
                "name" : "giulianobundles/mybundlerequirement",
                "version" : "1",
        "dist": {
                    "url": "http://url/to/zip/file",
                "type": "zip"
        },
        }
    },  
    ],
    "require": {
        "php": ">=5.3.2",
         "giulianobundles/mybundle": "*"             
    },
    "autoload": {
        "psr-0": {
            "config": "./"
        }
    },
}

and the bundle's composer.json package looks like

{
    "name": "giulianobundles/mybundle",
    "type":"library",
    "require": {
        "giulianobundles/mybundlerequirement": "1"
    }
}

Mybundle package get succesfully installed but its composer.json file is totally ignored. Any idea? What am I missing?

like image 410
Giuliano Iacobelli Avatar asked Feb 22 '13 11:02

Giuliano Iacobelli


People also ask

Where is my composer JSON file?

composer. json is a JSON file placed in the root folder of PHP project.

How do I run composer with composer json?

To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.


1 Answers

Indeed, Composer will not recursively look at composer.json files in the file system. It needs to see the composer.json files in the repository. The way it usually works is that a package has a git or svn URL somewhere. Composer will fetch, for instance, git://<host>/<package>/composer.json directly from the repository to figure out that package's dependencies before it's even installed to calculate the overall dependencies.

In your case, you are defining a package inline in your own composer.json file. This is used instead of a composer.json file in the dependency. This means Composer takes the "package": { ... } to be the canonical composer.json file for that package, it will not look into the code itself; especially not after unpacking it. It treats the Zip file as if it had no composer.json file of its own.

Define the dependencies in the "package": { ... } or host the code in a version control system from which Composer can fetch the composer.json file.

like image 82
deceze Avatar answered Oct 05 '22 13:10

deceze