Laravel没有安装Laravel Distro软件包的require-dev软件包

时间:2019-04-23 14:02:38

标签: php laravel composer-php

我用我所有网站使用的所有Laravel软件包创建了一个Laravel发行版软件包。 我还创建了一个使用此发行包的自定义Laravel网站。

不幸的是,当我在第二个composer文件上运行composer install --dev时,它不会安装laravel-distro composer软件包中的require-dev软件包,例如phpunit / phpunit

Laravel发行版作曲家配置:

$ 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示例作曲家配置:

$ 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"
    }
}

您可以看到此处缺少require-dev软件包。

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 个答案:

答案 0 :(得分:2)

这不是故意的。

由于这些软件包位于第一个基本package.json文件的require-dev部分中,因此只有在该软件包上运行composer install时,才会安装该软件包。

当您将该软件包拉入另一个项目时,composer只会从软件包中安装require-dev之外的那些依赖项。

这是因为require-dev仅用于开发该程序包,不应要求将其用于其他用途。如果您在使用基本软件包时需要安装这些软件包,则必须将它们放在require中,而不要放在require-dev中。