Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

update-notifier

Package Overview
Dependencies
Maintainers
3
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

update-notifier - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

lib/check.js

37

lib/update-notifier.js

@@ -7,8 +7,9 @@ 'use strict';

var colors = require('colors');
var fork = require('child_process').fork;
function UpdateNotifier(options) {
options = options || {};
this.options = options = options || {};
if (!options.packageName && !options.packageVersion) {
if (!options.packageName || !options.packageVersion) {
this.packageFile = require(path.resolve(path.dirname(module.parent.filename), options.packagePath || 'package'));

@@ -20,2 +21,3 @@ }

this.updateCheckInterval = options.updateCheckInterval || 1000 * 60 * 60 * 24; // 1 day
this.updateCheckTimeout = options.updateCheckTimeout || 20000; // 20 secs
this.registryUrl = options.registryUrl || 'http://registry.npmjs.org/%s';

@@ -28,2 +30,4 @@ this.config = new Configstore('update-notifier-' + this.packageName, {

UpdateNotifier.prototype.check = function() {
var cp;
if (this.config.get('optOut')) {

@@ -42,7 +46,11 @@ return;

this.checkNpm(function(update) {
if (update.type && update.type !== 'latest') {
this.config.set('update', update);
}
}.bind(this));
// Set some needed options before forking
// This is needed because we can't infer the packagePath in the fork
this.options.packageName = this.packageName;
this.options.packageVersion = this.packageVersion;
// Fork, passing the options as an environment property
cp = fork(__dirname + '/check.js', [JSON.stringify(this.options)]);
cp.unref();
cp.disconnect();
};

@@ -53,7 +61,11 @@

request({url: url, json: true}, function(error, response, body) {
request({url: url, json: true, timeout: this.updateCheckTimeout}, function(error, response, body) {
var currentVersion, latestVersion;
if (error) {
return cb(error);
}
if (body.error) {
error = 'Package not found';
return cb(new Error('Package not found'));
}

@@ -64,3 +76,3 @@

cb({
cb(null, {
latest: latestVersion,

@@ -70,4 +82,3 @@ current: currentVersion,

date: body.time[latestVersion],
name: this.packageName,
error: error
name: this.packageName
});

@@ -114,3 +125,5 @@ }.bind(this));

updateNotifier.check();
return updateNotifier;
};
module.exports.UpdateNotifier = UpdateNotifier;
{
"name": "update-notifier",
"version": "0.1.0",
"version": "0.1.1",
"description": "Update notifier for your package",

@@ -5,0 +5,0 @@ "keywords": [

@@ -9,3 +9,4 @@ # update-notifier [![Build Status](https://secure.travis-ci.org/yeoman/update-notifier.png?branch=master)](http://travis-ci.org/yeoman/update-notifier)

Whenever you initiate the update notifier and it's not inside the interval threshold it will asynchronously check with NPM if there's an available update and then persist the result. The next time the notifier is initiated the result will be loaded into the `.update` property. It shouldn't have any impact on your package startup performance.
Whenever you initiate the update notifier and it's not inside the interval threshold it will asynchronously check with NPM if there's an available update and then persist the result. The next time the notifier is initiated the result will be loaded into the `.update` property. Because of this it shoulddn't have any impact on your package startup performance.
The check process is done with [fork](http://nodejs.org/api/child_process.html#child_process_child_fork). This means that if you call `process.exit`, the check will still be performed in its own process.

@@ -102,2 +103,10 @@

#### updateCheckTimeout
Type: `number`
Default: `20000` (20 secs)
How long the update can take.
If it takes longer than the timeout, it will be aborted.
#### registryVersion

@@ -104,0 +113,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc