Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Dec 12, 2019
1 parent b1525e6 commit ccaf686
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UpdateNotifier {
// after the set interval, so not to bother users right away
lastUpdateCheck: Date.now()
});
} catch (error) {
} catch (_) {
// Expecting error code EACCES or EPERM
const message =
chalk().yellow(format(' %s update check failed ', options.pkg.name)) +
Expand Down Expand Up @@ -122,7 +122,7 @@ class UpdateNotifier {
}

notify(options) {
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpm;
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn;
if (!process.stdout.isTTY || suppressForNpm || !this.update) {
return this;
}
Expand Down
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Update notifications for your CLI app",
"license": "BSD-2-Clause",
"repository": "yeoman/update-notifier",
"funding": "https://github.com/yeoman/update-notifier?sponsor=1",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
Expand Down Expand Up @@ -33,26 +34,26 @@
"version"
],
"dependencies": {
"boxen": "^3.0.0",
"chalk": "^2.0.1",
"configstore": "^4.0.0",
"boxen": "^4.2.0",
"chalk": "^3.0.0",
"configstore": "^5.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-installed-globally": "^0.3.1",
"is-npm": "^4.0.0",
"is-yarn-global": "^0.3.0",
"latest-version": "^5.0.0",
"semver-diff": "^2.0.0",
"xdg-basedir": "^3.0.0"
"semver-diff": "^3.1.1",
"xdg-basedir": "^4.0.0"
},
"devDependencies": {
"ava": "^1.3.1",
"clear-module": "^3.1.0",
"ava": "^2.4.0",
"clear-module": "^4.0.0",
"fixture-stdout": "^0.2.1",
"mock-require": "^3.0.3",
"strip-ansi": "^5.2.0",
"xo": "^0.24.0"
"strip-ansi": "^6.0.0",
"xo": "^0.25.3"
},
"xo": {
"rules": {
Expand Down
32 changes: 12 additions & 20 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ Inform users of your package of updates in a non-intrusive way.
- [About](#about)
- [Users](#users)


## Install

```
$ npm install update-notifier
```


## Usage

### Simple
Expand Down Expand Up @@ -71,15 +69,13 @@ if (notifier.update) {
}
```


## How

Whenever you initiate the update notifier and it's not within the interval threshold, it will asynchronously check with npm in the background for available updates, then persist the result. The next time the notifier is initiated, the result will be loaded into the `.update` property. This prevents any impact on your package startup performance.
The update check is done in a unref'ed [child process](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options). This means that if you call `process.exit`, the check will still be performed in its own process.

The first time the user runs your app, it will check for an update, and even if an update is available, it will wait the specified `updateCheckInterval` before notifying the user. This is done to not be annoying to the user, but might surprise you as an implementer if you're testing whether it works. Check out [`example.js`](example.js) to quickly test out `update-notifier` and see how you can test that it works in your app.


## API

### notifier = updateNotifier(options)
Expand All @@ -96,17 +92,17 @@ Type: `object`

##### name

*Required*<br>
*Required*\
Type: `string`

##### version

*Required*<br>
*Required*\
Type: `string`

#### updateCheckInterval

Type: `number`<br>
Type: `number`\
Default: `1000 * 60 * 60 * 24` *(1 day)*

How often to check for updates.
Expand All @@ -119,19 +115,19 @@ Passing a callback here will make it check for an update directly and report rig

#### shouldNotifyInNpmScript

Type: `boolean`<br>
Type: `boolean`\
Default: `false`

Allows notification to be shown when running as an npm script.

#### distTag

Type: `string`<br>
Default: `latest`
Type: `string`\
Default: `'latest'`

Which [dist-tag](https://docs.npmjs.com/adding-dist-tags-to-packages) to use to find the latest version.

### notifier.notify([options])
### notifier.notify(options?)

Convenience method to display a notification message. *(See screenshot)*

Expand All @@ -143,33 +139,32 @@ Type: `object`

##### defer

Type: `boolean`<br>
Type: `boolean`\
Default: `true`

Defer showing the notification to after the process has exited.

##### message

Type: `string`<br>
Type: `string`\
Default: [See above screenshot](https://github.com/yeoman/update-notifier#update-notifier-)

Message that will be shown when an update is available.

##### isGlobal

Type: `boolean`<br>
Default: auto-detect
Type: `boolean`\
Default: Auto-detect

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).

##### boxenOpts

Type: `object`<br>
Type: `object`\
Default: `{padding: 1, margin: 1, align: 'center', borderColor: 'yellow', borderStyle: 'round'}` *(See screenshot)*

Options object that will be passed to [`boxen`](https://github.com/sindresorhus/boxen).


### User settings

Users of your module have the ability to opt-out of the update notifier by changing the `optOut` property to `true` in `~/.config/configstore/update-notifier-[your-module-name].json`. The path is available in `notifier.config.path`.
Expand All @@ -180,12 +175,10 @@ The check is also skipped automatically:
- on CI
- in unit tests (when the `NODE_ENV` environment variable is `test`)


## About

The idea for this module came from the desire to apply the browser update strategy to CLI tools, where everyone is always on the latest version. We first tried automatic updating, which we discovered wasn't popular. This is the second iteration of that idea, but limited to just update notifications.


## Users

There are a bunch projects using it:
Expand All @@ -199,7 +192,6 @@ There are a bunch projects using it:

[And 2700+ more…](https://www.npmjs.org/browse/depended/update-notifier)


---

<div align="center">
Expand Down
2 changes: 1 addition & 1 deletion test/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Control(shouldNotifyInNpmScript) {
const setupTest = isNpmReturnValue => {
['..', 'is-npm'].forEach(clearModule);
process.stdout.isTTY = true;
mock('is-npm', {isNpm: isNpmReturnValue || false});
mock('is-npm', {isNpmOrYarn: isNpmReturnValue || false});
const updateNotifier = require('..');
util.inherits(Control, updateNotifier.UpdateNotifier);
};
Expand Down
1 change: 0 additions & 1 deletion test/update-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import mockRequire from 'mock-require';

mockRequire('is-ci', false);

// eslint-disable-next-line import/first
import updateNotifier from '..';

const generateSettings = (options = {}) => {
Expand Down

0 comments on commit ccaf686

Please sign in to comment.