Skip to content

Commit 05a4171

Browse files
committed
fix(update-check): don't warn for prerelease or build
no issue - if we want to be able to push prereleases in the future, this is a necessary addition to the update check
1 parent 0c81bab commit 05a4171

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/utils/update-check.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
'use strict';
22
const Promise = require('bluebird');
3+
const includes = require('lodash/includes');
34
const updateNotifier = require('update-notifier');
45
const pkg = require('../../package.json');
56

7+
/*
8+
* Update notifier sends several different types of updates,
9+
* we want to make sure the only ones that trigger a warning are
10+
* major, minor, and patch releases. This allows us to push prereleases
11+
* & such in the future without those triggering a warning for users
12+
*
13+
* see https://github.com/yeoman/update-notifier#comprehensive for the different types
14+
* of updates
15+
*/
16+
const typesToWarn = [
17+
'major',
18+
'minor',
19+
'patch'
20+
];
21+
622
/**
723
* Checks if a version update is available
824
* @param {UI} ui ui instance
925
*/
1026
module.exports = function updateCheck(ui) {
1127
return Promise.fromCallback(cb => updateNotifier({pkg: pkg, callback: cb})).then((update) => {
12-
if (update.type !== 'latest') {
28+
if (includes(typesToWarn, update.type)) {
1329
const chalk = require('chalk');
1430

1531
ui.log(

test/unit/utils/update-check-spec.js

+20
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ describe('Unit: Utils > update-check', function () {
4848
});
4949
});
5050

51+
it('doesn\'t log a message if the type of update is not major, minor, or patch', function () {
52+
const pkg = {name: 'ghost', version: '1.0.0'};
53+
const updateNotifer = sinon.stub().callsFake((options) => {
54+
expect(options).to.exist;
55+
expect(options.pkg).to.deep.equal(pkg);
56+
expect(options.callback).to.be.a('function');
57+
options.callback(null, {type: 'prerelease'});
58+
});
59+
const logStub = sinon.stub();
60+
61+
const updateCheck = proxyquire(modulePath, {
62+
'../../package.json': pkg,
63+
'update-notifier': updateNotifer
64+
});
65+
66+
return updateCheck({log: logStub}).then(() => {
67+
expect(logStub.called).to.be.false;
68+
});
69+
});
70+
5171
it('logs a message if an update is available', function () {
5272
const pkg = {name: 'ghost', version: '1.0.0'};
5373
const updateNotifer = sinon.stub().callsFake((options) => {

0 commit comments

Comments
 (0)