Yarn: Add yarn version check on startup

Created on 17 Oct 2016  Â·  14Comments  Â·  Source: yarnpkg/yarn

Do you want to request a _feature_ or report a _bug_?
Feature

What is the current behavior?
Yarn does not notify the user that a new version of Yarn is available

What is the expected behavior?
Yarn should periodically check for new version on startup. Maybe once per day. You can get the latest version number by hitting https://yarnpkg.com/latest-version.

If the latest version is newer than the current version, display a message with the new version number, and instructions on how to update. Optionally, if the user is using a TTY (ie. they're not piping the output elsewhere or running Yarn from a script), we could prompt if they want to upgrade right away:

Yarn 0.16.0 is available! (you're using 0.15.0)
Do you want to upgrade now (Y/N)? __

This would use yarn update-self once it's updated to use the same installation method originally used (#1139).

For an initial version, we could just show instructions on how to update. Important: These instructions should correspond to the installation method the user used to install Yarn.

For example, on Debian or Ubuntu:

Yarn 0.16.0 is available! (you're using 0.15.0)
To upgrade, run "sudo apt-get install yarn"

On Windows when using the Windows installer:

Yarn 0.16.0 is available! (you're using 0.15.0)
To upgrade, download the latest installer from https://yarnpkg.com/latest.msi

On Mac OS:

Yarn 0.16.0 is available! (you're using 0.15.0)
To upgrade, run "brew upgrade yarn"

When installed via npm:

Yarn 0.16.0 is available! (you're using 0.15.0)
To upgrade, run "npm upgrade --global yarn"

Currently we don't actually record the installation method anywhere, so I think we'll just have to guess it based on the environment (eg. if /usr/share/lintian/overrides/yarn exists, the Ubuntu/Debian package was used) unless we update all the installation methods to write a config file specifying the installation method.

If we can't tell which installation method was used, just print the new version number without the upgrade instructions.

All 14 comments

I love this, but I'd prefer not to have a prompt to upgrade (or at least a config flag to turn that behavior off). The yarn self-update command working as you just mentioned in #1139 would make things very easy to keep things up to date especially on a vanilla Windows platform without any OS package manager.

Thanks for the great work!

Big fan of this idea

Love this idea. In case it offers any inspiration, we use https://github.com/yeoman/update-notifier for start-up based update notifications in a few different CLI projects.

I think you might be trying to do something a little more custom in each case given you would like to stick closely to the installation method originally used to install yarn.

@addyosmani - Yeah, I saw that (someone linked to it in another issue somewhere) but it looks tightly-coupled to npm. I wonder if we could use the UI of it while customising the backend.

In our case, we have an endpoint https://yarnpkg.com/latest-version that returns the version number, so a lot of the complexity (ie. checking version number from npm) doesn't exist for us. It should be fairly straightforward 😄

@Daniel15 please make a PR for this.

Can we somehow add a token to every build indicating the install method? I think that's way better than any sort of inference we might do.

Sgtm @Daniel15 :)

I'll loop in @sindresorhus just in case he's interested in generalizing update-notifier (or similar) to work better with yarn (even if it may not get used here).

please make a PR for this

I'll try to do that when I get some time to work on it (perhaps a week or two from now), I just thought I'd post the idea while it's still fresh in my mind. If anyone else wants to work on this and it's unassigned on Github, feel free to pick it up (I'll assign it to me if I start working on it) 😄

Can we somehow add a token to every build indicating the install method?

Yeah, that sounds like the best idea. It'd help with #942 (if we want to implement that) too.

I don't think update-notifier is a good fit here as-is, but could definitely be a good inspiration, and you could reuse many of its building blocks. The best thing about it is how non-intrusive it is. It only shows the update notification _after_ running the CLI tool and only if the terminal is interactive, so it's never in the way of what the user want to do. It should not show the notification very often; Maximum once a day, but preferably once a week. It's also important to have an easy opt-out for people not wanting update notifications.

I'm thinking the output text could be:

Yarn 0.16.0 is available!
To upgrade from 0.15.0, run:
brew upgrade yarn

Having the command on a separate line makes it easier to copy-paste for users.

Yeah, I saw that (someone linked to it in another issue somewhere) but it looks tightly-coupled to npm. I wonder if we could use the UI of it while customising the backend.

The update-notifier UI is just boxen for the box and chalk for styling the text.

Thanks for your insight, @sindresorhus!

It only shows the update notification after running the CLI tool and only if the terminal is interactive

This is a great idea, better than showing the notification / asking about it before running the tool.

Created #1429 to fix this, pending approval.

Where is it?…

$ yarn
yarn install v1.3.2
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.49s.

But 1.5.1 at https://yarnpkg.com/latest-version :slightly_frowning_face:

The check only runs once per day, so it might not have ran yet.

The check only runs once per day, so it might not have ran yet.

Still no:

$ yarn
yarn install v1.3.2
[1/4] Resolving packages...
success Already up-to-date.
Done in 0.33s.
Was this page helpful?
0 / 5 - 0 ratings