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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bszhct/pkg-updater

v1.0.5

Published

A simple updater which use in your cli tool.

Downloads

2

Readme

pkg-updater

This version solves the problem of automatic update failure.

This package is suitable for update checking of cli tools. It will check the version in background process, and notify the users when update is available.

Usage

Install the module with: npm install pkg-updater --save.

const updater = require('pkg-updater');
const pkg = require('./package.json'); // your cli tool's package.json

updater({'pkg': pkg}) .then(() => { /* start cli here */ });

updater({
  'pkg': pkg,  
  'registry': 'http://xxx.registry.com', // custom registry
  'tag': 'next', // custom the check tag(default is latest)
  'checkInterval': 24 * 60 * 60 * 1000, // custom the check interval(ms)
  'updateMessage': 'package update from <%=current%> to <%=latest%>.' // custom notify message
}).then(() => { /* start cli here */ });

API

updater(options) -> {Promise}

  • options {Object}
    • pkg {Object} (required)
    • registry {String}
    • tag {String}
    • level {String}
    • checkInterval {Integer}
    • updateMessage {String}
    • onVersionChange {Function}
    • logFile {String}

pkg

The package.json data, should contain name and version property. You can just write require('./package.json').

registry

The registry from which we fetch the package information. It is https://registry.npmjs.org by default.

tag

The tag we use to fetch the package's version. We will request the {registry}/{package.name}/{tag} to get the remote version. It is latest by default.

level

The incompatible level to decide whether we should process.exit. It is major by default.

You can provide:

  • major: remote is 2.0.0, current is 1.0.0, we will process.exit
  • minor: remote is 1.1.0, current is 1.0.0, we will process.exit
  • patch: remote is 1.0.1, current is 1.0.0, we will process.exit

checkInterval

The interval(ms) to create the daemon check process. It is 60 * 60 * 1000(1h) by default.

updateMessage

The message we use to notiy user in the terminal. It is a lodash template string. The default value is:

'Package update available:' +
'<%=colors.dim(current)%> -> <%=colors.green(latest)%>' +
'<%if(incompatible){%>\n<%=colors.bold("This version is incompatible, you should update before continuing.")%><%}%>\n' +
'Run <%=colors.cyan(command)%> to update.'

You can use following variables:

  • name: package's name
  • current: package's current version
  • latest: package's remote version
  • incompatible: whether the current and latest is compatiable
  • command: the update command, default is npm i {package.name} -g
  • colors: the colors object

onVersionChange

The function to execute when the remote version is newer than the current version.

The default behavior of this function is:

  • use the boxen to display the updateMessage
  • if the version is incompatible, exit the process

If you really know what you are doing, you can provide your custom function.

This function can be a generator function, is called as followed:

yield onVersionChange({
  'incompatible': false,
  'latestVersion': '2.0.1',
  'pkg': {
    'name': 'foo',
    'version': '2.0.0'
  },
  'level': 'major',
  'updateMessage': 'the default update message'
});

logFile

The log file we use to store the check information. It is {$HOME}/.pkg_updater.json.

This file's format looks like this:

{
  "foo": {
    "latestVersion": "2.0.1",
    "lastCheck": 1477294183263
  },
  "bar": {
    "latestVersion": "1.0.1",  
    "lastCheck": 1477294183263     
  }
}