diff --git a/index.js b/index.js index d04847e..3192481 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const importLazy = require('import-lazy')(require); const configstore = importLazy('configstore'); const chalk = importLazy('chalk'); +const semver = importLazy('semver'); const semverDiff = importLazy('semver-diff'); const latestVersion = importLazy('latest-version'); const isNpm = importLazy('is-npm'); @@ -114,7 +115,7 @@ class UpdateNotifier { notify(options) { const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn; - if (!process.stdout.isTTY || suppressForNpm || !this.update || this.update.current === this.update.latest) { + if (!process.stdout.isTTY || suppressForNpm || !this.update || !semver().gt(this.update.latest, this.update.current)) { return this; } diff --git a/package.json b/package.json index da62905..b681002 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "is-yarn-global": "^0.3.0", "latest-version": "^5.0.0", "pupa": "^2.0.1", + "semver": "^7.3.2", "semver-diff": "^3.1.1", "xdg-basedir": "^4.0.0" }, diff --git a/test/notify.js b/test/notify.js index 5aee3fc..2dae098 100644 --- a/test/notify.js +++ b/test/notify.js @@ -127,3 +127,11 @@ test('should not output if current version is the latest', t => { notifier.notify({defer: false}); t.false(stripAnsi(errorLogs).includes('Update available')); }); + +test('should not output if current version is more recent than the reported latest', t => { + setupTest(true); + const notifier = new Control(true); + notifier.update.current = '1.0.1'; + notifier.notify({defer: false}); + t.false(stripAnsi(errorLogs).includes('Update available')); +});