如何指定 Composer 安装路径?

2022-01-21 00:00:00 php symfony1 composer-php

我有这个定义:

{
    "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/ 上.如何指定?

I am using Symfony 1, and I'd like to install them on plugins/sfGuardPlugin/. How do I specify this?

推荐答案

看来你可以定义 vendor 目录为 其他东西(你的情况是plugins):

It seems that you can define the vendor dir to be something else (plugins in your case):

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

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

Then, you might rename the package name to not have a level dir inside, like:

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

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

So, your composer.json should look like this:

{
    "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不好):

Using this configuration, you will get the path (which is of course not good for symfony):

plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/

plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/

我找到了一个使用这个 composer.json 的解决方法:

I found a workaround with this 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.*"
    }
}

相关文章