如何强制开发依赖项从依赖项也与composer一起安装? [英] How to force dev-dependencies from a dependency to also install with composer?

查看:58
本文介绍了如何强制开发依赖项从依赖项也与composer一起安装?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个程序包(cms),该程序包与特定程序包(代码生成器)的开发依赖关系来创建代码.生产中不需要此软件包.

I'm currently working on a package (cms), which has a dev-dependency to a certain package (code-generator) to create code. This package is not needed in production.

但是,在创建使用cms软件包的网站时,未安装开发依赖项(包括代码生成器)(顺便说一句,这是正确的作曲家行为).

However, when creating a website that uses the cms package, dev-dependencies (including the code-generator) are not installed (which is correct composer behavior btw).

但是在开发网站时,需要代码生成器.

But while developing the website, the code-generator is required.

在安装软件包时,是否有任何方法可以强制某些dev-dependency也要安装?

Is there any way to force a certain dev-dependency to also install when the package is installed?

推荐答案

这是不可能的.可能需要依赖才能使程序包正常工作(然后应在 require 部分中并始终将其安装),或者仅对于开发此程序包(然后它应该在 require-dev 部分中,并且仅在软件包存储库为root时安装.两者之间没有任何关系.如果您的程序包要求此代码生成器依赖性工作 ,则显然不能进入第一类( require 部分).

This is not possible. Dependency can either be required for the package to work properly (then it should be in require section and it is always installed), or required only for development of this package (then it should be in require-dev section and is installed only when package repository is root). There is nothing in between. If this code-generator dependency is required by your package to work it clearly fails into first category (require section).

通常,在这种情况下,最好的解决方案是将此程序包分为2个程序包:常规程序包和 dev 程序包,并且所有工具仅在开发过程中使用.因此,应通过2个命令进行安装:

Usually in this case the best solution is to split this package into 2 packages: regular package and dev package with all tools used only during development process. So it should be installed by 2 commands:

composer require myvendor/mypackage
composer require myvendor/mypackage-dev --dev

这仍然需要每个人都安装两个软件包而不是一个软件包,但是,如果有正确的文档记录,这应该不是什么大问题.结果应该更清楚( myvendor/mypackage-dev 软件包的目的是什么)并为软件包所有者提供更多控制权(他可以轻松地为 dev 包)和最终用户(如果他不想使用此代码生成器,他总是可以跳过安装 myvendor/mypackage-dev ).

This will still require everyone to install two packages instead of one, but it should not be a big problem if it is properly documented. Result should is more clear (it should be quite obvious what is the purpose of myvendor/mypackage-dev package) and gives more control to package owner (he can easily add new dependencies for dev package) and end user (he can always skip installing myvendor/mypackage-dev if he don't want to use this code generator).

这篇关于如何强制开发依赖项从依赖项也与composer一起安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆