Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a CLI message when newer version is available #292

Merged
merged 1 commit into from
Dec 6, 2018

Conversation

yuliabaron
Copy link
Contributor

  • Ready for review
  • Follows CONTRIBUTING rules
  • Reviewed by Snyk internal team

What does this PR do?

Adding a message to CLI when a newer version is available

What are the relevant tickets?

https://snyksec.atlassian.net/browse/SC-6399

Screenshots

image

@yuliabaron yuliabaron self-assigned this Dec 5, 2018
package.json Outdated Show resolved Hide resolved
Copy link
Contributor

@miiila miiila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really happy to see this is coming back :-) Suggested few minor things to check, happy to assist with any of them.

src/cli/index.ts Outdated
// Checks for available update and returns an instance
// Default updateCheckInterval is once a day
var notifier = updateNotifier({
pkg: pkg,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write this as `updateNotifier({pkg}); when object key is same as a variable it points to, you can use this syntactic sugar :-)

src/cli/index.ts Outdated
var notifier = updateNotifier({
pkg: pkg,
});
// Notify using the built-in convenience method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this comment. Do you think we need it?

src/cli/index.ts Outdated
import * as updateNotifier from 'update-notifier';
var pkg = require('../../package.json');

async function updateCheck() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As notify is not asycnhronous (i.e. we don't do await notifier.notify(), async keyword before the function name is misleading.

src/cli/index.ts Outdated
@@ -108,6 +121,7 @@ function checkPaths(args) {
}

async function main() {
await updateCheck();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to the comment above, updateCheck() can be fully synchronous.

src/cli/index.ts Outdated
@@ -14,6 +14,19 @@ import errors = require('../lib/error');
import ansiEscapes = require('ansi-escapes');
import {isPathToPackageFile} from '../lib/detect';

import * as updateNotifier from 'update-notifier';
var pkg = require('../../package.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- var
+ const

src/cli/index.ts Outdated Show resolved Hide resolved
src/cli/index.ts Outdated
@@ -14,6 +14,19 @@ import errors = require('../lib/error');
import ansiEscapes = require('ansi-escapes');
import {isPathToPackageFile} from '../lib/detect';

import * as updateNotifier from 'update-notifier';
var pkg = require('../../package.json');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personal sidenote - I don't like using require to load .json files, I would suggest fs.readFile, but I fear we can saw this pattern in this app more often, so it's probably good to go.

src/cli/index.ts Outdated Show resolved Hide resolved
src/cli/index.ts Outdated
try {
notifier = updateNotifier({pkgFile});
} catch (err) {
console.warn('Failed to start updater, ERR=', err);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure whether to keep this warning. The code works from different directories, errors were observed during the tests on travis only

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine that we get here when version is not present in the package.json as would be the case on Travis etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly

darscan
darscan previously approved these changes Dec 5, 2018
return;
}

notifier.notify();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

notifier could be null here due to let and try/catch.. perhaps move notifier.notify(); up into the try block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i return from catch, but you're right, will move

@yuliabaron yuliabaron merged commit daebb6a into master Dec 6, 2018
@yuliabaron yuliabaron deleted the feat/cli_upgrade_message branch December 6, 2018 11:39
@snyksec
Copy link

snyksec commented Dec 6, 2018

🎉 This PR is included in version 1.116.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants