update-notifier
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8740
113
137
1