Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you check if an npm version number is valid before running npm publish?

Obviously if you try to npm publish without updating the version number of your module you will get an error. Is there any way to verify that the version number is valid for publishing before actually running npm publish?

My use case: I'm using CircleCI to build my module when pushing to any git branch. If somebody creates a pull request to master, I want to verify that the version number has been updated. However, I don't want to actually publish the package until the pull request to master has been accepted.

like image 721
trentjones21 Avatar asked Apr 29 '18 01:04

trentjones21


People also ask

Does npm publish Increase version?

After changing the version number in your package. json , you can run npm publish to publish the new version to NPM. npm install will install the latest version in the NPM repository.

Do I need to build before npm publish?

json and publish it to npm using the same version. You can't publish again using the same version, or a previous one. You can read more about versioning here. Don't forget to build before publishing.


1 Answers

You can get your current package version by: npm view <pkg> version (npm v5), than compare it with the version in the code.

It is easy to check whether the version has change, a simple === is enough. If you need to check whether the new version is valid, you should use look for a module for that.

https://www.npmjs.com/package/semver for example if you use JS code to check, or https://github.com/cloudflare/semver_bash if you use bash

like image 132
kkkkkkk Avatar answered Oct 21 '22 04:10

kkkkkkk