Jenssen
Jenssen

Reputation: 1871

Composer install package with dev dependencies

How do I install a composer package with dev dependencies?

So for example:

When I have this package:

https://github.com/spatie/laravel-demo-mode

And I run:

composer require spatie/laravel-demo-mode

The tests folder is not installed?!

Upvotes: 1

Views: 2792

Answers (1)

Kyslik
Kyslik

Reputation: 8385

In short you don't (ever). If you want to contribute, you need to set up new Laravel project and set up composer to autoload your version of package, either from your fork or from somewhere on your disk. And when you do that you are just using your version of the package (again without the possibility to run packages's tests).

In order to run tests of the package you need to change directory to the root of the package and install its dependencies ($ composer install), after you've done that you may run $ phpunit.


What I am usually doing in when I want to contribute is:

  • have empty Laravel project ready (unversioned)
  • have packages folder in root
  • in that packages folder I usually do $ git clone <repo fork> (It may be more than one package at once)
  • in case I want to run package's tests I do $ composer install and $ phpunit (your IDE may squeak at you about duplicate definitions but you may ignore it)
  • improve and test the code of package in packages folder
  • test your changes "live" on Laravel project right-away

composer.json may look like:

...
"autoload": {
    "classmap": [
        "database/seeds",
        "database/factories"
    ],
    "psr-4": {
        "App\\": "app/",
        "Vendor\\Package\\": "packages/path-to-src/"
    }
},
...

You may find useful this example repo I use https://github.com/Kyslik/column-sortable-example to demonstrate how to work with package I maintain. Mainly take a look at folder structure and composer.json.

There may be better ways on how to do contributing but I have only found (and developed) this one.


If I have small changes in mind (like typo, or just return type or whatever is "small") I do change package within vendor folder, and see if it breaks anything; after that I fork package source and edit the change right in the Github's web interface. To clean up just run $ composer install/update from root folder of your Laravel project.

Upvotes: 3

Related Questions