diff --git a/index.js b/index.js index 95075e4..a24f036 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ class UpdateNotifier { constructor(options = {}) { this.options = options; options.pkg = options.pkg || {}; + options.distTag = options.distTag || 'latest'; // Reduce pkg to the essential keys. with fallback to deprecated options // TODO: Remove deprecated options at some point far into the future @@ -106,12 +107,13 @@ class UpdateNotifier { } async checkNpm() { - const latest = await latestVersion()(this.packageName); + const {distTag} = this.options; + const latest = await latestVersion()(this.packageName, {version: distTag}); return { latest, current: this.packageVersion, - type: semverDiff()(this.packageVersion, latest) || 'latest', + type: semverDiff()(this.packageVersion, latest) || distTag, name: this.packageName }; } diff --git a/readme.md b/readme.md index 62f9b9e..f9999a5 100644 --- a/readme.md +++ b/readme.md @@ -137,6 +137,13 @@ Default: `false` Allows notification to be shown when running as an npm script. +#### distTag + +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]) Convenience method to display a notification message. *(See screenshot)* diff --git a/test/update-notifier.js b/test/update-notifier.js index d70f03b..fcdd24f 100644 --- a/test/update-notifier.js +++ b/test/update-notifier.js @@ -13,7 +13,8 @@ const generateSettings = (options = {}) => { name: 'update-notifier-tester', version: '0.0.2' }, - callback: options.callback + callback: options.callback, + distTag: options.distTag }; }; @@ -35,7 +36,12 @@ test.afterEach(() => { test('check for update', async t => { const update = await updateNotifier(generateSettings()).checkNpm(); - t.is(update.current, '0.0.2'); + t.is(update.latest, '0.0.2'); +}); + +test('check for update with dist-tag', async t => { + const update = await updateNotifier(generateSettings({distTag: '0.0.3-rc1'})).checkNpm(); + t.is(update.latest, '0.0.3-rc1'); }); test.cb('check for update with callback', t => {