How to force Composer to download a local package?(如何强制 Composer 下载本地包?)
问题描述
假设我们有以下目录结构,我们假设 my-package 也存在于 Packagist:
Let's say we have the following directory structure, we assume my-package also exists on Packagist:
- apps
\_ my-app
  \_ composer.json
- packages
\_ my-package
  \_ composer.json
要将 my/package 添加为 my-app 的依赖项,文档声明我们可以使用以下配置:
To add my/package as a dependency of my-app, the documentation states we can use the following configuration:
{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package"
        }
    ],
    "require": {
        "my/package": "*"
    }
}
但是,当我 composer update 时,依赖项仍然是从 Packagist 下载的.所以,看看,我禁用了 Packagist.org:
However when I composer update, the dependency is still downloaded from Packagist. So, to see, I disabled Packagist.org:
{
    "repositories": [
        {
            "type": "path",
            "url": "../../packages/my-package",
            "packagist.org": false
        }
    ],
    "require": {
        "my/package": "*"
    }
}
我使用 composer clearcache 清除缓存,使用 composer remove my/package 删除 my/package 并使用  再次安装composer require my/package --prefer-source (我不明白 --prefer-source 是否仅适用于 vcs).下载的包还是不是本地的.如何强制作曲家使用本地的?
I cleared the cache with composer clearcache, removed my/package with composer remove my/package and installed it again with composer require my/package --prefer-source (I didn't understand if --prefer-source is for vcs only). The downloaded package is still not the local one. How to force composer to use the local one?
推荐答案
"require": {
    "my/package": "*"
}
如果是 VCS 或 path 存储库类型,您需要指定您请求的包的版本.因此,不要像现在那样使用 *,而是使用 @dev:
In case of VCS or path repository types, you need to specify version of the package you request. So instead of using *, as you have currently, use @dev:
"require": {
    "my/package": "@dev"
}
                        这篇关于如何强制 Composer 下载本地包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何强制 Composer 下载本地包?
				
        
 
            
        基础教程推荐
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
 - 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
 - PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
 - Yii2 - 在运行时设置邮件传输参数 2022-01-01
 - 将变量从树枝传递给 js 2022-01-01
 - php中的foreach复选框POST 2021-01-01
 - 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
 - Web 服务器如何处理请求? 2021-01-01
 - 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
 - php中的PDF导出 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				