angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng update to v9 fails with invalid semver in package.json

Open fergusg opened this issue 6 years ago • 6 comments

Is this a regression?

Yes, the previous version in which this bug was not present was: .8.2.13

Description

ng update fails if package.json version is not fully semver (x.x.x).

Minimal Reproduction

$ ng new blah
$ cd blah
$ ng update rxjs
# Found 30 dependencies.

Edit package.json to change "version": "0.0".

$ ng update rxjs --allow-dirty
Found 0 dependencies.
Package 'rxjs' is not a dependency.

fergusg avatar Mar 06 '20 15:03 fergusg

Is there any particular use case for non-semver version numbers? AFAICT, NPM requires the version field to be semver (emphasis mine).

Version must be parseable by node-semver, which is bundled with npm as a dependency. (npm install semver to use it yourself.)

It doesn't really define what that format is, but instead defers to the implementation of semver, which does not consider it to be valid:

const semver = require("semver");
semver.valid("0.0"); // null

Is there a specific use case you want us to support, or is this simply a matter of having a clearer error message about the problem?

dgp1130 avatar May 28 '20 20:05 dgp1130

From our side, we don't use semver, but a combination of {year}-{dayOfYear}-{GitHash} So when we upgraded to v9 and met this restriction, we just set the version to 0.0.0, stopped using it, and created another field to store our real version.

I'm sure npm registries already enforce semver when you try to add it, so why make enforcement mandatory when it may be the top level package and never get installed via npm

Stexxen avatar May 28 '20 21:05 Stexxen

@Stexxen, you can continue to use your versioning scheme with semver, if you are willing to change the pattern to:

{year}{dayOfYear}+{GitHash}

^ that's one - removed and another one replaced with +, it's in the spec.

<version core> ::= <major> "." <minor> "." <patch>
<valid semver> ::= <version core> "-" <pre-release> "+" <build>

So for today, which is day 150 of 2020, you can use 1.0.0-2020150+daf6b1c8 and this will allow you to keep using the package.json version field and also have the required info. And as a bonus, you can increment the <version core> whenever you wish, or you can continue to use the same <version core> and just increment the <pre-release> part and the <build> part

SchnWalter avatar May 28 '20 21:05 SchnWalter

@SchnWalter wow, I had no idea the semver spec has so much flexibility. Thanks for this. I think we can use semver afterall 👍

Stexxen avatar May 28 '20 23:05 Stexxen

Great! Most people don't realize semvers are that flexible (I didn't either until a month or two ago).

We could probably do a better job of communicating the error, but this is a pretty specific condition, so I think I'll just close the issue unless we start seeing this recur frequently enough to warrant a fix.

dgp1130 avatar May 28 '20 23:05 dgp1130

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.