diff --git a/index.js b/index.js index eaa2ce2..35f44c6 100644 --- a/index.js +++ b/index.js @@ -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)) + @@ -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; } diff --git a/package.json b/package.json index 13794a5..9cff906 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/readme.md b/readme.md index 5ac253d..a0a3cc8 100644 --- a/readme.md +++ b/readme.md @@ -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 @@ -71,7 +69,6 @@ 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. @@ -79,7 +76,6 @@ The update check is done in a unref'ed [child process](https://nodejs.org/api/ch 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) @@ -96,17 +92,17 @@ Type: `object` ##### name -*Required*
+*Required*\ Type: `string` ##### version -*Required*
+*Required*\ Type: `string` #### updateCheckInterval -Type: `number`
+Type: `number`\ Default: `1000 * 60 * 60 * 24` *(1 day)* How often to check for updates. @@ -119,19 +115,19 @@ Passing a callback here will make it check for an update directly and report rig #### shouldNotifyInNpmScript -Type: `boolean`
+Type: `boolean`\ Default: `false` Allows notification to be shown when running as an npm script. #### distTag -Type: `string`
-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)* @@ -143,33 +139,32 @@ Type: `object` ##### defer -Type: `boolean`
+Type: `boolean`\ Default: `true` Defer showing the notification to after the process has exited. ##### message -Type: `string`
+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`
-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`
+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`. @@ -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: @@ -199,7 +192,6 @@ There are a bunch projects using it: [And 2700+ moreā€¦](https://www.npmjs.org/browse/depended/update-notifier) - ---
diff --git a/test/notify.js b/test/notify.js index 7834d57..2fddf41 100644 --- a/test/notify.js +++ b/test/notify.js @@ -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); }; diff --git a/test/update-notifier.js b/test/update-notifier.js index e6b807b..704e6e1 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -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 = {}) => {