Miura-shi
Miura-shi

Reputation: 4519

Composer not installing local package dependencies

In my Laravel 5.4 composer.json file I have the following that autoloads my custom package. Note, that this package is not published and is being loaded locally.

"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/",
        "Vendor\\Module\\": "packages/vendor/module/src"
    }
},

And then in my package composer.json file I have the following

{
    "name": "vendor/module",
    "description": "A custom package",
    "version": "1.0.0",
    "type": "project",
    "authors": [
    ],
    "minimum-stability": "dev",
    "require": {
      "laravelcollective/html": "^5.4.0"
    }
}

However, when I run composer install from the root Laravel directory, it never picks up the laravelcollective/html package that I am requiring.

Is there a way to load in dependencies on a local package that is not published?

Upvotes: 2

Views: 4410

Answers (1)

Miura-shi
Miura-shi

Reputation: 4519

I believe I found a solution, all though it may not be the best method for local package development it is working for me.

In the root composer.json file, I added the following and running a composer update from the root of the application seems to now pick up the package and it's dependencies and installs everything into the main vendor directory of the root application.

"repositories": [
    {
        "type": "path",
        "url": "packages/vendor/module"
    }
],
"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "~5.7",
    "vendor/module": "1.0.*"
},
"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/",
        "Vendor\\Module\\": "packages/vendor/module/src"
    }
},

The good thing about this method is it creates a symbolic link only for the custom package, thus you can continue to write updates in the packages directory and the changes will take affect instead of having to commit to your local git repository if you set the type to vcs in the repositories field of the composer.json.

I also had to specify in the require-dev field the version number so that it passes the version constraint, otherwise you would get a warning that the package does not meet the minimum version requirements when running composer.

Upvotes: 6

Related Questions