How to force dev-dependencies from a dependency to also install with 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.
有没有办法在安装包时强制安装某个开发依赖项?
Is there any way to force a certain dev-dependency to also install when the package is installed?
推荐答案
这是不可能的.依赖关系可以是包正常工作所必需的(那么它应该在 require
部分并且它总是被安装),或者只需要 this package 的开发(然后它应该在 require-dev
部分,并且仅在包存储库为根时安装).两者之间没有任何东西.如果您的包需要此代码生成器依赖项来工作,那么它显然无法进入第一类(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).
通常在这种情况下,最好的解决方案是将这个包分成两个包:常规包和 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<添加新的依赖项/code> 包)和最终用户(如果他不想使用此代码生成器,他总是可以跳过安装
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).
这篇关于如何强制依赖项中的开发依赖项也与作曲家一起安装?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何强制依赖项中的开发依赖项也与作曲家一起安装?
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- Laravel 仓库 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01