Skip to content

Commit bc1721a

Browse files
fregantesindresorhus
authored andcommitted
Avoid showing notification if current version is the latest (#174)
1 parent ccaf686 commit bc1721a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class UpdateNotifier {
9494
this.update = this.config.get('update');
9595

9696
if (this.update) {
97+
// Use the real latest version instead of the cached one
98+
this.update.current = this.packageVersion;
99+
100+
// Clear cached information
97101
this.config.delete('update');
98102
}
99103

@@ -123,7 +127,7 @@ class UpdateNotifier {
123127

124128
notify(options) {
125129
const suppressForNpm = !this.shouldNotifyInNpmScript && isNpm().isNpmOrYarn;
126-
if (!process.stdout.isTTY || suppressForNpm || !this.update) {
130+
if (!process.stdout.isTTY || suppressForNpm || !this.update || this.update.current === this.update.latest) {
127131
return this;
128132
}
129133

test/notify.js

+8
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,11 @@ test('should ouput if running as npm script and shouldNotifyInNpmScript option s
8383
notifier.notify({defer: false});
8484
t.true(stripAnsi(errorLogs).includes('Update available'));
8585
});
86+
87+
test('should not output if current version is the latest', t => {
88+
setupTest(true);
89+
const notifier = new Control(true);
90+
notifier.update.current = '1.0.0';
91+
notifier.notify({defer: false});
92+
t.false(stripAnsi(errorLogs).includes('Update available'));
93+
});

0 commit comments

Comments
 (0)