composer config 添加不带名称的存储库位置

composer config add repository location without the name

有没有什么方法可以使用 composer CLI 命令将存储库位置添加到 composer.json 但不说明其名称?

你可以这样做:

composer config repositories.<name> vcs /path/to/the/repository

但我有兴趣在不指定名称的情况下添加存储库位置。

由于可以在 composer.json 中添加存储库的位置而无需名称:

{
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }
    ],
    "require": {
        "monolog/monolog": "dev-bugfix"
    }
}

我有兴趣添加这样的条目:

        {
            "type": "vcs",
            "url": "https://github.com/igorw/monolog"
        }

通过使用 composer CLI 但命令:

composer config repositories vcs /path/to/the/repository

失败。

你知道怎么做吗?

目前还不能。如果您查看解析 repositories 参数(或 repo/repos)的正则表达式:

// handle repositories
if (preg_match('/^repos?(?:itories)?\.(.+)/', $settingKey, $matches)) {

https://github.com/composer/composer/blob/1.7.2/src/Composer/Command/ConfigCommand.php#L535

您看到它需要 repositories.name 格式。我的猜测是,如果您还没有定义存储库,匿名添加它们会很好,但如果您开始尝试命名其中的一些存储库,它就会中断。另外 unset 命令不会起作用,因为你没有给它命名,并且 运行 命令重复会继续添加它们。

我的猜测是,不支持这一点是故意的。不过,您始终可以在存储库上打开一个问题来请求它。

我找不到这样做的方法。我只是手动添加它(没有 cli 工具)。我确实尝试使用 composer config repositories._ vcs /url。它有效,但它显然将名称设置为“_”。然后你可以进去删除它。但是,如果您仍然这样做,您也可以手动添加它。