【问题标题】:How to specify Composer install path?如何指定 Composer 安装路径?
【发布时间】:2012-08-06 16:13:35
【问题描述】:

我有这个定义:

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "symfony/sfGuardPlugin",
                "version": "4.0.2",
                "dist": {
                    "url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
                    "type": "tar"
                }
            }
        }
    ],
    "require": {
        "symfony/sfGuardPlugin": "4.0.*"
    }
}

我正在使用 Symfony 1,我想将它们安装在 plugins/sfGuardPlugin/ 上。如何指定?

【问题讨论】:

    标签: php symfony1 composer-php


    【解决方案1】:

    您似乎可以将vendor 目录定义为something else(在您的情况下为plugins):

    {
        "config": {
            "vendor-dir": "plugins"
        }
    }
    

    然后,您可以将包名重命名为内部没有级别目录,例如:

            "package": {
                "name": "sfGuardPlugin",
    

    所以,你的composer.json 应该是这样的:

    {
        "config": {
            "vendor-dir": "plugins"
        },
        "repositories": [
            {
                "type": "package",
                "package": {
                    "name": "sfGuardPlugin",
                    "version": "4.0.2",
                    "dist": {
                        "url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
                        "type": "tar"
                    }
                }
            }
        ],
        "require": {
            "sfGuardPlugin": "4.0.*"
        }
    }
    

    编辑

    使用这个配置,你会得到路径(这当然对symfony不好):

    plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/

    我找到了解决此composer.json 的方法:

    {
        "config": {
            "vendor-dir": "plugins"
        },
        "repositories": [
            {
                "type": "package",
                "package": {
                    "name": "sfGuardPlugin",
                    "version": "4.0.2",
                    "source": {
                        "url": "http://svn.symfony-project.com/plugins/sfGuardPlugin/",
                        "type": "svn",
                        "reference": "branches/1.3/"
                    }
                }
            }
        ],
        "require": {
            "sfGuardPlugin": "4.0.*"
        }
    }
    

    【讨论】:

    • 很好,我也可以以某种方式使提取的文件夹不像现在那么深:plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/,而不是我想要plugins/sfGuardPlugin
    • 是的,刚刚看到。我正在尝试使用不同的类型(而不是 tar)。
    • 这很好——所以他们毕竟还有一个存储库:)
    • 有没有办法只为某些特定的包指定供应商目录,而其他的保持默认?
    • 这是一个很好且经过研究的答案,但不要放弃 Adam's V.,因为它看起来更正式,哦,而且容易 ;-)
    【解决方案2】:

    您还可以使用composer/installers,这是一个带有“symfony1-plugin”包类型的多框架作曲家库安装程序。这是我的 composer.json 文件的样子,以便它安装 Symfony 1.4(在 lib/vendor 中)和在 (/plugins) 中的插件:

    {
        "config": {
            "vendor-dir": "lib/vendor"
        },
        "repositories": {
            "symfony": {
                "type": "package",
                "package": {
                    "name": "symfony/symfony1",
                    "version": "1.4",
                    "dist": {
                        "url": "https://github.com/symfony/symfony1/zipball/1.4",
                        "type": "zip"
                    }
                }
            },
            "sfResquePlugin" : {
                "type": "package",
                "package": {
                    "name": "devpips/sfResquePlugin",
                    "type": "symfony1-plugin",
                    "version": "0.1",
                    "dist": {
                        "url": "https://github.com/devpips/sfResquePlugin/zipball/master",
                        "type": "zip"
                    }
                }
            }
        },
        "require": {
            "composer/installers": "dev-master",
            "symfony/symfony1": "1.4",
            "devpips/sfResquePlugin":"0.1"
        }
    }
    

    【讨论】:

    • 我看不出这会如何指向/plugins - 你能详细说明一下吗?
    • @IsaacLubow,这将由composer-installers 包完成,因为symfony1 有一个插件:) 检查Symfony1Installer.php
    【解决方案3】:

    参见COMPOSER_VENDOR_DIR 环境变量。

    通过设置此变量,您可以让 Composer 将依赖项安装到供应商以外的目录中。

    如果您想在特定环境(例如 vagrant 或 docker)中覆盖它,您不希望它位于共享文件夹/卷中,这可能会有所帮助。

    正如 J0k 所说,composer.jsonconfig 部分中有 vendor-dir

    默认为供应商。如果需要,您可以将依赖项安装到不同的目录中。 $HOME 和 ~ 将替换为您在 vendor-dir 中的主目录路径以及下面的所有 *-dir 选项。

    【讨论】:

      猜你喜欢
      • 2014-05-06
      • 2013-10-08
      • 2012-11-03
      • 2018-12-21
      • 2017-08-25
      • 1970-01-01
      • 2015-05-07
      • 2021-12-16
      • 2016-12-05
      相关资源
      最近更新 更多