Manual:Composer.json best practices

From mediawiki.org
This page is a translated version of the page Manual:Composer.json best practices and the translation is 59% complete.

MediaWiki内部で使用される拡張機能/ライブラリ/等のためにcomposer.jsonファイルを作成するとき、従うべきいくつかのベストプラクティスを紹介します。 また、composer validateを実行すると、スキーマエラーが指摘されます。

設定

  • prepend-autoloader: false. ComposerのオートローダはMediaWikiのよりも遅く、ロードされるクラスのほとんどはMediaWikiの内部で見つかりそうなので、composerオートローダをプリペンドする代わりにアペンドしてください。 詳しくはこちらをご覧ください。
  • optimize-autoloader: true. 最適化しない理由はありません。

Good example: core MediaWiki

依存関係

  • 依存関係は、タグが利用できない場合は、特定のバージョン番号またはsha1コミットに固定する必要があります。

Good example: core MediaWiki

命名

Libraries hosted in Gerrit or by the Wikimedia GitHub account should typically be published under the "wikimedia" namespace (e.g. "wikimedia/cdb", "wikimedia/simplei18n"). The use of the "mediawiki" namespace should be reserved for extensions and other intrinsically MediaWiki related components (bot frameworks, etc). 独立した組織の下でGitHubでホストされているプロジェクトは、グループが公開するライブラリ全体で一貫して適用されるように、同様の組織名スペースの規約を採用することが推奨されます。

作者

Major authors to the project should be documented in the "authors" property. 少なくとも、名前とメールアドレスの欄は記入する必要があります。

Extensions and skins

拡張機能

拡張機能の名前はすべて小文字で、単語の区切りとしてハイフンを使用します。例えば

  • Extension:WikiEditor --> mediawiki/wiki-editor
  • Extension:MassMessage --> mediawiki/mass-message

To make themselves installable, a dependency upon "composer/installers" with version >= 1.0.1 is required (a reasonable value for this field is "^2|^1.0.1"), and the type needs to be set to "mediawiki-extension".

Good example: Bootstrap extension

外装

タイプが「mediawiki-skin」でなければならないことを除いて、主に拡張機能と同じです。 名称の末尾には「-skin」を付けること。

Because Composer uses lowercase names for packages (e.g. mediawiki/vector-skin), the extra.installer-name property must be set to the uppercase name (e.g. Vector) so it is cloned in the right directory.

Good example: Vector skin

Overlaps with extension.json and skin.json

Extensions and skins register information about themselves using an extension.json or skin.json file. Some metadata fields in these files overlap, including:

  • homepage vs. url
  • license vs. license-name

The redundancy of data between extension/skin.json and composer.json has been discussed (see タスク T89456), but current consensus is that it is unavoidable.