yarnpkg / yarn

The 1.x line is frozen - features and bugfixes now happen on https://github.com/yarnpkg/berry
https://classic.yarnpkg.com
Other
41.44k stars 2.72k forks source link

Yarn outdated show a Patch update as Minor Update #6015

Open Skaronator opened 6 years ago

Skaronator commented 6 years ago

Do you want to request a feature or report a bug? Bug

What is the current behavior? yarn outdated use color to show major, minor and patch updates but for what-ever reason it display a patch update from 0.1.9 to 0.1.10 as minor update. I guess it thinks that 1 digit number to 2 digit number means minor.

If my guess is correct you should just check if old version + 1 = new version and if this is true it should be noted as Patch update.

Here is a screenshot. The affected line is apollo-boost.

image

If the current behavior is a bug, please provide the steps to reproduce. Have a package with a Patch version of .9 installed and run yarn outdated while the latest version is .10

What is the expected behavior?

A version update from 0.1.9 to 0.1.10 should be displayed as Patch update and not as Minor update.

Please mention your node.js, yarn and operating system version.

rally25rs commented 6 years ago

This seems to be intentional. This code exists in yarn:

      } else if (v1.patch !== v2.patch) {
        if (preMinor) {
          // If the major & minor version numbers are zero (0.0.x), treat a change
          // of the patch version number as a major change.
          diff = 'major';
        } else if (preMajor) {
          // If the major version number is zero (0.x.x), treat a change
          // of the patch version number as a minor change.
          diff = 'minor';
        } else {
          diff = 'patch';
        }
      }

I remember looking into something like this a while ago, but semver has different semantics for a 0.x version. Like 0.1.0 and 0.2.0 indicates a breaking change whereas 1.1.0 and 1.2.0 indicates backwards compatibility.

I forget if I originally noticed this in npm's handling of semver, or in the actual spec. All I can seem to find on semver.org is

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

Oh, actually I think I remember what it is... in npm's handling of semver ranges:

However when there is a leading 0. npm considers the 2nd version number to be "major". You can play with it on the semver calulator: https://semver.npmjs.com/

If you pick package lodash and enter the range ^1.2.0 then version 1.2.x and 1.3.x match.

However if you enter ^0.2.0 then versions 0.2.0 and 0.2.2 match, but 0.3.0 does not. npm considers the second digit to be the "major". I think yarn lined up the outdated labels to match the range selector meanings (how would this new version satisfy the major / minor range selectors?). Most of the npm docs seem to just gloss over the fact that 0.x is different and just say "always start at 1.0.0"


However, I also just noticed that on that semver calculator page, ~0.2.0 and ^0.2.0 select the exact same range, so maybe npm actually considers the 2nd digit to be both the major and minor? They really went and made this all sorts of confusing 😕