How to specify Composer install path?

谁说我不能喝 提交于 2019-11-26 10:16:28

问题


I have this definition:

{
    \"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.*\"
    }
}

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


回答1:


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",

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.*"
    }
}

Edit

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

plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/

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.*"
    }
}



回答2:


You can also use composer/installers, a multi-framework composer library installer with the "symfony1-plugin" package type. This is what my composer.json file looks like, in order for it to install both Symfony 1.4 (in lib/vendor) and plugins in (/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"
    }
}



回答3:


See COMPOSER_VENDOR_DIR environment variable.

By setting this var you can make Composer install the dependencies into a directory other than vendor.

Can be helpful in the case you want to override this in a particular environment such as vagrant or docker where you wouldn't want this to be in a shared folder / volume.

And as J0k said, there's vendor-dir in config section of composer.json

Defaults to vendor. You can install dependencies into a different directory if you want to. $HOME and ~ will be replaced by your home directory's path in vendor-dir and all *-dir options below.



来源:https://stackoverflow.com/questions/11883374/how-to-specify-composer-install-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!