Skip to content

Commit

Permalink
Avoid showing notification if current version is the latest (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored and sindresorhus committed Dec 12, 2019
1 parent ccaf686 commit bc1721a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -94,6 +94,10 @@ class UpdateNotifier {
this.update = this.config.get('update');

if (this.update) {
// Use the real latest version instead of the cached one
this.update.current = this.packageVersion;

// Clear cached information
this.config.delete('update');
}

Expand Down Expand Up @@ -123,7 +127,7 @@ class UpdateNotifier {

notify(options) {
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn;
if (!process.stdout.isTTY || suppressForNpm || !this.update) {
if (!process.stdout.isTTY || suppressForNpm || !this.update || this.update.current === this.update.latest) {
return this;
}

Expand Down
8 changes: 8 additions & 0 deletions test/notify.js
Expand Up @@ -83,3 +83,11 @@ test('should ouput if running as npm script and shouldNotifyInNpmScript option s
notifier.notify({defer: false});
t.true(stripAnsi(errorLogs).includes('Update available'));
});

test('should not output if current version is the latest', t => {
setupTest(true);
const notifier = new Control(true);
notifier.update.current = '1.0.0';
notifier.notify({defer: false});
t.false(stripAnsi(errorLogs).includes('Update available'));
});

0 comments on commit bc1721a

Please sign in to comment.