composer prefer-dist 和 prefer-source 之间的区别?区别、prefer、composer、source

2023-09-06 15:57:50 作者:不信命只信双手去苦拼

查看PHP Composer的install命令的帮助,看到以下两个选项

Looking at the help for PHP Composer's install command, I see the following two options

$ composer help install
Options:
 --prefer-source            Forces installation from package sources when possible, including VCS information.
 --prefer-dist              Forces installation from package dist even for dev versions.

什么是dist"安装?我浏览了作曲家网站和谷歌,但似乎没有任何东西可以解决这个问题(所以我认为这对于熟悉 Composer 的人来说是核心和显而易见的——为新手问题道歉)

What's a "dist" installation? I poked around the composer site and Google but there didn't seem to be anything that addressed this (So I assume it's something core and obvious to folks familiar with Composer — apologies for the newbie question)

我假设 --prefer-source 是 Composer 向 Packagist 询问存储库位置的位置,然后是 checkout/clone/export/etc.项目本身.

I'm assuming --prefer-source is where Composer will ask Packagist for the repository location, and then checkout/clone/export/etc. the project itself.

如果是这样,那么 --prefer-dist 从哪里下载?它下载什么?

If so, then where does --prefer-dist download from? What does it download?

推荐答案

根据http://getcomposer.org/doc/03-cli.md,--prefer-source 选项将更喜欢创建一个包目录,它是一个版本控制存储库".这相当于您输入:

According to http://getcomposer.org/doc/03-cli.md, the --prefer-source option will prefer to create a package directory that is a "version control repository". This is equivalent to you typing:

$ git clone ...

$ svn checkout ...

--prefer-dist 选项会优先创建一个非版本控制存储库",相当于你输入:

The --prefer-dist option will prefer to create a non-"version control repository", which is equivalent to you typing:

$ git clone ... ; rm -fr dir/.git

$ svn export ...

此外,您可以在 composer.json 中为 sourcedist 定义单独的 repos.这是一个例子:

Also, you can define separate repos for source and dist in your composer.json. Here's an example:

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "joshuaclayton/blueprint-css",
                "version": "master",
                "source": {
                    "url": "git://github.com/joshuaclayton/blueprint-css.git",
                    "type": "git",
                    "reference": "master",
                }
            }
        },
        {
            "type": "package",
            "package": {
                "name": "fiftyone/mobi-lite-php",
                "version": "2013.03.06",
                "dist": {
                    "url": "http://iweb.dl.sourceforge.net/project/fiftyone/51Degrees.mobi-Lite-2013.03.06.php.zip",
                    "type": "zip"
                },
            }
        }
    ]
}

注意:无论出于何种原因,当我使用 --prefer-dist 时,有时会出现诸如

NOTE: for whatever reason, when I use --prefer-dist, I sometimes get errors such as

Fatal error: Cannot redeclare class Zend_Db_Adapter_Pdo_Abstract in ...

当我使用 --prefer-source 时不会出现.出于这个原因,我只使用--prefer-source,直到我找出这个问题的原因.

which do not appear when I use --prefer-source. For this reason, I only use --prefer-source, until I figure out the cause of this issue.