Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm publish patch for earlier major version

Tags:

npm

I can't seem to find information about how npm works with branches within a repository.

Suppose an npm package is currently versioned at: 1.0.5

A major change requires a version change from 1.0.5 => 2.0.0

Some users continue using 1.x.x to avoid breaking changes.

If a bug is discovered in 1.0.5 it needs to be fixed for the 1.x.x users requiring version change from 1.0.5 => 1.0.6

In effect, this is branching. I'd make a git branch for 1.x.x users and continue using git's master branch for 2.x.x

But how does this fit in with npm? Should I publish an older npm version 1.0.6? In that case doesn't 1.0.6 become the latest while actually 2.0.0 should be the default when doing npm install.

I can't find branch related information for npm. I'm sure the above is a common situation but I just can't find any info. Please can someone point me in the right direction.

like image 474
Kayo Avatar asked Jul 11 '14 06:07

Kayo


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.

How do I install a specific version of npm?

Use npm list [package-name] to know the specific latest version of an installed package. Use npm install [package-name]@[version-number] to install an older version of a package. Prefix a version number with a caret (^) or a tilde (~) to specify to install the latest minor or patch version, respectively.


1 Answers

You are on the right track - you want to publish [email protected] without updating the latest tag. You can do this by supplying a --tag <tagname> argument to npm publish --

cd project git checkout old-branch grep version package.json   "version": "1.0.5", [make changes] git commit npm version patch grep version package.json   "version": "1.0.6", npm publish --tag old-version 

As long as you supply a --tag <tagname> argument to npm publish, the latest tag will not be updated, and people using npm install <package> or npm install <package>@latest will still get the 2.x version.

Note that the tagname has to share a namespace with version numbers, so it's best to choose a tagname that doesn't look like a semver version; avoid '1.0.6' or 'v1.0.6'.

Source: https://docs.npmjs.com/cli/publish and: https://docs.npmjs.com/getting-started/using-tags

like image 84
Sam Mikes Avatar answered Sep 24 '22 21:09

Sam Mikes