わすれっぽいきみえ

みらいのじぶんにやさしくしてやる

composerはcomposer updateを使わない限りcomposer.jsonに書かれてるライブラリを勝手にupdateしない

getcomposer.org

普段からcomposerを使っているのに basic usageのページをそういえばまともに読んだことがなかった。
当たり前のことではあるんだが、しばらくライブラリのアップデートをしないでいるとうっかり忘れちゃうような自分の中では地味に重要なことが書かれていると思ったので、抜粋して書いておく。
意訳してるけど、そこは適当に。

Commit your application's composer.lock (along with composer.json) into version control. This is important because the install command checks if a lock file is present, and if it is, it downloads the versions specified there (regardless of what composer.json says).

composer.lockとcomposer.jsonはversion controlに登録しておくこと。
install コマンドはlockファイルの存在を確認しており、存在していたらcomposer.jsonに記載されていることが何であったとしても、そこに指定されているバージョンのものをダウンロードする。

This means that if any of the dependencies get a new version, you won't get the updates automatically. To update to the new version, use the update command.

これは新しいバージョンの中にどんな依存関係があったとしても、自動的にはアップデートされないことを意味している。新しいバージョンをアップデートしたければ update コマンドを使うこと。

Composer will display a Warning when executing an install command if composer.lock and composer.json are not synchronized.

Composerはcomposer.lockとcomposer.jsonの間に差分があればinstall時にWarningを表示してくれる。


ある特定のライブラリをアップデートしたければ、 composer update hoge みたいにライブラリ名を直接指定する。こうすることで他のアップデートしたくないライブラリの依存関係は変更しないまま、特定ライブラリだけのアップデートが行える。