Skip to content

Commit 3dfe42d

Browse files
authored
Don't suggest to upgrade to lower version (#192)
1 parent 132b7ce commit 3dfe42d

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const importLazy = require('import-lazy')(require);
66

77
const configstore = importLazy('configstore');
88
const chalk = importLazy('chalk');
9+
const semver = importLazy('semver');
910
const semverDiff = importLazy('semver-diff');
1011
const latestVersion = importLazy('latest-version');
1112
const isNpm = importLazy('is-npm');
@@ -114,7 +115,7 @@ class UpdateNotifier {
114115

115116
notify(options) {
116117
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn;
117-
if (!process.stdout.isTTY || suppressForNpm || !this.update || this.update.current === this.update.latest) {
118+
if (!process.stdout.isTTY || suppressForNpm || !this.update || !semver().gt(this.update.latest, this.update.current)) {
118119
return this;
119120
}
120121

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"is-yarn-global": "^0.3.0",
4646
"latest-version": "^5.0.0",
4747
"pupa": "^2.0.1",
48+
"semver": "^7.3.2",
4849
"semver-diff": "^3.1.1",
4950
"xdg-basedir": "^4.0.0"
5051
},

test/notify.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,11 @@ test('should not output if current version is the latest', t => {
127127
notifier.notify({defer: false});
128128
t.false(stripAnsi(errorLogs).includes('Update available'));
129129
});
130+
131+
test('should not output if current version is more recent than the reported latest', t => {
132+
setupTest(true);
133+
const notifier = new Control(true);
134+
notifier.update.current = '1.0.1';
135+
notifier.notify({defer: false});
136+
t.false(stripAnsi(errorLogs).includes('Update available'));
137+
});

0 commit comments

Comments
 (0)