php 作曲家可以在不实际下载软件包的情况下生成`composer.lock`吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44805083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:02:19  来源:igfitidea点击:

Can composer generate the `composer.lock` without actually download the packages?

phpcomposer-php

提问by ciaoben

It does exist a command to generate the composer.lockfrom a composer.json?

它确实存在composer.lockcomposer.json?

Something similar ruby's bundler: $ bundle lock

类似 ruby​​ 的东西bundler$ bundle lock

回答by Duncanmoo

If you do not have a composer.lock

如果您没有 composer.lock

The answer is "no", you have to generate the lock file using:

答案是否定的,您必须使用以下方法生成锁定文件:

composer install

Installing Without composer.lock

If you have never run the command before and there is also no composer.lock file present, Composer simply resolves all dependencies listed in your composer.json file and downloads the latest versionof their files into the vendor directory in your project.

在没有 composer.lock 的情况下安装

如果您之前从未运行过该命令并且也没有 composer.lock 文件,那么 Composer 只需解析您的 composer.json 文件中列出的所有依赖项,并将 其文件的最新版本下载到您项目的 vendor 目录中。

Source: getcomposer.org

资料来源:getcomposer.org

NB Potential Issue:Without the lock file Composer will use the latest version of the dependencies.

NB 潜在问题:如果没有锁定文件,Composer 将使用最新版本的依赖项。

If you already have a composer.lock

如果你已经有一个 composer.lock

If you already have a composer.lockand Composer is complaining about it being out of sync, you'll see this warning:

如果您已经有一个composer.lock并且 Composer 抱怨它不同步,您将看到以下警告:

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

警告:锁定文件不是最新的 composer.json 中的最新更改。您可能会得到过时的依赖项。运行更新以更新它们。

To fix this you can update the lock file itself, without updating the dependencies. This will only update the content-hashin the lock file:

要解决此问题,您可以更新锁定文件本身,而无需更新依赖项。这只会更新content-hash锁定文件中的:

composer update --lock

From the Composer manual:

从作曲家手册:

--lock Only updates the lock file hash to suppress warning about the lock file being out of date.

--lock 仅更新锁定文件哈希以抑制有关锁定文件已过期的警告。

回答by deadbyte

The feature is being included in the v2.0 release, see here: https://github.com/composer/composer/pull/8669

该功能已包含在 v2.0 版本中,请参见此处:https: //github.com/composer/composer/pull/8669