LoginSignup
0
0

More than 5 years have passed since last update.

npm、Bowerでパッケージを公開するときにつまづいたこと

Posted at

JSONを事前にバリデートしたほうがいい

bower.json内の余計なカンマに気づかず公開してしまい、試しにダウンロードしようとしてエラーに気づきました。
結局、パッチのバージョンを上げて公開し直しました。
package.jsonもbower.jsonも事前に検査しておいたほうがいいです。

Webで検査

  • package.json: http://package-json-validator.com/
  • bower.json: 適当なサービスが見当たりませんでした。ここでいろいろなJSONの検査ができるようですが、余計なカンマをエラーと認識しませんでした。

コマンドラインで検査

それぞれのnpmパッケージが提供されています。

devDependenciesに追加して、一括して検査できるようにします。
なお、bower-jsonは実行用のJSファイルを別途用意しなければなりません。
今回はbower-json.validate.jsに記述しています。

package.json
{
  "devDependencies": {
    "bower-json": "^0.8.1",
    "package-json-validator": "^0.6.1"
  },
  "scripts": {
    "validate-json": "pjv && node bower-json.validate.js"
  }
bower-json.validate.js
var bowerJson = require('bower-json');
bowerJson.read('bower.json', function (err, json) {
  if (err) {
    console.error('There was an error reading the file');
    console.error(err.message);
    return;
  }
  console.log('bower.json is valid');
});

これで、下記のコマンドで一括して検査できます。

$ npm run validate-json

descriptionは必須

descriptionがないとパッケージの紹介ページがかっこ悪くなります。
たとえばnpmのユーザーのページで。
現在はdescriptionを書いているので下記のように表示されています。

jquery.add-input-area - v4.9.1 - jQuery plugin to add or delete form fields.

以前は横着してdescriptionを書いていなかったので、README.mdのh1見出し直後の1行、TravisCIのバッジのコードが表示されていました。

jquery.add-input-area - v4.9.0 - 
[![Build Status](https://travis-ci.org/sutara79/jquery.simple-scroll-follow.svg?branch=master)](https://travis-ci.org/sutara79/jquery.simple-scroll-follow)

これでは意味不明です。
というわけでpackage.jsonでもbower.jsonでもdescriptionは必須です。

{
  "description": "jQuery plugin to add or delete form fields."
0
0
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
0
0