Skip to content

Commit

Permalink
Add distTag option (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore authored and sindresorhus committed Apr 7, 2019
1 parent 14632e4 commit c8faa84
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Expand Up @@ -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
Expand Down Expand Up @@ -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
};
}
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Expand Up @@ -137,6 +137,13 @@ 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])

Convenience method to display a notification message. *(See screenshot)*
Expand Down
10 changes: 8 additions & 2 deletions test/update-notifier.js
Expand Up @@ -13,7 +13,8 @@ const generateSettings = (options = {}) => {
name: 'update-notifier-tester',
version: '0.0.2'
},
callback: options.callback
callback: options.callback,
distTag: options.distTag
};
};

Expand All @@ -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 => {
Expand Down

0 comments on commit c8faa84

Please sign in to comment.