如何强制依赖项中的开发依赖项也与作曲家一起安装?

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).

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)