简体   繁体   English

composer:有没有办法为包存储库指定首选项顺序?

[英]composer : is there a way to specify a preference order for package repositories?

I am working with a package vendorName/moduleName (a Magento extension) that is present on packagist and on firegento . 我正在使用packagistfiregento上的package vendorName/moduleName (Magento扩展)。

On my composer.json file, I have : 在我的composer.json文件中,我有:

"require": {
   ....................,
   ...................,
  "vendorName/moduleName":"*"
},
"repositories": [
  ......................,
  ....................,
  {
    "type": "composer",
    "url": "https://packages.firegento.com"
  }
],

As Composer is downloaded pre-configured to use packagist.org , the vendorName/moduleName is loaded from packagist . 由于Composer已预先配置为使用packagist.org ,因此vendorName/moduleName是从packagist加载的。

I would like to force vendorName/moduleName to be loaded from firegento . 我想强制从firegento加载vendorName/moduleName

I tried to add : 我试着添加:

"repositories": [
  {
    "packagist": false
  },

but then, composer will no more search in packagist : that's not what I want.(as there are usefull packages in packagist too...) 但是,作曲家将不再在packagist中搜索:这不是我想要的。(因为packagist中也有有用的包...)

I guess I could use 我想我可以用

composer config --global --unset repositories.packagist

and then 然后

composer config --global repositories.firegento composer https://packages.firegento.com
composer config --global repositories.packagist composer https://packagist.org

to add repositories in my prefered order (I'm not sure it works...). 以我的首选顺序添加存储库(我不确定它是否有效......)。

Is there a better/simpler way to achieve my purpose ? 有没有更好/更简单的方法来达到我的目的? I would prefer editing the composer.json more than running global config commands but it's maybe not possible. 我更喜欢编辑composer.json而不是运行全局配置命令,但它可能不可能。

Well, 好,

I think I found the answer here : 我想我在这里找到了答案:

Repository candidates are, in the end, only evaluated by their order of definition. 最终,存储库候选者仅按其定义顺序进行评估。 Packagist is internally added as the last one by definition (though you can disable that) to ensure local copies are always preferred, if allowed by resolver settings. 根据定义,Packagist在内部添加为最后一个(尽管您可以禁用它),以确保始终首选本地副本(如果解析器设置允许)。

That means that if I define the firegento repo in my composer.json , then composer will load the package vendorName/moduleName in firegento before packagist . 这意味着,如果我定义了firegento在我的回购composer.json ,然后作曲家将加载包vendorName/moduleNamefiregentopackagist I thought it was the opposite behaviour; 我认为这是相反的行为; I was wrong. 我错了。

Another helpfull comment here : 另一种有益的意见在这里

Order of repository definitions matters. 存储库定义的顺序很重要。 But composer will still search through all repositories regardless, because it could be that a repository that is defined later has a more recent version available of the package you are requiring. 但是,无论如何,作曲家仍将搜索所有存储库,因为它可能是稍后定义的存储库具有您需要的更新版本的软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM