Socket
Socket
Sign inDemoInstall

update-notifier

Package Overview
Dependencies
90
Maintainers
6
Versions
48
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.5.0 to 3.0.0

14

check.js

@@ -9,3 +9,8 @@ /* eslint-disable unicorn/no-process-exit */

updateNotifier.checkNpm().then(update => {
(async () => {
// Exit process when offline
setTimeout(process.exit, 1000 * 30);
const update = await updateNotifier.checkNpm();
// Only update the last update check time on success

@@ -18,7 +23,8 @@ updateNotifier.config.set('lastUpdateCheck', Date.now());

// Call process exit explicitly to terminate the child process
// Otherwise the child process will run forever, according to the Node.js docs
// Call process exit explicitly to terminate the child process,
// otherwise the child process will run forever, according to the Node.js docs
process.exit();
}).catch(() => {
})().catch(error => {
console.error(error);
process.exit(1);
});
'use strict';
const spawn = require('child_process').spawn;
const {spawn} = require('child_process');
const path = require('path');
const format = require('util').format;
const {format} = require('util');
const importLazy = require('import-lazy')(require);

@@ -13,12 +13,15 @@

const isInstalledGlobally = importLazy('is-installed-globally');
const isYarnGlobal = importLazy('is-yarn-global');
const hasYarn = importLazy('has-yarn');
const boxen = importLazy('boxen');
const xdgBasedir = importLazy('xdg-basedir');
const isCi = importLazy('is-ci');
const ONE_DAY = 1000 * 60 * 60 * 24;
class UpdateNotifier {
constructor(options) {
options = options || {};
constructor(options = {}) {
this.options = options;
options.pkg = options.pkg || {};
options.distTag = options.distTag || 'latest';

@@ -42,3 +45,3 @@ // Reduce pkg to the essential keys. with fallback to deprecated options

this.disabled = 'NO_UPDATE_NOTIFIER' in process.env ||
process.argv.indexOf('--no-update-notifier') !== -1 ||
process.argv.includes('--no-update-notifier') ||
isCi();

@@ -56,5 +59,5 @@ this.shouldNotifyInNpmScript = options.shouldNotifyInNpmScript;

});
} catch (err) {
} catch (error) {
// Expecting error code EACCES or EPERM
const msg =
const message =
chalk().yellow(format(' %s update check failed ', options.pkg.name)) +

@@ -66,3 +69,3 @@ format('\n Try running with %s or get access ', chalk().cyan('sudo')) +

process.on('exit', () => {
console.error('\n' + boxen()(msg, {align: 'center'}));
console.error('\n' + boxen()(message, {align: 'center'}));
});

@@ -72,7 +75,13 @@ }

}
check() {
if (this.hasCallback) {
this.checkNpm()
.then(update => this.callback(null, update))
.catch(err => this.callback(err));
(async () => {
try {
this.callback(null, await this.checkNpm());
} catch (error) {
this.callback(error);
}
})();
return;

@@ -106,14 +115,17 @@ }

}
checkNpm() {
return latestVersion()(this.packageName).then(latestVersion => {
return {
latest: latestVersion,
current: this.packageVersion,
type: semverDiff()(this.packageVersion, latestVersion) || 'latest',
name: this.packageName
};
});
async checkNpm() {
const {distTag} = this.options;
const latest = await latestVersion()(this.packageName, {version: distTag});
return {
latest,
current: this.packageVersion,
type: semverDiff()(this.packageVersion, latest) || distTag,
name: this.packageName
};
}
notify(opts) {
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm();
notify(options) {
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpm;
if (!process.stdout.isTTY || suppressForNpm || !this.update) {

@@ -123,8 +135,22 @@ return this;

opts = Object.assign({isGlobal: isInstalledGlobally()}, opts);
options = {
isGlobal: isInstalledGlobally(),
isYarnGlobal: isYarnGlobal()(),
...options
};
opts.message = opts.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan('npm i ' + (opts.isGlobal ? '-g ' : '') + this.packageName) + ' to update';
let installCommand;
opts.boxenOpts = opts.boxenOpts || {
if (options.isYarnGlobal) {
installCommand = `yarn global add ${this.packageName}`;
} else if (hasYarn()()) {
installCommand = `yarn add ${this.packageName}`;
} else {
installCommand = `npm i ${options.isGlobal ? '-g ' : ''}${this.packageName}`;
}
options.message = options.message || 'Update available ' + chalk().dim(this.update.current) + chalk().reset(' → ') +
chalk().green(this.update.latest) + ' \nRun ' + chalk().cyan(installCommand) + ' to update';
options.boxenOpts = options.boxenOpts || {
padding: 1,

@@ -137,5 +163,5 @@ margin: 1,

const message = '\n' + boxen()(opts.message, opts.boxenOpts);
const message = '\n' + boxen()(options.message, options.boxenOpts);
if (opts.defer === false) {
if (options.defer === false) {
console.error(message);

@@ -142,0 +168,0 @@ } else {

{
"name": "update-notifier",
"version": "2.5.0",
"description": "Update notifications for your CLI app",
"license": "BSD-2-Clause",
"repository": "yeoman/update-notifier",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"test": "xo && ava --timeout=20s"
},
"files": [
"index.js",
"check.js"
],
"keywords": [
"npm",
"update",
"updater",
"notify",
"notifier",
"check",
"checker",
"cli",
"module",
"package",
"version"
],
"dependencies": {
"boxen": "^1.2.1",
"chalk": "^2.0.1",
"configstore": "^3.0.0",
"import-lazy": "^2.1.0",
"is-ci": "^1.0.10",
"is-installed-globally": "^0.1.0",
"is-npm": "^1.0.0",
"latest-version": "^3.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"clear-module": "^2.1.0",
"fixture-stdout": "^0.2.1",
"mock-require": "^2.0.2",
"strip-ansi": "^4.0.0",
"xo": "^0.18.2"
}
"name": "update-notifier",
"version": "3.0.0",
"description": "Update notifications for your CLI app",
"license": "BSD-2-Clause",
"repository": "yeoman/update-notifier",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
},
"scripts": {
"test": "xo && ava --timeout=20s -s"
},
"files": [
"index.js",
"check.js"
],
"keywords": [
"npm",
"update",
"updater",
"notify",
"notifier",
"check",
"checker",
"cli",
"module",
"package",
"version"
],
"dependencies": {
"boxen": "^3.0.0",
"chalk": "^2.0.1",
"configstore": "^4.0.0",
"has-yarn": "^2.1.0",
"import-lazy": "^2.1.0",
"is-ci": "^2.0.0",
"is-installed-globally": "^0.1.0",
"is-npm": "^3.0.0",
"is-yarn-global": "^0.3.0",
"latest-version": "^5.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"clear-module": "^3.1.0",
"fixture-stdout": "^0.2.1",
"mock-require": "^3.0.3",
"strip-ansi": "^5.2.0",
"xo": "^0.24.0"
}
}

@@ -83,2 +83,17 @@ # update-notifier [![Build Status](https://travis-ci.org/yeoman/update-notifier.svg?branch=master)](https://travis-ci.org/yeoman/update-notifier)

---
<div align="center">
<b>
<a href="https://tidelift.com/subscription/pkg/npm-update_notifier?utm_source=npm-update-notifier&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
</b>
<br>
<sub>
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
</sub>
</div>
---
## API

@@ -88,3 +103,3 @@

Checks if there is an available update. Accepts options defined below. Returns an instance with an `.update` property there is an available update, otherwise `undefined`.
Checks if there is an available update. Accepts options defined below. Returns an instance with an `.update` property if there is an available update, otherwise `undefined`.

@@ -120,2 +135,16 @@ ### options

#### shouldNotifyInNpmScript
Type: `boolean`<br>
Default: `false`
Allows notification to be shown when running as an npm script.
#### distTag
Type: `string`<br>
Default: `latest`
Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version.
### notifier.notify([options])

@@ -148,3 +177,3 @@

Type: `boolean`<br>
Default: `true`
Default: auto-detect

@@ -160,9 +189,3 @@ Include the `-g` argument in the default message's `npm i` recommendation. You may want to change this if your CLI package can be installed as a dependency of another project, and don't want to recommend a global installation. This option is ignored if you supply your own `message` (see above).

##### shouldNotifyInNpmScript
Type: `boolean`<br>
Default: `false`
Allows notification to be shown when running as an npm script.
### User settings

@@ -193,7 +216,12 @@

[And 1600+ more…](https://www.npmjs.org/browse/depended/update-notifier)
[And 2700+ more…](https://www.npmjs.org/browse/depended/update-notifier)
## Security
To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.
## License
BSD-2-Clause © Google
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc