2

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?

Miura-shi
  • 4,409
  • 5
  • 36
  • 55
  • have you tried composer update ? – Leo Aug 24 '17 at 20:12
  • Do you already have a composer.lock file? When you composer install, the composer.lock file is used to pull dependencies. Sounds like you need to composer update? In fact anytime you change anything in the composer.json file, you need to composer update. – gview Aug 24 '17 at 20:15
  • That is correct, the root application does already have a composer.lock file. Should I delete the lock file and run composer update again? – Miura-shi Aug 24 '17 at 20:16
  • No just run composer update. It overwrites the existing one. You should then push the new composer.lock file, so in the future you run composer install. – gview Aug 24 '17 at 20:16
  • Okay I ran composer update and says nothing to install or update. So it is still not seeing the required dependencies in my local package. – Miura-shi Aug 24 '17 at 20:17
  • Please see this answer I provided a while back. You [might find it helpful](https://stackoverflow.com/questions/22104102/do-you-have-to-run-composer-on-localhost-and-on-production/22106489#22106489). – gview Aug 24 '17 at 20:18

1 Answers1

6

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.

Miura-shi
  • 4,409
  • 5
  • 36
  • 55