Skip to content

Commit

Permalink
Don't suggest to upgrade to lower version (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Sep 29, 2020
1 parent 132b7ce commit 3dfe42d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 8 additions & 0 deletions test/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});

0 comments on commit 3dfe42d

Please sign in to comment.