通过 Github fork 加载 Composer 包

10

我在Github上fork了一个库,现在想将我的fork加载到项目中,而不将forked库添加到packagist中。在我的composer.json文件中添加仓库和依赖后,我遇到了以下错误:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package cnizzardini/ssl-certificate could not be found in any version, there may be a typo in the package name.

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.

这是我的完整composer.json文件:

{
    "name": "cakephp/app",
    "description": "CakePHP skeleton app",
    "homepage": "http://cakephp.org",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=5.5.9",
        "cakephp/cakephp": "~3.4",
        "mobiledetect/mobiledetectlib": "2.*",
        "cakephp/migrations": "~1.0",
        "cakephp/plugin-installer": "*",
        "guzzlehttp/guzzle": "^6.2",
        "donatj/phpuseragentparser": "^0.7.0",
        "cnizzardini/ssl-certificate": "dev-master"
    },
    "require-dev": {
        "psy/psysh": "@stable",
        "cakephp/debug_kit": "~3.2",
        "cakephp/bake": "~1.1",
        "phpunit/phpunit": "^5.5"
    },
    "suggest": {
        "phpunit/phpunit": "Allows automated tests to be run without system-wide install.",
        "cakephp/cakephp-codesniffer": "Allows to check the code against the coding standards used in CakePHP."
    },
    "autoload": {
        "psr-4": {
            "App\\": "src",
            "Api\\": "./plugins/Api/src",
            "Channel\\": "./plugins/Channel/src",
            "System\\": "./plugins/System/src",
            "Admin\\": "./plugins/Admin/src"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Test\\": "tests",
            "Cake\\Test\\": "./vendor/cakephp/cakephp/tests",
            "Api\\Test\\": "./plugins/Api/tests",
            "Channel\\Test\\": "./plugins/Channel/tests",
            "System\\Test\\": "./plugins/System/tests",
            "Admin\\Test\\": "./plugins/Admin/tests"
        }
    },
    "scripts": {
        "post-install-cmd": "App\\Console\\Installer::postInstall",
        "post-create-project-cmd": "App\\Console\\Installer::postInstall",
        "post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/cnizzardini/ssl-certificate.git"
        }
    ],
    "minimum-stability": "stable",
    "prefer-stable": true
}

我尝试过添加 https://github.com/cnizzardini/ssl-certificate,包括加上.git和不加.git。我也尝试将minimum-stability设置为dev,prefer-stable设置为false。
但是,所有尝试都失败了 :-(

可能是如何使用Composer要求分支的重复问题。 - rickdenhaan
接近了,但我需要的修复略有不同。我需要引用我的分支。 - cnizzardini
1个回答

12
你的分支上的 composer.json 文件仍然调用了包名为"spatie/ssl-certificate"的包,因此这就是你需要引用的包名。
以下代码应该可以正常工作:
{
    ...
    "require": {
        ...
        "spatie/ssl-certificate": "dev-master"
    },
    ...
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/cnizzardini/ssl-certificate.git"
        }
    ],
    ...
}

如果不行,您可以通过更改其composer.json文件中的name属性,在您自己的存储库中重命名软件包:

{
    "name": "cnizzardini/ssl-certificate",
    "description": "A class to easily query the properties of an ssl certificate ",
    ...
}

现在已经拉取了spatie/ssl-certificate。我想要我的分支:cnizzardini/ssl-certificate。 - cnizzardini
2
如果这行不起作用,您可以尝试在您的 fork 的 composer.json 文件 中更改包名称。 - rickdenhaan
那个可以,如果你更新你的答案,我会接受它作为正确的。 - cnizzardini
1
我接受了,我会更改解决方案,只需说明我需要在分支中更改包名称以匹配我的composer.json文件中的引用,以便其他人不会感到困惑。谢谢。 - cnizzardini

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接