0

I have created a Laravel distro package with all Laravel packages that all of my websites use. I've also created a custom Laravel-website that uses this distro package.

Unfortunately when I run composer install --dev on the 2nd composer file, it won't install the require-dev packages from the laravel-distro composer package, e.g. phpunit/phpunit

Laravel-distro composer configuration:

$ cat laravel-distro/composer.json
{
    "name": "dennis00/laravel-distro",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.8.*",
        "laravel/tinker": "^1.0",
        "laravel/installer": "^2.0.1"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.5"
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "vendor-dir": "vendor",
        "sort-packages": true
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "autoload": {
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\\": "tests/"
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

Laravel-example composer configuration:

$ cat laravel-example/composer.json
{
    "name": "dennis00/laravel-example",
    "description": "Example of Laravel Distro",
    "type": "project",
    "license": "GPL-2.0+",
    "minimum-stability": "dev",
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "require": {
        "dennis00/laravel-distro": "dev-master@dev",
        "laravel/horizon": "^4.0@dev"
    }
}

You can see the require-dev packages are missing here.

root@f506ece6f4ea:/var/www/html# ls vendor
autoload.php  cakephp dennis00  doctrine   egulias  fideloper   jakub-onderka  laravel  monolog  nette  ocramius  paragonie  phpstan  psy        ramsey     symfony   vlucas
bin       composer  dnoegel   dragonmantank  erusev   guzzlehttp  jean85       league   nesbot   nikic  opis  phpoption  psr      ralouphie  swiftmailer  tijsverkoyen

root@f506ece6f4ea:/var/www/html# ls vendor_backup/
autoload.php  bin dnoegel   dragonmantank  erusev     filp  hamcrest       laravel  mockery  myclabs  nikic       opis   phar-io  phpoption  phpunit  psy     sebastian  symfony  tijsverkoyen  webmozart
beyondcode    composer  doctrine  egulias  fideloper  fzaninotto  jakub-onderka  league monolog  nesbot   nunomaduro  paragonie  phpdocumentor  phpspec    psr      ramsey  swiftmailer  theseer  vlucas
root@f506ece6f4ea:/var/www/html#

1 Answer 1

2

It won't, this is intentional.

As the packages are in the require-dev section of the first base package.json file, this will only be installed if you are running composer install on that package.

As you are pulling that package into another project, composer will only install those dependencies from the package that are not within require-dev.

This is because require-dev is only for the development of that package and should not be required to use the package in something else. If you need these packages to be installed when you are using your base package, then you must put them in require and not require-dev.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.