Relax the validation of versions for npm packages
Context
When $ npm publish
does auto-corrections, it can cause failures when uploading npm packages to a GitLab NPM registry. To solve this, users should:
-
$ npm pkg fix
which will simply apply the auto corrections - Commit the changes to package.json (This could be optional, but it avoids running step 1 all the time.)
- Run $ npm publish
- This time around, it will not auto-correct things (since they are already auto-corrected). The upload will be accepted.
Problem to solve
Relax the validation checks for versions to reduce the number of failed npm uploads.
⚙ Technical details
Use https://gitlab.com/gitlab-org/ruby/gems/semver_dialects (already included in the GitLab codebase) to do version comparisons in a less strict manner.
This way, the same parts that $ npm
ignores will be handled.
Example:
v = SemverDialects.parse_version("npm", "1.0.0+a")
v.to_s
=> "1.0.0"
v = SemverDialects.parse_version("npm", "v1.0.0")
v.to_s
=> "1.0.0"
v1 = SemverDialects.parse_version("npm", "v1.0.0+a")
v2 = SemverDialects.parse_version("npm", "1.0.0")
v1 == v2
=> true
Edited by David Fernandez