私人作曲家包 - 没有找到有效的 composer.json

2022-01-21 00:00:00 package-managers php composer-php

我正在尝试使用 composer 加载我在 BitBucket 上托管的库,如 官方文档和这里,但不断收到以下错误:

I'm trying to load a library I have hosted on BitBucket using composer as explained both in the official documentation and here, but keep receiving the following error:

[ComposerRepositoryInvalidRepositoryException]
No valid composer.json was found in any branch or tag of [repository URL], could not load a package from it.

这是我的项目 composer.json:

Here is my project composer.json:

{
    "name": "Project name",
    "require": {
        "my-vendor/my-package": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url": [repository URL]
        }
    ]
}

这是我远程存储库中的 composer.json(显然找不到):

And here is the composer.json in my remote repository (that apparently can't be found):

{
    "name": "my-vendor/my-package",
    "version": "0.3",
    "autoload": {
        "psr-0": {
            "NS_": "src"
        }
    }
}

我应该提一下,两个 composer.json 文件都应该在根目录中.

I should mention that both composer.json files are in the root directory as they should be.

其他一些注意事项:

我还尝试了非作曲家包"方法,在我的项目 composer.json 中指定包信息,并从我的远程存储库中省略 composer.json,如 文档.这成功克隆了 master 分支,但随后导致以下错误:

I've also tried the "non-composer package" approach, whereby I specify the package information in my project composer.json, and omit the composer.json from my remote repository, as outlined in the documentation. This successfully clones the master branch but then results in the following error:

[RuntimeException]
Failed to execute git checkout "master" && git reset --hard "master"

fatal: Not a git repository (or any of the parent directories): .git

但是,包已按预期下载到/vendor,所以我不确定它为什么要再次尝试检查 master.

However, the package is downloaded to /vendor as expected, so I'm not sure why it's trying to checkout master again.

这不是我希望解决此问题的方式(因为我宁愿使用远程存储库中的 composer.json),但它可能有助于在其他地方发现问题.

This is not the way I wish to solve this problem (as I'd rather make use of a composer.json in the remote repository), but it might help identify an issue elsewhere.

感谢您的帮助.

编辑

我已经设法通过 HTTP 引用 package.json 来让它工作:

I've managed to get it working by referencing a package.json over HTTP:

"repositories": [
    {
        "type": "composer",
        "url": "http://localhost/packages.json"
    }
]

packages.json 看起来像:

The packages.json looks like:

{
    "packages": {
        "vendor/my-package": {
            "dev-master": {
                "name": "vendor/my-package",
                "version": "dev-master",
                "source": {
                    "url": [repository URL],
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    }
}

这是让它工作的唯一方法吗?如果我只打算使用一两个内部包,那么托管我自己的 packages.json 文件似乎有点矫枉过正.

Is this the only way to get this working? It seems a bit overkill to host my own packages.json file if I'm only going to be using one or two in-house packages.

不管怎样,这给了我之前提到的同样的 Git 错误.

Regardless, this is giving me the same Git error as I mentioned previously.

编辑 2

强制出错(无效的 SSH 密码)给出:

Forcing an error (invalid SSH passphrase) gives this:

[RuntimeException]
Failed to execute git clone "[repository URL]" "C:workspaceDFv3vendorvendor/my-package" && cd /D "C:workspaceDFv3vendorvendor/my-package" && git remote add composer "[repository URL]" && git fetch composer

所以我可以清楚地看到它在这里做什么.但是,似乎 在 这条命令运行它 cds 进入 .git 目录并尝试运行:

So I can clearly see what it's doing here. However, it seems after this command runs it cds into the .git directory and tries running:

git checkout "master" && git reset --hard "master"

大概是为了摆脱它拉出的作曲家实例.但是,它在错误的目录中运行它,我不知道为什么..

Presumably to get rid of the composer instance it pulled. However, it's running this in the wrong directory and I can't figure out why..

推荐答案

我已经设法通过在 HTTP 上引用 package.json 来让它工作:

I've managed to get it working by referencing a package.json over HTTP:

"repositories": [
    {
        "type": "composer",
        "url": "http://localhost/packages.json"
    }
]

所以 packages.json 文件看起来像:

so the packages.json file looks like:

{
    "packages": {
        "vendor/my-package": {
            "dev-master": {
                "name": "vendor/my-package",
                "version": "dev-master",
                "source": {
                    "url": [repository URL],
                    "type": "git",
                    "reference": "master"
                }
            }
        }
    }
}

<小时>

另外,我在命令提示符下的自动运行注册表项似乎干扰了作曲家的运行.


Also, its seems an autorun registry entry I had for command prompt was interfering with composer running.

请参阅:要求私有 git Bitbucket 存储库无法找到有效的 composer.json.

相关文章