如何在Composer中使用路径类型本地存储库 [英] How to use path type local repository with Composer

查看:40
本文介绍了如何在Composer中使用路径类型本地存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Composer来说还比较陌生,一直在寻找使用路径回购类型使用本地存储库的示例.我发现了几篇文章(例如这一篇关于主题的这个,但是当我尝试我最终得到的例子是这样的错误:

I am relatively new to Composer and have been looking for an example of using a local repository using the path repo type. I've found several articles (e.g. this one and this one on the topic, but when I try the examples I end up getting an error like:

The requested package myvendor/mylibrary could not be found in any version, there may be a typo in the package name.

所以我想我将为我正在尝试的事情创建一个超简单的示例,希望有人可以将我指向正确的方向.

So I thought I'd create a super-simple example of what I'm trying in hopes that someone can point me in the right direction.

我的示例应用程序的组织方式如下:

My sample app is organised as such:

├── app1
│   └── composer.json
├── app2
│   └── composer.json
└── libraries
    └── testlibrary
        ├── composer.json
        ├── TestService.php

libraries/testlibrary/composer.json 中的内容如下:

{
  "name": "myvendor/mylibrary",
  "version": "dev-master"
}

在每个应用程序文件夹(例如app1)中, composer.json 文件如下所示:

And within each of the app folders (e.g. app1) the composer.json file looks like this:

{
    "repositories": [
        {
            "type": "path",
            "url": "../libraries/testlibrary"
        }
    ],
    "require": {
        "myvendor/mylibrary": "*"
    }
}

如果有人对我做错的事情有任何建议,我将非常感激!

If anyone has any suggestion for what I'm doing incorrectly, I'd be very appreciative!

推荐答案

我找到了答案

I found an answer here

代替此:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "*"
    }
}

您应该这样写:

{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "dev-master"
    }
}

请注意 require 部分中从 * dev-master 的更改.

Note the change from * to dev-master in the require section.

这篇关于如何在Composer中使用路径类型本地存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆