npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

travis-npm-test

v1.1.2

Published

これは以下のポストのクローンであり、同時にポスト内で例示されているリポジトリになります。

Readme

Travis CIを使ってnpmを継続的に公開・メンテナンスするよ

これは以下のポストのクローンであり、同時にポスト内で例示されているリポジトリになります。

http://qiita.com/KamataRyo/items/6e795c6734f9a775f5a6

Build Status

npmで公開予定のライブラリを想定し、CIサービスを中心にしてリリース管理を行う方法について書きます。

ローカルマシンに必要なライブラリをインストールする

GitNode.jsTravis CI Clientをインストールします。お好きな方法でお使いの端末にインストールしてください。以下はHomebrewがインストールされているMacのターミナル上での操作の例です。

$ brew install git
$ brew install node
$ gem install travis

各サービスのサインアップ・ログイン

それぞれのサービスにサインアップしておきます。

Travis CI Clientでのログイン

GitHubのアカウントを使い、Travis CI Client上でログインを行います。以下のコマンドを使うと、GitHubユーザー名、パスワード、2要素認証のコード(設定している方のみ)をインタラクティブに入力してログインすることができます。画像にある標準出力のメッセージによればGitHubのアクセストークンを使って認証する方法もあるようです。

$ travis login

スクリーンショット 2017-04-11 17.46.21.png

npmクライアントでのログイン

npmのクライアントはNode.jsと一緒にインストールされているはずです。npmjs.comのアカウントを使い、クライアント上でログインを行います。npm loginコマンドを使うと、ユーザー名、パスワード、公開Eメールアドレスをインタラクティブに入力してログインすることができます。

$ npm login

スクリーンショット 2017-04-11 18.11.22.png

プロジェクトのセットアップ

対象となるプロジェクトをセットアップします。プロジェクトはGitの管理下に置き、またnpmプロジェクトとしての初期化(package.jsonの作成)を行っておいてください。

$ cd path-to-the-project
$ git init
$ npm init -y

また、このプロジェクトはGitHub上で公開プロジェクトとしてホストできるようにしておく必要があります。今回は、kamataryo/travis-npm-testというリポジトリで例を用意してあります。

$ git remote add origin [email protected]:kamataryo/travis-npm-test.git

Travis CIのセットアップ

travis initコマンドを使うと .travis.ymlが作成され、また、このリポジトリの存在をTravis CIに伝えることができます。この際は、正しいリポジトリかどうか、プロジェクトのプログラミング言語は何かをインタラクティブに聞かれますので、正しい答えを入力してください。package.jsonがあるにもかかわらず、よくrubyに間違われます。

$ travis init

スクリーンショット 2017-04-11 17.56.55.png

ここまでの設定を行うと、GitHubへのプッシュをトリガーに、Travis CIでのビルドが発火する状態になっているはずです。

npmへのデプロイのセットアップ

.travis.ymlを編集してデプロイ設定を行います。ファイルに以下の値を追加してください。

deploy:
  provider: npm
  email: "[email protected]"
  on:
    tags: true

on.tags = trueは、タグのコミットの場合のみデプロイが発火する設定です。この他、特定のブランチのプッシュにフックすることもできるようです。詳細は以下のドキュメントなどを参照してください。

https://docs.travis-ci.com/user/deployment/npm/

npmの認証トークンを確認する

npm loginコマンドが成功していると、~/.npmrcに認証トークンが記載されるはずです。これを確認してください。

$ cat ~/.npmrc

//registry.npmjs.org/:_authToken=[認証トークン]

travis encryptコマンドを使い、得られた認証トークンを暗号化します。addオプションでカレントディレクトリにある.travis.ymlに値を追記してくれます。ただ、この時にyamlファイルが勝手に整形されてしまうので、これが嫌な場合はaddオプションを外して標準出力をコピペするのがいいかもしれません。

$ travis encrypt [認証トークン] --add deploy.api_key

以上までの設定を行うと、.travis.ymlは以下のような内容になっているはずです。

language: node_js
node_js:
- '7'
deploy:
  provider: npm
  email: '[email protected]'
  on:
    tags: true
  api_key:
    secure: [暗号化された認証トークン]

npmで公開する

以上でTravis CIの設定が完了したので、GitHubにプッシュしてみます。

$ git add .
$ git commit -m "Init repo"
$ git push origin master

タグを付け、プッシュすることでリリースします。

$ npm version patch
$ git push origin v1.0.1

npm versionコマンドは色々な仕事をしてくれていているようで、

  • package.jsonの編集(バージョン番号のインクリメント)
  • 新しいバージョンタグの作成
  • masterブランチへのamendコミット(?)

などをしてくれているみたいです。あとはタグをプッシュするだけでOKになります。patch引数を与えるとバージョンの v0.0.xの部分、それとは別にminormajor引数を与えるとそれぞれ v0.x.0vx.0.0の部分がインクリメントされます。

Travis CIでのテストが成功すると、ビルドはdeployセクションに移行してnpm publishコマンドを自動で実行してくれます。以下のリンクは成功したビルドの履歴になります。

https://travis-ci.org/KamataRyo/travis-npm-test/builds/220894443

スクリーンショット 2017-04-11 18.51.30.png

オプション

npm versionコマンドのポストスクリプトを以下のように定義しておくと、npm versionコマンドの後でタグをプッシュしなくていいので便利かもしれません。最新のタグを自動でプッシュします。

{
  ...
  "scripts": {
     ...
  	 "postversion": "git push origin $(git tag -l | tail -n1)",
  	 ...
  }
}

まとめ

今回例示したリポジトリは以下のものになります。 https://github.com/KamataRyo/travis-npm-test

また、このリポジトリのTravis CIでのビルドログは以下から閲覧できます。 https://travis-ci.org/KamataRyo/travis-npm-test/builds

CIツール・サービスを中心にしたワークフローを採ることで、タグを付けてプッシュするだけでライブラリの公開・更新を行うことができます。テストに失敗するとデプロイが発火しないため、ヒューマンエラーによりテストが落ちる状態でプッシュしてしまったとしても、リリースを防ぐことができます。