896
571

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

package.json のチルダ(~) とキャレット(^)

Last updated at Posted at 2015-08-20

バージョン指定でいっつもこいつの違いを忘れてしまって、npm とか semver のドキュメントを探すところから始まるから自分用のメモ。

  • ^1.1.2 = 1.x
  • ~1.1.2 = 1.1.x

(追記 一応↑は間違っていないのだけど、厳密にいうとちょっと間違っていた)

チルダ表記 ~

"明記したところ以下のバージョンがあがることのみ許容"

  • ~1.1.2 = 1.1.2 <= version < 1.2.0
  • ~1.1 = 1.1.x
  • ~1 = 1.x

オリジナルの定義は、

Allows patch-level changes if a minor version is specified on the comparator. Allows minor-level changes if not.

キャレット表記 ^

"一番左側にある、ゼロでないバージョニングは変えない (それ以下があがることは許容)"

  • ^1.2.3 := 1.2.3 <= version < 2.0.0
  • ^0.2.3 := 0.2.3 <= version < 0.3.0
  • ^0.0.3 := 0.0.3 <= version < 0.0.4

オリジナルの定義は

Allows changes that do not modify the left-most non-zero digit in the [major, minor, patch] tuple.

余談

こんなことで悩むくらいなら最初から 1.2.x とか >=1.0.2 <2.1.2 とかみたいに書いておいたほうが圧倒的にわかりやすい。
許容されるのは↓の通り。

docs.npmjs.com/files/package.json
{ "dependencies" :
  { "foo" : "1.0.0 - 2.9999.9999"
  , "bar" : ">=1.0.2 <2.1.2"
  , "baz" : ">1.0.2 <=2.3.4"
  , "boo" : "2.0.1"
  , "qux" : "<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"
  , "asd" : "http://asdf.com/asdf.tar.gz"
  , "til" : "~1.2"
  , "elf" : "~1.2.3"
  , "two" : "2.x"
  , "thr" : "3.3.x"
  , "lat" : "latest"
  , "dyl" : "file:../dyl"
  }
}

参考

本件ではどうでもいいけどこれも:

896
571
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
896
571

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?