15
8

More than 3 years have passed since last update.

yarnでパッケージをアップデートするときに注意すること

Last updated at Posted at 2019-09-27

手順

  1. yarn outdatedでversionを確認する
  2. yarn upgrade-interacitve --latest でパッケージを更新する。

手順としては上記2点だけで更新できるが
きちんと理解していないと躓くので、それぞれをきちんと理解する。

yarn outdated

古いパッケージの依存関係があるかをチェックします。
https://yarnpkg.com/lang/ja/docs/cli/outdated/

Package    Current Wanted Latest Package Type    URL
lodash     4.15.0  4.15.0 4.16.4 devDependencies https://github.com/lodash/lodash#readme
underscore 1.6.0   1.6.0  1.8.3  dependencies    https://github.com/jashkenas/underscore#readme
✨  Done in 0.72s.

Currentは現在のversionを、
Latestは最新のversionを表している。

そしてWantedに関しては以下の通り。

The resulting field 'wanted' shows the latest version according to the version specified in the package.json, the field 'latest' the very latest version of the package.

つまり、現在のpackage.jsonの指定に従った最新のversionになるため
メジャーアップデートが入った場合などでpackage.josnも更新したいときはLatestを参照する。

yarn upgrade-interactive --latest

npm-check の対話型の更新モードと同様に、古くなったパッケージを簡単に更新する手順を提供する。
https://yarnpkg.com/lang/ja/docs/cli/upgrade-interactive/

上記と同様に、latestオプションをつけないと現在のpackage.jsonの指定に従った最新のversionを表示するため、最新のversionにアップデートするのであればオプションをつける。

[1/? Choose which packages to update. (Press <space> to select, <a> to toggle all, <i> to inverse s
election)
 devDependencies
❯◯ autoprefixer      6.7.7  ❯  7.0.0          https://github.com/postcss/autoprefixer#readme
 ◯ webpack           2.4.1  ❯  2.5.1          https://github.com/webpack/webpack

 dependencies
 ◯ bull              2.2.6  ❯  3.0.0-alpha.3  https://github.com/OptimalBits/bull#readme
 ◯ fs-extra          3.0.0  ❯  3.0.1          https://github.com/jprichardson/node-fs-extra
 ◯ socket.io         1.7.3  ❯  1.7.4          https://github.com/socketio/socket.io#readme
 ◯ socket.io-client  1.7.3  ❯  1.7.4          https://github.com/Automattic/socket.io-client#readme

latestオプションなしの場合

逆にlatestオプションなしで更新すると、package.jsonの指定に従って更新されるため
キャレットやチルダ記述の範囲内でyarn.lockファイルのみが更新されることになる。
package.jsonファイルは更新されないので、なぜ???とならないように注意。

yarn.lockファイルの共有

更新されたyarn.lockファイルは共有することで、プロジェクト全体で
パッケージのマイナーバージョンの依存関係のズレがなくなるので
commit,pushを忘れないように。

15
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
8