douhuifen9942
2014-04-27 21:49
浏览 108
已采纳

为什么Composer安装不同的包?

I've been working with the Magento Firegento custom Composer installer, and I ran into this odd bit of Composer behavior I don't understand.

Consider the following dead simple composer.json file

{
    "require": {
        "magento-hackathon/magento-composer-installer": "*"
    }
}

If I run compser.phar install with this composer.json file, I get the following.

$ composer.phar install --no-dev 
Loading composer repositories with package information
Installing dependencies
  - Installing aoepeople/composer-installers (v0.0.1)
    Loading from cache

Writing lock file
Generating autoload files

From my mostly lay-person's understanding composer.phar, I've said

Hey, composer, please install the magento-hackathon/magento-composer-installer package from packagist.org

And composer has said back to me

Sir, yes sir! Here's the aoepeople/composer-installers package

I don't understand why composer installed aoepeople/composer-installers, when I asked for magento-hackathon/magento-composer-installer.

To be clear: I understand the reason magento-hackathon/magento-composer-installer wasn't installed is this is a package that lives in a different composer repository. My original mistake was not including this repository in my composer.json file.

However, it doesn't make sense to me that composer would install a different package than the one I asked for. When I search packagist there's no magento-hackathon/magento-composer-installer extension.

Why does packagist install a different extension? What's happening behind the scenes to make magento-hackathon/magento-composer-installer resolve to aoepeople/composer-installers? How/where in the composer source could I debug this sort of thing myself in the future?

图片转代码服务由CSDN问答提供 功能建议

我一直在使用Magento Firegento自定义Composer安装程序,我遇到了这个奇怪的Composer行为我 不明白。

考虑以下死的简单 composer.json 文件

  {
“ 要求“:{
”magento-hackathon / magento-composer-installer“:”*“
} 
} 
   
 
 

如果我运行 使用此 composer.json 文件进行compser.phar安装,我得到以下内容。

  $ composer.phar install --no-dev 
使用包信息加载编写器存储库
安装依赖项
  - 安装aoepeople / composer-installers(v0.0.1)
 从缓存中加载
 
写入锁定文件
生成自动加载文件
   
 
 

从我大多数人的理解 composer.phar ,我' 我说

嘿,作曲家,请从packagist.org安装 magento-hackathon / magento-composer-installer

作曲家回复我说了

先生,是的,先生! 这是 aoepeople / composer-installers

我不明白为什么作曲家安装 aoepeople / composer-installers ,当我要求 magento-hackathon / magento-composer-installer

要明确:我理解 magento-hackathon /的原因 未安装magento-composer-installer 这是一个包含在不同作曲家存储库。 我最初的错误是不在我的 composer.json 文件中包含此存储库。

但是,这对我来说没有意义 那个作曲家会安装一个不同于我要求的包。 当我搜索包时,没有 magento-hackathon / magento-composer -installer 扩展名

为什么packagist会安装不同的扩展程序? 幕后发生了什么使 magento-hackathon / magento-composer-installer 解析为 aoepeople / composer-installers ? 我将来如何/在作曲家来源中调试这种事情?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongnuo4594 2014-04-27 22:18
    已采纳

    Vinai published a great writeup on Magento and Composer here.

    Quoting from there

    Composer will use packagist.org to look where to get the libraries. Because Magento modules aren’t listed there, you will have to add the packages.firegento.org repository to the configuration as follows [...]

    So you will need the repository

       "repositories":[
         {
           "type":"composer",
           "url":"http://packages.firegento.com"
         }
       ],
    

    to get the magento composer installer.

    And yes composer offers replacements. On the packaging entry for aoepeople/composer-installers you will notice the replaces section:

    Package Screenshot

    And since magento-hackathon/magento-composer-installer is not available on packagist composer will deliver you aoepeople/composer-installers.

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • drzdu44226 2014-04-27 22:16

    The Packagist package at https://packagist.org/packages/aoepeople/composer-installers has metadata saying that it replaces the magento-hackathon/magento-composer-installer package. Packagist would then install this as it's the package that replaces what you asked for.

    Docs here: https://getcomposer.org/doc/04-schema.md#replace

    评论
    解决 无用
    打赏 举报
  • dongpo1599 2014-04-28 05:59

    OK, so that's a weird behavior :) I'm the author of the aoepeople/composer-installers package and the idea behind this is that this package provides an alternative (very basic and simplified implementation of the composer package-type magento-module - and adds another type magento-source. I only want the installer to put the package in the right place - keeping it simple. That's why I decided to come up with an alternative package.

    The reason why the aoepeople/composer-installer replaces the magento-hackathon/magento-composer-installer is because many Magento modules already come with a composer.json that requires the magento-hackathon/magento-composer-installer. In order to be able to seamlessly use the simpler installer that one is "pretending" to be the hackathon-installer. But unless you actively require aoepeople/composer-installers in your project's composer.json you should continue using the original installer as no Magento module's composer.json out there (not even ours) is directly referring to aoepeople/composer-installers.

    The fact that packagist tries to be "smart" and returns a package that replaces a package that's not registered is new to me and - to be honest - very disturbing. While this might be intended behavior I share the opinion that this could easily be abused. I start liking Alan's idea to bypass packagist completely using "packagist":"disabled". Especially in the case of Magento modules this seems to happen easily because most of the Magento modules are unknown to packagist while being registered at packages.firegento.com only.

    A simple quickfix/workaround to this specific situation could be to register magento-hackathon/magento-composer-installer on packagist.org.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题