From bc1721a08a13c24a6ef17e9e511423b908f0513c Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Thu, 12 Dec 2019 20:27:53 +0700 Subject: [PATCH] Avoid showing notification if current version is the latest (#174) --- index.js | 6 +++++- test/notify.js | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 35f44c6..1640fc4 100644 --- a/index.js +++ b/index.js @@ -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'); } @@ -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; } diff --git a/test/notify.js b/test/notify.js index 2fddf41..460d0dc 100644 --- a/test/notify.js +++ b/test/notify.js @@ -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')); +});