LoginSignup
57
34

More than 5 years have passed since last update.

package.jsonの内容をまとめてみました

Last updated at Posted at 2018-04-08

はじめに

package.jsonのフィールドについて調べました。やや英語の直訳になっている箇所がありますので、ご指摘等いただけますと幸いです。

必須

  • name
  • version

この二つのフィールドがないとパッケージをインストールすることはできません。nameversionは共に単一なidを作成するために使われます。

name

{
  "name": "my-new-package"
}

パッケージ名。nameはURLやコマンドラインの引数、node_modulesに記述されるディレクトリ名として使われます。

■規約

  • 214文字以下(@scope/を含む)
  • 一文字目は「.(ドット)」「_(アンダースコア)」以外
  • 大文字は禁止
  • URLで使用可能な文字、記号

■TIPS

  • Node.jsのコアモジュール (/bin内に置かれているモジュール)と同じ名前は使えない
  • jsまたはnodeは使えない
  • nameが何を意味するかわかるような短い名前をつける
  • レジストリ内に同じ名前が存在しない

version

{
  "version": "1.0.0"
}

現在のパッケージのバージョン。

description

{
  "description": "this package is about managing money"
}

パッケージの目的を示すための文字列。パッケージマネージャ内でパッケージを探す時にも使われる。

keywords

{
  "keywords": ["cryptocurrency", "bill", "coin", "mile"]
}

String型の配列で、descriptionと同様にパッケージマネージャ内でパッケージを探す時に役に立つ。

license

{
  "license": "MIT",
  "license": "(MIT or GPL-3.0)",
  "license": "SEE LICENSE IN LICENSE_FILENAME.txt",
  "license": "UNLICENSED"
}

特別な理由がなければOSIに記載されているものを使用すること。
次のうち、当てはまる条件のものを記述しなければならない。

  • 標準ライセンスを一つ使用する場合は、SPDX license identifier
  • 標準ライセンスを複数使用する場合は、SPDX license expression syntax 2.0 expression
  • 非標準ライセンスを使用する場合は、SEE LICENSE IN <filename>
  • private、あるいは非公開パッケージを使う権利を与えたくない場合は、UNLICENSED

homepage

{
  "homepage": "https://your-package.org"
}

トップページ、あるいはパッケージのドキュメントがあるURLを記述。

bugs

{
  "bugs": "https://github.com/user/repo/issues"
}

ユーザーがパッケージの問題点を発見した際に、その問題点を共有するためのURLを記述。GitHubのパスやメールアドレスなどを指定します。

repository

{
  "repository": { "type": "git", "url": "https://github.com/user/repo.git" },
  "repository": "github:user/repo",
  "repository": "gitlab:user/repo",
  "repository": "bitbucket:user/repo",
  "repository": "gist:a1b2c3d4e5f"
}

パッケージの実際のコードが存在する場所を記述。

author

{
  "author": {
    "name": "Your Name",
    "email": "you@example.com",
    "url": "http://your-website.com"
  },
  "author": "Your Name <you@example.com> (http://your-website.com)"
}

auther情報を記述。autherは一人です。

contributors

{
  "contributors": [
    { "name": "Your Friend", "email": "friend@example.com", "url": "http://friends-website.com" }
    { "name": "Other Friend", "email": "other@example.com", "url": "http://other-website.com" }
  ],
  "contributors": [
    "Your Friend <friend@example.com> (http://friends-website.com)",
    "Other Friend <other@example.com> (http://other-website.com)"
  ]
}

パッケージ作成に関わった人を記述。配列で記述します。

files

{
  "files": ["filename.js", "directory/", "glob/*.{js,json}"]
}

プロジェクトに含まれるファイルを記述。ファイル名、ディレクトリ名、ワイルドカードを使用したファイル名を記述します。

main

{
  "main": "filename.js"
}

プロジェクトの主エントリーを記述。

bin

{
  "bin": "bin.js",
  "bin": {
    "command-name": "bin/command-name.js",
    "other-command": "bin/other-command"
  }
}

実行可能なファイルを記述。

man

{
  "man": "./man/doc.1",
  "man": ["./man/doc.1", "./man/doc.2"]
}

プロジェクトに関するマニュアルページがある場合は記述。

directories

{
  "directories": {
    "lib": "path/to/lib/",
    "bin": "path/to/bin/",
    "man": "path/to/man/",
    "doc": "path/to/doc/",
    "example": "path/to/example/"
  }
}

バイナリファイル、マニュアルページ、ドキュメント、exampleの実際の格納場所を記述。

scripts

{
  "scripts": {
    "build-project": "node build-project.js"
  }
}

パッケージに関連したタスクを自動化するのに役立つ。yarn run <script>で実行される様々なスクリプトを定義することが可能。

config

{
  "config": {
    "port": "8080"
  }
}

scriptsで使用される構成オプションやパラメータなどを記述。

dependencies

{
  "dependencies": {
    "package-1": "^3.1.4"
  }
}

開発や製品に必要な依存関係を記述。正しいバージョン(最も小さいバージョンまで、あるいはバージョンの範囲)を記述します。

devDependencies

{
  "devDependencies": {
    "package-2": "^0.4.2"
  }
}

インストールはされないが、開発する際に必要なものを記述。

peerDependencies

{
  "peerDependencies": {
    "package-3": "^2.7.18"
  }
}

他のパッケージとの互換性を記述。

optionalDependencies

{
  "optionalDependencies": {
    "package-5": "^1.6.1"
  }
}

パッケージとともに使われるが、必要なものではない。記述がなくてもインストール作業に影響はない。

bundledDependencies

{
  "bundledDependencies": ["package-4"]
}

パッケージ公開時に、まとめられるパッケージを配列にして記述。

flat

resolutions

System

engines

os

cpu

private

publishConfig

参考文献

package.json

57
34
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
57
34